summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-07 14:46:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-07 15:59:16 -0400
commit63a292324d20832b68c92f784828e55e644481cc (patch)
treef49c7077caf738cd285681421f9c9baa03068c99 /Types
parentb08f7c428b4bc9eabd95596d08594ddd1057a0bf (diff)
add a UUID type
Should have done this a long time ago.
Diffstat (limited to 'Types')
-rw-r--r--Types/Remote.hs7
-rw-r--r--Types/UUID.hs14
2 files changed, 16 insertions, 5 deletions
diff --git a/Types/Remote.hs b/Types/Remote.hs
index 49f16bfdd..0a4a0fa88 100644
--- a/Types/Remote.hs
+++ b/Types/Remote.hs
@@ -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
diff --git a/Types/UUID.hs b/Types/UUID.hs
index eb3497fa9..f7232d0b9 100644
--- a/Types/UUID.hs
+++ b/Types/UUID.hs
@@ -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, "")]