summaryrefslogtreecommitdiff
path: root/P2P
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-03-10 13:12:24 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-03-10 13:35:31 -0400
commit8cb9381befed4174624edfc80e09185c9340b4f6 (patch)
treee5d2041ff38502b1f8a5ef9caa6515cccfcea555 /P2P
parente230fd58b5f5d5d16f87e1bd5c0f2e553f2ae5a2 (diff)
AssociatedFile newtype
To prevent any further mistakes like 1a497cefb47557f0b4788c606f9071be422b2511 This commit was sponsored by Francois Marier on Patreon.
Diffstat (limited to 'P2P')
-rw-r--r--P2P/Protocol.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/P2P/Protocol.hs b/P2P/Protocol.hs
index 135409e26..e74979170 100644
--- a/P2P/Protocol.hs
+++ b/P2P/Protocol.hs
@@ -136,8 +136,9 @@ instance Proto.Serializable Service where
-- These mungings are ok, because an AssociatedFile is only ever displayed
-- to the user and does not need to match a file on disk.
instance Proto.Serializable AssociatedFile where
- serialize Nothing = ""
- serialize (Just af) = toInternalGitPath $ concatMap esc af
+ serialize (AssociatedFile Nothing) = ""
+ serialize (AssociatedFile (Just af)) =
+ toInternalGitPath $ concatMap esc af
where
esc '%' = "%%"
esc c
@@ -145,9 +146,9 @@ instance Proto.Serializable AssociatedFile where
| otherwise = [c]
deserialize s = case fromInternalGitPath $ deesc [] s of
- [] -> Just Nothing
+ [] -> Just (AssociatedFile Nothing)
f
- | isRelative f -> Just (Just f)
+ | isRelative f -> Just (AssociatedFile (Just f))
| otherwise -> Nothing
where
deesc b [] = reverse b