From 0b2dd374d84c9d9563ec337e934b2f7fceabe8bb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 20 Dec 2022 15:42:34 -0400 Subject: [PATCH] --anything and --nothing Added --anything (and --nothing). Eg, git-annex find --anything will list all annexed files whether or not the content is present. This is slightly faster and clearer than --include=* or --exclude=* While I can't imagine how --nothing will be used, preferred content expressions already had anything and nothing, so might as well support both as matching options as well. Sponsored-by: Dartmouth College's Datalad project --- CHANGELOG | 3 +++ CmdLine/GitAnnex/Options.hs | 10 +++++++ Limit.hs | 10 ++++++- doc/git-annex-find.mdwn | 2 +- doc/git-annex-matching-options.mdwn | 9 +++++++ ...0__or_alike__41___to_find_and_findref.mdwn | 2 ++ ..._8407146882e97ee8510f28df2ba5129c._comment | 26 +++++++++++++++++++ 7 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 doc/todo/add_--all___40__or_alike__41___to_find_and_findref/comment_1_8407146882e97ee8510f28df2ba5129c._comment diff --git a/CHANGELOG b/CHANGELOG index 75d1b6eaa4..7a423117d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ git-annex (10.20221213) UNRELEASED; urgency=medium * Improve handling of some .git/annex/ subdirectories being on other filesystems, in the bittorrent special remote, and youtube-dl integration, and git-annex addurl. + * Added --anything (and --nothing). Eg, git-annex find --anything + will list all annexed files whether or not the content is present. + This is slightly faster and clearer than --include=* or --exclude=* -- Joey Hess Mon, 12 Dec 2022 13:04:54 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index df24b7f1f9..de481d25e5 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -378,6 +378,16 @@ fileMatchingOptions' lb = <> help "match files smaller than a size" <> hidden ) + , annexFlag (setAnnexState Limit.addAnything) + ( long "anything" + <> help "match all files" + <> hidden + ) + , annexFlag (setAnnexState Limit.addNothing) + ( long "nothing" + <> help "don't match any files" + <> hidden + ) ] combiningOptions :: [AnnexOption] diff --git a/Limit.hs b/Limit.hs index 79d7e47942..b105c9fb88 100644 --- a/Limit.hs +++ b/Limit.hs @@ -1,6 +1,6 @@ {- user-specified limits on files to act on - - - Copyright 2011-2021 Joey Hess + - Copyright 2011-2022 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -431,6 +431,10 @@ limitUnused = MatchFiles isunused k = S.member k <$> unusedKeys +{- Adds a limit that matches anything. -} +addAnything :: Annex () +addAnything = addLimit (Right limitAnything) + {- Limit that matches any version of any file or key. -} limitAnything :: MatchFiles Annex limitAnything = MatchFiles @@ -441,6 +445,10 @@ limitAnything = MatchFiles , matchNeedsLocationLog = False } +{- Adds a limit that never matches. -} +addNothing :: Annex () +addNothing = addLimit (Right limitNothing) + {- Limit that never matches. -} limitNothing :: MatchFiles Annex limitNothing = MatchFiles diff --git a/doc/git-annex-find.mdwn b/doc/git-annex-find.mdwn index 2decd932b8..9f578092a9 100644 --- a/doc/git-annex-find.mdwn +++ b/doc/git-annex-find.mdwn @@ -22,7 +22,7 @@ finds files in the current directory and its subdirectories. currently present. Specifying any of the matching options will override this default behavior. - To list all annexed files, present or not, specify `--include "*"`. + To list all annexed files, present or not, specify `--anything`. To list annexed files whose content is not present, specify `--not --in=here` diff --git a/doc/git-annex-matching-options.mdwn b/doc/git-annex-matching-options.mdwn index 510aeb1c76..41de0d77b2 100644 --- a/doc/git-annex-matching-options.mdwn +++ b/doc/git-annex-matching-options.mdwn @@ -245,6 +245,15 @@ in either of two repositories. This is only available to use when git-annex was built with the MagicMime build flag. +* `--anything` + + Always matches. One way this can be useful is `git-annex find --anything` + will list all annexed files, whether their content is present or not. + +* `--nothing` + + Never matches. (Same as `--not --anything`) + * `--not` Inverts the next matching option. For example, to match diff --git a/doc/todo/add_--all___40__or_alike__41___to_find_and_findref.mdwn b/doc/todo/add_--all___40__or_alike__41___to_find_and_findref.mdwn index aa02cd747a..c6a57de89b 100644 --- a/doc/todo/add_--all___40__or_alike__41___to_find_and_findref.mdwn +++ b/doc/todo/add_--all___40__or_alike__41___to_find_and_findref.mdwn @@ -6,3 +6,5 @@ I found no other way to make `find` (or `findref`) to do what is needed. So I fe [[!meta author=yoh]] [[!tag projects/datalad]] + +> [[done]]; added --anything (and --nothing). --[[Joey]] diff --git a/doc/todo/add_--all___40__or_alike__41___to_find_and_findref/comment_1_8407146882e97ee8510f28df2ba5129c._comment b/doc/todo/add_--all___40__or_alike__41___to_find_and_findref/comment_1_8407146882e97ee8510f28df2ba5129c._comment new file mode 100644 index 0000000000..b3b68572df --- /dev/null +++ b/doc/todo/add_--all___40__or_alike__41___to_find_and_findref/comment_1_8407146882e97ee8510f28df2ba5129c._comment @@ -0,0 +1,26 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2022-12-20T19:21:34Z" + content=""" +Using --copies necessarily loads up the location tracking log for +each file, which does add overhead. + +Any other matching option that matches everything will work just as well +for you. I think that `git-annex find --include='*'` is the best thing +currently available. Indeed, the git-annex-find man page suggests to use +that. The only overhead is an unncessary glob match, which +should be almost unmeasurable. + +It does seem like it might be worth adding --anything that simply matches +anything. Preferred content expressions already support "anything". And +`git-annex find --anything` makes sense and is easier to type. + +But, you'll probably be better off using `--include='*'` since it works +with older versions of git-annex. + +(--all is the wrong name for such an option since it already has another +meaning, although I don't think it makes sense for `git-annex find` to +support --all, it has certianly been requested before by people who want to +generalize that existing meaning..) +"""]]