refactor
This commit is contained in:
parent
56488e807b
commit
52104dae6f
3 changed files with 14 additions and 15 deletions
|
@ -58,7 +58,7 @@ hasSibling = not . null <$> siblingBranches
|
||||||
{- List of git-annex (refs, branches), including the main one and any
|
{- List of git-annex (refs, branches), including the main one and any
|
||||||
- from remotes. Duplicate refs are filtered out. -}
|
- from remotes. Duplicate refs are filtered out. -}
|
||||||
siblingBranches :: Annex [(Git.Ref, Git.Branch)]
|
siblingBranches :: Annex [(Git.Ref, Git.Branch)]
|
||||||
siblingBranches = inRepo $ Git.Ref.matching name
|
siblingBranches = inRepo $ Git.Ref.matchingUniq name
|
||||||
|
|
||||||
{- Creates the branch, if it does not already exist. -}
|
{- Creates the branch, if it does not already exist. -}
|
||||||
create :: Annex ()
|
create :: Annex ()
|
||||||
|
|
|
@ -46,18 +46,12 @@ syncRemotes branch [] = defaultSyncRemotes branch
|
||||||
syncRemotes _ rs = mapM Remote.byName rs
|
syncRemotes _ rs = mapM Remote.byName rs
|
||||||
|
|
||||||
defaultSyncRemotes :: Git.Ref -> Annex [Remote.Remote Annex]
|
defaultSyncRemotes :: Git.Ref -> Annex [Remote.Remote Annex]
|
||||||
defaultSyncRemotes syncbranch = mapM Remote.byName
|
defaultSyncRemotes syncbranch = mapM Remote.byName =<<
|
||||||
=<< process . L.unpack <$> inRepo showref
|
map getRemoteName . filter isRemote . map (show . snd) <$>
|
||||||
|
inRepo (Git.Ref.matching $ Git.Ref.base syncbranch)
|
||||||
where
|
where
|
||||||
showref = Git.Command.pipeRead
|
|
||||||
[ Param "show-ref"
|
|
||||||
, Param $ show $ Git.Ref.base syncbranch
|
|
||||||
]
|
|
||||||
process = map getRemoteName . filter isRemote .
|
|
||||||
map getBranchName . lines
|
|
||||||
isRemote r = "refs/remotes/" `isPrefixOf` r
|
|
||||||
getBranchName = snd . separate (== ' ')
|
|
||||||
getRemoteName = fst . separate (== '/') . snd . separate (== '/') . snd . separate (== '/')
|
getRemoteName = fst . separate (== '/') . snd . separate (== '/') . snd . separate (== '/')
|
||||||
|
isRemote r = "refs/remotes/" `isPrefixOf` r
|
||||||
|
|
||||||
commit :: CommandStart
|
commit :: CommandStart
|
||||||
commit = do
|
commit = do
|
||||||
|
|
13
Git/Ref.hs
13
Git/Ref.hs
|
@ -48,13 +48,18 @@ sha branch repo = process . L.unpack <$> showref repo
|
||||||
process [] = Nothing
|
process [] = Nothing
|
||||||
process s = Just $ Ref $ firstLine s
|
process s = Just $ Ref $ firstLine s
|
||||||
|
|
||||||
{- List of (refs, branches) matching a given ref spec.
|
{- List of (refs, branches) matching a given ref spec. -}
|
||||||
- Duplicate refs are filtered out. -}
|
|
||||||
matching :: Ref -> Repo -> IO [(Ref, Branch)]
|
matching :: Ref -> Repo -> IO [(Ref, Branch)]
|
||||||
matching ref repo = do
|
matching ref repo = do
|
||||||
r <- pipeRead [Param "show-ref", Param $ show ref] repo
|
r <- pipeRead [Param "show-ref", Param $ show ref] repo
|
||||||
return $ nubBy uniqref $ map (gen . L.unpack) (L.lines r)
|
return $ map (gen . L.unpack) (L.lines r)
|
||||||
where
|
where
|
||||||
uniqref (a, _) (b, _) = a == b
|
|
||||||
gen l = let (r, b) = separate (== ' ') l in
|
gen l = let (r, b) = separate (== ' ') l in
|
||||||
(Ref r, Ref b)
|
(Ref r, Ref b)
|
||||||
|
|
||||||
|
{- List of (refs, branches) matching a given ref spec.
|
||||||
|
- Duplicate refs are filtered out. -}
|
||||||
|
matchingUniq :: Ref -> Repo -> IO [(Ref, Branch)]
|
||||||
|
matchingUniq ref repo = nubBy uniqref <$> matching ref repo
|
||||||
|
where
|
||||||
|
uniqref (a, _) (b, _) = a == b
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue