diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-06-16 16:50:03 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-06-16 16:50:03 -0400 |
commit | 712deee42b122f0ec07866e6bd7770343cee971c (patch) | |
tree | 4eb2525edc3cf17d2f6710c7ce52eb28d423f28b | |
parent | c9d9fca2ed950b32be992d5ac2a055c8246f52a5 (diff) |
sync: Add support for --all and --unused.
-rw-r--r-- | CmdLine/GitAnnex/Options.hs | 16 | ||||
-rw-r--r-- | CmdLine/Seek.hs | 20 | ||||
-rw-r--r-- | Command/Sync.hs | 17 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | doc/git-annex-sync.mdwn | 39 | ||||
-rw-r--r-- | doc/todo/wishlist:_--all_option_for_sync.mdwn | 2 |
6 files changed, 64 insertions, 31 deletions
diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 46d593618..320268f6a 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -53,13 +53,15 @@ gitAnnexOptions = commonOptions ++ -- Options for matching on annexed keys, rather than work tree files. keyOptions :: [Option] -keyOptions = - [ Option ['A'] ["all"] (NoArg (Annex.setFlag "all")) - "operate on all versions of all files" - , Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused")) - "operate on files found by last run of git-annex unused" - , keyOption - ] +keyOptions = [ allOption, unusedOption, keyOption] + +allOption :: Option +allOption = Option ['A'] ["all"] (NoArg (Annex.setFlag "all")) + "operate on all versions of all files" + +unusedOption :: Option +unusedOption = Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused")) + "operate on files found by last run of git-annex unused" keyOption :: Option keyOption = Option [] ["key"] (ReqArg (Annex.setField "key") paramKey) diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index 664c12b62..47e2c79bc 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -4,7 +4,7 @@ - the values a user passes to a command, and prepare actions operating - on them. - - - Copyright 2010-2014 Joey Hess <id@joeyh.name> + - Copyright 2010-2015 Joey Hess <id@joeyh.name> - - Licensed under the GNU GPL version 3 or higher. -} @@ -172,7 +172,17 @@ withNothing _ _ = error "This command takes no parameters." - Otherwise falls back to a regular CommandSeek action on - whatever params were passed. -} withKeyOptions :: Bool -> (Key -> CommandStart) -> CommandSeek -> CommandSeek -withKeyOptions auto keyop fallbackop params = do +withKeyOptions auto keyop = withKeyOptions' auto $ \getkeys -> do + matcher <- Limit.getMatcher + seekActions $ map (process matcher) <$> getkeys + where + process matcher k = ifM (matcher $ MatchingKey k) + ( keyop k + , return Nothing + ) + +withKeyOptions' :: Bool -> (Annex [Key] -> Annex ()) -> CommandSeek -> CommandSeek +withKeyOptions' auto keyop fallbackop params = do bare <- fromRepo Git.repoIsLocalBare allkeys <- Annex.getFlag "all" unused <- Annex.getFlag "unused" @@ -194,11 +204,7 @@ withKeyOptions auto keyop fallbackop params = do _ -> error "Can only specify one of file names, --all, --unused, --key, or --incomplete" where go True _ = error "Cannot use --auto with --all or --unused or --key or --incomplete" - go False a = do - matcher <- Limit.getMatcher - seekActions $ map (process matcher) <$> a - process matcher k = ifM (matcher $ MatchingKey k) - ( keyop k , return Nothing) + go False getkeys = keyop getkeys incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True prepFiltered :: (FilePath -> CommandStart) -> Annex [FilePath] -> Annex [CommandStart] diff --git a/Command/Sync.hs b/Command/Sync.hs index dbf16992d..88449384d 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -58,6 +58,8 @@ syncOptions :: [Option] syncOptions = [ contentOption , messageOption + , allOption + , unusedOption ] contentOption :: Option @@ -371,12 +373,19 @@ newer remote b = do seekSyncContent :: [Remote] -> Annex Bool seekSyncContent rs = do mvar <- liftIO newEmptyMVar - mapM_ (go mvar) =<< seekHelper LsFiles.inRepo [] + -- Always start with the work tree; this ensures that preferred + -- content expressions that match files match, even when in --all + -- mode. + seekworktree mvar [] + withKeyOptions' False (seekkeys mvar) (const noop) [] liftIO $ not <$> isEmptyMVar mvar where - go mvar f = ifAnnexed f - (\v -> void (liftIO (tryPutMVar mvar ())) >> syncFile rs (Just f) v) - noop + seekworktree mvar = seekHelper LsFiles.inRepo >=> + mapM_ (\f -> ifAnnexed f (go mvar (Just f)) noop) + seekkeys mvar getkeys = mapM_ (go mvar Nothing) =<< getkeys + go mvar af k = do + void $ liftIO $ tryPutMVar mvar () + syncFile rs af k syncFile :: [Remote] -> AssociatedFile -> Key -> Annex () syncFile rs af k = do diff --git a/debian/changelog b/debian/changelog index e05d80e4b..3264bee9f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -34,6 +34,7 @@ git-annex (5.20150529) UNRELEASED; urgency=medium * debian/cabal-wrapper: Removed this hack which should not be needed anymore. * info: Added json output for "backend usage", "numcopies stats", "repositories containing these files", and "transfers in progress". + * sync: Add support for --all and --unused. -- Joey Hess <id@joeyh.name> Sat, 30 May 2015 02:07:18 -0400 diff --git a/doc/git-annex-sync.mdwn b/doc/git-annex-sync.mdwn index 1659dfb8b..2d81d44de 100644 --- a/doc/git-annex-sync.mdwn +++ b/doc/git-annex-sync.mdwn @@ -21,6 +21,9 @@ those branches on the remote repositories. You can use standard git commands to do each of those steps by hand, or if you don't want to worry about the details, you can use sync. +The content of annexed objects is not synced by default, but the --content +option (see below) can make that also be synchronized. + Merge conflicts are automatically handled by sync. When two conflicting versions of a file have been committed, both will be added to the tree, under different filenames. For example, file "foo" would be replaced @@ -31,9 +34,12 @@ tree with changes made to the local repository. However, those changes are pushed to the remote, so they can be merged into its working tree by running "git annex sync" on the remote. - # OPTIONS +* `--message=msg` + + Use this option to specify a commit message. + * `--fast` Only sync with the remotes with the lowest annex-cost value configured. @@ -41,20 +47,29 @@ by running "git annex sync" on the remote. * `--content` Normally, syncing does not transfer the contents of annexed files. - This option causes the file contents to also be uploaded and downloaded - as necessary. + This option causes the content of files in the work tree + to also be uploaded and downloaded as necessary. - By default, this tries to get each annexed file that the local repository - does not yet have, and then copies each file to every remote that it is - syncing with. This behavior can be overridden by configuring the preferred - content of a repository. See [[git-annex-preferred-content]](1). + By default, this tries to get each annexed file in the work tree + that the local repository does not yet have, and then copies each + file in the work tree to every remote that it is syncing with. + This behavior can be overridden by configuring the preferred content + of a repository. See [[git-annex-preferred-content]](1). - To make two repositories have the same set of files, you should use - [[git-annex-mirror]](1) instead of this flag. +* `--all` -* `--message=msg` + This option, when combined with `--content`, makes all available versions + of all files be synced, when preferred content settings allow. - Use this option to specify a commit message. + Note that preferred content settings that use `include=` or `exclude=` + will only match the version of files currently in the work tree, but not + past versions of files. + +* `--unused` + + This option, when combined with `--content`, makes files + found by last run of git-annex unused be synced, when preferred content + settings allow. # SEE ALSO @@ -62,8 +77,6 @@ by running "git annex sync" on the remote. [[git-annex-preferred-content]](1) -[[git-annex-mirror]](1) - # AUTHOR Joey Hess <id@joeyh.name> diff --git a/doc/todo/wishlist:_--all_option_for_sync.mdwn b/doc/todo/wishlist:_--all_option_for_sync.mdwn index 75e4b27d3..fd609a091 100644 --- a/doc/todo/wishlist:_--all_option_for_sync.mdwn +++ b/doc/todo/wishlist:_--all_option_for_sync.mdwn @@ -18,3 +18,5 @@ Please add an `--all` option to the `sync` command Thanks Andrew + +> Implemented; [[done]]. --[[Joey]] |