summaryrefslogtreecommitdiff
path: root/Annex/TaggedPush.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-06 16:29:19 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-06 16:29:19 -0400
commitdc82128f6f0ffef9f6973baed3ad63d89802c898 (patch)
tree93ff21057d04f9d1c48e4c9e2fa75de092dc1908 /Annex/TaggedPush.hs
parent49b88039e597ec761227d00ddf125f8ebe5c6a4f (diff)
tag xmpp pushes with jid
This fixes the issue mentioned in the last commit. Turns out just collecting UUID of clients behind a XMPP remote is insufficient (although I should probably still do it for other reasons), because a single remote repo might be connected via both XMPP and local pairing. So a way is needed to know when a push was received from any client using a given XMPP remote over XMPP, as opposed to via ssh.
Diffstat (limited to 'Annex/TaggedPush.hs')
-rw-r--r--Annex/TaggedPush.hs42
1 files changed, 26 insertions, 16 deletions
diff --git a/Annex/TaggedPush.hs b/Annex/TaggedPush.hs
index f54ce756f..4f5125ce0 100644
--- a/Annex/TaggedPush.hs
+++ b/Annex/TaggedPush.hs
@@ -1,4 +1,4 @@
-{- git-annex uuid-tagged pushes
+{- git-annex tagged pushes
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
@@ -13,9 +13,11 @@ import qualified Annex.Branch
import qualified Git
import qualified Git.Ref
import qualified Git.Command
+import Utility.Base64
{- Converts a git branch into a branch that is tagged with a UUID, typically
- - the UUID of the repo that will be pushing it.
+ - the UUID of the repo that will be pushing it, and possibly with other
+ - information.
-
- Pushing to branches on the remote that have out uuid in them is ugly,
- but it reserves those branches for pushing by us, and so our pushes will
@@ -23,25 +25,33 @@ import qualified Git.Command
-
- To avoid cluttering up the branch display, the branch is put under
- refs/synced/, rather than the usual refs/remotes/
+ -
+ - Both UUIDs and Base64 encoded data are always legal to be used in git
+ - refs, per git-check-ref-format.
-}
-toTaggedBranch :: UUID -> Git.Branch -> Git.Branch
-toTaggedBranch u b = Git.Ref $ concat
- [ s
- , ":"
- , "refs/synced/" ++ fromUUID u ++ "/" ++ s
+toTaggedBranch :: UUID -> Maybe String -> Git.Branch -> Git.Branch
+toTaggedBranch u info b = Git.Ref $ join "/" $ catMaybes
+ [ Just "refs/synced"
+ , Just $ fromUUID u
+ , toB64 <$> info
+ , Just $ show $ Git.Ref.base b
]
- where
- s = show $ Git.Ref.base b
-branchTaggedBy :: Git.Branch -> Maybe UUID
-branchTaggedBy b = case split "/" $ show b of
- ("refs":"synced":u:_base) -> Just $ toUUID u
+fromTaggedBranch :: Git.Branch -> Maybe (UUID, Maybe String)
+fromTaggedBranch b = case split "/" $ show b of
+ ("refs":"synced":u:info:_base) ->
+ Just (toUUID u, fromB64Maybe info)
+ ("refs":"synced":u:_base) ->
+ Just (toUUID u, Nothing)
_ -> Nothing
+ where
-taggedPush :: UUID -> Git.Ref -> Remote -> Git.Repo -> IO Bool
-taggedPush u branch remote = Git.Command.runBool
+taggedPush :: UUID -> Maybe String -> Git.Ref -> Remote -> Git.Repo -> IO Bool
+taggedPush u info branch remote = Git.Command.runBool
[ Param "push"
, Param $ Remote.name remote
- , Param $ show $ toTaggedBranch u Annex.Branch.name
- , Param $ show $ toTaggedBranch u branch
+ , Param $ refspec Annex.Branch.name
+ , Param $ refspec branch
]
+ where
+ refspec b = show b ++ ":" ++ show (toTaggedBranch u info b)