diff --git a/CHANGELOG b/CHANGELOG index 96ede489fd..f79708af11 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,8 @@ git-annex (7.20181206) UNRELEASED; urgency=medium --exclude, --want-get, --want-drop to filenames from the branch. Previously, combining --branch with those would fail to match anything. * add, import, findref: Support --time-limit. + * Add --branch option to git-annex find and mildly deprecate findref in + favor of it. -- Joey Hess Thu, 06 Dec 2018 13:39:16 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 253574bf6d..4f99782588 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -174,10 +174,7 @@ data KeyOptions parseKeyOptions :: Parser KeyOptions parseKeyOptions = parseAllOption - <|> WantBranchKeys <$> some (option (str >>= pure . Ref) - ( long "branch" <> metavar paramRef - <> help "operate on files in the specified branch or treeish" - )) + <|> parseBranchKeysOption <|> flag' WantUnusedKeys ( long "unused" <> short 'U' <> help "operate on files found by last run of git-annex unused" @@ -187,6 +184,13 @@ parseKeyOptions = parseAllOption <> help "operate on specified key" )) +parseBranchKeysOption :: Parser KeyOptions +parseBranchKeysOption = + WantBranchKeys <$> some (option (str >>= pure . Ref) + ( long "branch" <> metavar paramRef + <> help "operate on files in the specified branch or treeish" + )) + parseFailedTransfersOption :: Parser KeyOptions parseFailedTransfersOption = flag' WantFailedTransfers ( long "failed" diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index 8b65532dc4..efb373fb40 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -79,22 +79,6 @@ withFilesNotInGit skipdotfiles a l go fs = seekActions $ prepFiltered a $ return $ concat $ segmentPaths (map (\(WorkTreeItem f) -> f) l) fs -withFilesInRefs :: ((FilePath, Key) -> CommandSeek) -> [Git.Ref] -> CommandSeek -withFilesInRefs a = mapM_ go - where - go r = do - matcher <- Limit.getMatcher - (l, cleanup) <- inRepo $ LsTree.lsTree r - forM_ l $ \ti -> do - let f = getTopFilePath $ LsTree.file ti - catKey (LsTree.sha ti) >>= \case - Nothing -> noop - Just k -> - let i = MatchingKey k (AssociatedFile (Just f)) - in whenM (matcher i) $ - a (f, k) - liftIO $ void cleanup - withPathContents :: ((FilePath, FilePath) -> CommandSeek) -> CmdParams -> CommandSeek withPathContents a params = do matcher <- Limit.getMatcher diff --git a/Command/Find.hs b/Command/Find.hs index 46b8d98038..9c7b82016d 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2010-2012 Joey Hess + - Copyright 2010-2018 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -14,6 +14,8 @@ import Command import Annex.Content import Limit import Types.Key +import Types.ActionItem +import Git.FilePath import qualified Utility.Format import Utility.DataUnits @@ -28,6 +30,7 @@ mkCommand = noCommit . noMessages . withGlobalOptions [jsonOptions] data FindOptions = FindOptions { findThese :: CmdParams , formatOption :: Maybe Utility.Format.Format + , keyOptions :: Maybe KeyOptions , batchOption :: BatchMode } @@ -35,6 +38,7 @@ optParser :: CmdParamsDesc -> Parser FindOptions optParser desc = FindOptions <$> cmdParams desc <*> optional parseFormatOption + <*> optional parseBranchKeysOption <*> parseBatchOption parseFormatOption :: Parser Utility.Format.Format @@ -50,7 +54,9 @@ parseFormatOption = seek :: FindOptions -> CommandSeek seek o = case batchOption o of - NoBatch -> withFilesInGit (commandAction . go) + NoBatch -> withKeyOptions (keyOptions o) False + (commandAction . startKeys o) + (withFilesInGit (commandAction . go)) =<< workTreeItems (findThese o) Batch fmt -> batchFilesMatching fmt go where @@ -66,6 +72,11 @@ start o file key = ifM (limited <||> inAnnex key) , stop ) +startKeys :: FindOptions -> (Key, ActionItem) -> CommandStart +startKeys o (key, ActionItemBranchFilePath (BranchFilePath _ topf)) = + start o (getTopFilePath topf) key +startKeys _ _ = stop + showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex () showFormatted format unformatted vars = unlessM (showFullJSON $ JSONChunk vars) $ diff --git a/Command/FindRef.hs b/Command/FindRef.hs index 42ffbad870..f09ed4b9e3 100644 --- a/Command/FindRef.hs +++ b/Command/FindRef.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2014 Joey Hess + - Copyright 2014-2018 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -14,9 +14,14 @@ import qualified Git cmd :: Command cmd = withGlobalOptions [annexedMatchingOptions] $ Find.mkCommand $ command "findref" SectionPlumbing - "lists files in a git ref" + "lists files in a git ref (deprecated)" paramRef (seek <$$> Find.optParser) seek :: Find.FindOptions -> CommandSeek -seek o = (commandAction . uncurry (Find.start o)) - `withFilesInRefs` (map Git.Ref $ Find.findThese o) +seek o = Find.seek o' + where + o' = o + { Find.keyOptions = Just $ WantBranchKeys $ + map Git.Ref (Find.findThese o) + , Find.findThese = [] + } diff --git a/doc/git-annex-find.mdwn b/doc/git-annex-find.mdwn index 6e5a319759..cbd59b5ad3 100644 --- a/doc/git-annex-find.mdwn +++ b/doc/git-annex-find.mdwn @@ -26,6 +26,10 @@ finds files in the current directory and its subdirectories. To list annexed files whose content is not present, specify `--not --in=here` +* `--branch=ref` + + List files in the specified branch or treeish. + * `--print0` Output filenames terminated with nulls, for use with `xargs -0` diff --git a/doc/git-annex-findref.mdwn b/doc/git-annex-findref.mdwn index ce07e0ee46..6406e404bb 100644 --- a/doc/git-annex-findref.mdwn +++ b/doc/git-annex-findref.mdwn @@ -1,6 +1,6 @@ # NAME -git-annex findref - lists files in a git ref +git-annex findref - lists files in a git ref (deprecated) # SYNOPSIS @@ -8,9 +8,9 @@ git annex findref `[ref]` # DESCRIPTION -This is very similar to the `git-annex find` command, but instead of -finding files in the current work tree, it finds files in the -specified git ref. +This is the same as `git annex find` with the --branch option, and you're +encouraged to use that instead unless you need to support older versions of +git-annex. # OPTIONS diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index a0c0f6e0f3..095f2a8169 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -660,7 +660,7 @@ subdirectories). * `findref [ref]` - Lists files in a git ref. + Lists files in a git ref. (deprecated) See [[git-annex-findref]](1) for details.