summaryrefslogtreecommitdiff
path: root/Annex/TaggedPush.hs
blob: f54ce756fab7de91944563842e813cc095462e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{- git-annex uuid-tagged pushes
 -
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Annex.TaggedPush where

import Common.Annex
import qualified Remote
import qualified Annex.Branch
import qualified Git
import qualified Git.Ref
import qualified Git.Command

{- Converts a git branch into a branch that is tagged with a UUID, typically
 - the UUID of the repo that will be pushing it.
 -
 - 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
 - never conflict with other pushes.
 -
 - To avoid cluttering up the branch display, the branch is put under
 - refs/synced/, rather than the usual refs/remotes/
 -}
toTaggedBranch :: UUID -> Git.Branch -> Git.Branch
toTaggedBranch u b = Git.Ref $ concat
	[ s
	, ":"
	, "refs/synced/" ++ fromUUID u ++ "/" ++ s
	]
  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
	_ -> Nothing

taggedPush :: UUID -> Git.Ref -> Remote -> Git.Repo -> IO Bool
taggedPush u branch remote = Git.Command.runBool
        [ Param "push"
        , Param $ Remote.name remote
        , Param $ show $ toTaggedBranch u Annex.Branch.name
        , Param $ show $ toTaggedBranch u branch
        ]