From e7d3e546c298add0a39ec1a979d9b1574b9b9b76 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 Dec 2011 21:17:36 -0400 Subject: [PATCH] sync --fast: Selects some of the remotes with the lowest annex.cost and syncs those, in addition to any specified at the command line. --- Command/Sync.hs | 23 +++++++++++++++++++---- debian/changelog | 2 ++ doc/git-annex.mdwn | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index a3450278ce..81b77e5cc1 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -13,14 +13,17 @@ module Command.Sync where import Common.Annex import Command import qualified Remote +import qualified Annex import qualified Annex.Branch import qualified Git.Command import qualified Git.Branch import qualified Git.Config import qualified Git.Ref import qualified Git +import qualified Types.Remote import qualified Data.ByteString.Lazy.Char8 as L +import qualified Data.Map as M def :: [Command] def = [command "sync" (paramOptional (paramRepeating paramRemote)) @@ -28,9 +31,9 @@ def = [command "sync" (paramOptional (paramRepeating paramRemote)) -- syncing involves several operations, any of which can independantly fail seek :: CommandSeek -seek args = do +seek rs = do !branch <- currentBranch - remotes <- syncRemotes args + remotes <- syncRemotes rs return $ concat $ [ [ commit ] , [ mergeLocal branch ] @@ -44,11 +47,23 @@ syncBranch :: Git.Ref -> Git.Ref syncBranch = Git.Ref.under "refs/heads/synced/" syncRemotes :: [String] -> Annex [Remote.Remote Annex] -syncRemotes [] = filterM hasurl =<< Remote.remoteList +syncRemotes rs = do + fast <- Annex.getState Annex.fast + if fast + then nub <$> pickfast + else wanted where + wanted + | null rs = filterM hasurl =<< Remote.remoteList + | otherwise = listed + listed = mapM Remote.byName rs hasurl r = not . null <$> geturl r geturl r = fromRepo $ Git.Config.get ("remote." ++ Remote.name r ++ ".url") "" -syncRemotes rs = mapM Remote.byName rs + pickfast = (++) <$> listed <*> (fastest <$> Remote.remoteList) + fastest = fromMaybe [] . headMaybe . + map snd . sort . M.toList . costmap + costmap = M.fromListWith (++) . map costpair + costpair r = (Types.Remote.cost r, [r]) commit :: CommandStart commit = do diff --git a/debian/changelog b/debian/changelog index 7b8e347767..db447fea4a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,8 @@ git-annex (3.20111212) UNRELEASED; urgency=low * Updated to build with monad-control 0.3. * sync: Improved to work well without a central bare repository. Thanks to Joachim Breitner. + * sync --fast: Selects some of the remotes with the lowest annex.cost + and syncs those, in addition to any specified at the command line. -- Joey Hess Mon, 12 Dec 2011 01:57:49 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index acdb1313da..a0dd3d3f1b 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -124,7 +124,8 @@ subdirectories). Use this command when you want to synchronize the local repository with one or more of its remotes. You can specifiy the remotes to sync with; - the default is to sync with all remotes. + the default is to sync with all remotes. Or specify --fast to sync with + the remotes with the lowest annex-cost value. The sync process involves first committing all local changes, then fetching and merging the `synced/master` and the `git-annex` branch