From aba3e1177632cac4e08c2b36373b0c1f8c804747 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Dec 2014 13:41:03 -0400 Subject: [PATCH] sync: Now supports remote groups, the same way git remote update does. --- Command/Sync.hs | 19 +++++++++++++++++-- Remote.hs | 15 ++++++++++++++- debian/changelog | 1 + doc/git-annex.mdwn | 5 +++-- doc/todo/remote_groups_support_for_sync.mdwn | 2 ++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index a89737647c..28d7c69c55 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -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 diff --git a/Remote.hs b/Remote.hs index 65e725338f..2f0bb2111c 100644 --- a/Remote.hs +++ b/Remote.hs @@ -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 diff --git a/debian/changelog b/debian/changelog index 6c1bad91b5..c476ab86a2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Mon, 22 Dec 2014 15:16:38 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index dfd0b6b490..a6f638de26 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -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. diff --git a/doc/todo/remote_groups_support_for_sync.mdwn b/doc/todo/remote_groups_support_for_sync.mdwn index f963f0bd09..b49016427e 100644 --- a/doc/todo/remote_groups_support_for_sync.mdwn +++ b/doc/todo/remote_groups_support_for_sync.mdwn @@ -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]]