sync: Now supports remote groups, the same way git remote update does.

This commit is contained in:
Joey Hess 2014-12-29 13:41:03 -04:00
parent f7333d29ae
commit aba3e11776
5 changed files with 37 additions and 5 deletions

View file

@ -6,7 +6,17 @@
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Sync where
module Command.Sync (
cmd,
prepMerge,
mergeLocal,
mergeRemote,
commitStaged,
pushBranch,
updateBranch,
syncBranch,
updateSyncBranch,
) where
import Common.Annex
import Command
@ -109,16 +119,21 @@ syncRemotes :: [String] -> Annex [Remote]
syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
where
pickfast = (++) <$> listed <*> (filterM good =<< fastest <$> available)
wanted
| null rs = filterM good =<< concat . Remote.byCost <$> available
| otherwise = listed
listed = catMaybes <$> mapM (Remote.byName . Just) rs
listed = concat <$> mapM Remote.byNameOrGroup rs
available = filter (remoteAnnexSync . Remote.gitconfig)
. filter (not . Remote.isXMPPRemote)
<$> Remote.remoteList
good r
| Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r
| otherwise = return True
fastest = fromMaybe [] . headMaybe . Remote.byCost
commit :: CommandStart

View file

@ -26,6 +26,7 @@ module Remote (
uuidDescriptions,
byName,
byName',
byNameOrGroup,
byNameOnly,
byNameWithUUID,
byCost,
@ -94,7 +95,11 @@ addName desc n
| otherwise = desc ++ " [" ++ n ++ "]"
{- When a name is specified, looks up the remote matching that name.
- (Or it can be a UUID.) -}
- (Or it can be a UUID.)
-
- Throws an error if a name is specified and no matching remote can be
- found.
-}
byName :: Maybe RemoteName -> Annex (Maybe Remote)
byName Nothing = return Nothing
byName (Just n) = either error Just <$> byName' n
@ -121,6 +126,14 @@ byName' n = go . filter matching <$> remoteList
go (match:_) = Right match
matching r = n == name r || toUUID n == uuid r
{- Finds the remote or remote group matching the name. -}
byNameOrGroup :: RemoteName -> Annex [Remote]
byNameOrGroup n = go =<< getConfigMaybe (ConfigKey ("remotes." ++ n))
where
go (Just l) = concatMap maybeToList <$>
mapM (Remote.byName . Just) (split " " l)
go Nothing = maybeToList <$> Remote.byName (Just n)
{- Only matches remote name, not UUID -}
byNameOnly :: RemoteName -> Annex (Maybe Remote)
byNameOnly n = headMaybe . filter matching <$> remoteList

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ git-annex (5.20141220) UNRELEASED; urgency=medium
* vicfg: Avoid crashing on badly encoded config data.
* Work around statfs() overflow on some XFS systems.
* sync: Now supports remote groups, the same way git remote update does.
-- Joey Hess <id@joeyh.name> Mon, 22 Dec 2014 15:16:38 -0400

View file

@ -143,8 +143,9 @@ subdirectories).
* `sync [remote ...]`
Use this command when you want to synchronize the local repository with
one or more of its remotes. You can specify the remotes to sync with by
name; the default is to sync with all remotes.
one or more of its remotes. You can specify the remotes (or remote
groups) to sync with by name; the default if none are specified is to
sync with all remotes.
Or specify `--fast` to sync with the remotes with the
lowest annex-cost value.

View file

@ -1,3 +1,5 @@
`git remote update $group` looks at the $group.away git config and fetches
from the listed remotes. It would be useful if `git annex sync $group` did the same.
--[[Joey]]
[[done]]