add a UUID type

Should have done this a long time ago.
This commit is contained in:
Joey Hess 2011-11-07 14:46:01 -04:00
parent b08f7c428b
commit 63a292324d
18 changed files with 67 additions and 55 deletions

View file

@ -15,6 +15,7 @@ import Data.Ord
import qualified Git
import Types.Key
import Types.UUID
type RemoteConfig = M.Map String String
@ -25,15 +26,15 @@ data RemoteType a = RemoteType {
-- enumerates remotes of this type
enumerate :: a [Git.Repo],
-- generates a remote of this type
generate :: Git.Repo -> String -> Maybe RemoteConfig -> a (Remote a),
generate :: Git.Repo -> UUID -> Maybe RemoteConfig -> a (Remote a),
-- initializes or changes a remote
setup :: String -> RemoteConfig -> a RemoteConfig
setup :: UUID -> RemoteConfig -> a RemoteConfig
}
{- An individual remote. -}
data Remote a = Remote {
-- each Remote has a unique uuid
uuid :: String,
uuid :: UUID,
-- each Remote has a human visible name
name :: String,
-- Remotes have a use cost; higher is more expensive

View file

@ -7,5 +7,15 @@
module Types.UUID where
-- might be nice to have a newtype, but lots of stuff treats uuids as strings
type UUID = String
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
data UUID = NoUUID | UUID String
deriving (Eq, Ord)
instance Show UUID where
show (UUID u) = u
show NoUUID = ""
instance Read UUID where
readsPrec _ s
| null s = [(NoUUID, "")]
| otherwise = [(UUID s, "")]