From f3f864fc6d676bc825203a216fe77c2a19c5d581 Mon Sep 17 00:00:00 2001
From: Joey Hess <joeyh@joeyh.name>
Date: Tue, 28 Nov 2023 11:51:43 -0400
Subject: [PATCH] findkeys: Support --largerthan and --smallerthan

Sponsored-by: Brett Eisenberg on Patreon
---
 CHANGELOG                                            |  1 +
 CmdLine/GitAnnex/Options.hs                          |  7 ++++++-
 ...it-annex_findkeys_does_not_know_--largerthan.mdwn |  2 ++
 ...mment_1_f6484f69669439ef49513b84d3bd91cf._comment | 12 ++++++++++++
 4 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 doc/bugs/git-annex_findkeys_does_not_know_--largerthan/comment_1_f6484f69669439ef49513b84d3bd91cf._comment

diff --git a/CHANGELOG b/CHANGELOG
index 4ca82dcea0..1bb37b85f3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,6 +20,7 @@ git-annex (10.20230927) UNRELEASED; urgency=medium
   * Fix bug in git-annex copy --from --to that skipped files that were
     locally present.
   * Make git-annex copy --from --to --fast actually fast.
+  * findkeys: Support --largerthan and --smallerthan.
 
  -- Joey Hess <id@joeyh.name>  Tue, 10 Oct 2023 13:17:31 -0400
 
diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs
index 92649fae34..b5170f3131 100644
--- a/CmdLine/GitAnnex/Options.hs
+++ b/CmdLine/GitAnnex/Options.hs
@@ -266,6 +266,7 @@ annexedMatchingOptions = concat
 keyMatchingOptions :: [AnnexOption]
 keyMatchingOptions = concat
 	[ keyMatchingOptions'
+	, sizeMatchingOptions Limit.LimitAnnexFiles
 	, anythingNothingOptions
 	, combiningOptions 
 	, timeLimitOption 
@@ -398,7 +399,11 @@ fileMatchingOptions' lb =
 		<> help "limit to files whose content is the same as another file matching the glob pattern"
 		<> hidden
 		)
-	, annexOption (setAnnexState . Limit.addLargerThan lb) $ strOption
+	] ++ sizeMatchingOptions lb
+
+sizeMatchingOptions :: Limit.LimitBy -> [AnnexOption]
+sizeMatchingOptions lb =
+	[ annexOption (setAnnexState . Limit.addLargerThan lb) $ strOption
 		( long "largerthan" <> metavar paramSize
 		<> help "match files larger than a size"
 		<> hidden
diff --git a/doc/bugs/git-annex_findkeys_does_not_know_--largerthan.mdwn b/doc/bugs/git-annex_findkeys_does_not_know_--largerthan.mdwn
index 9894921581..591564f055 100644
--- a/doc/bugs/git-annex_findkeys_does_not_know_--largerthan.mdwn
+++ b/doc/bugs/git-annex_findkeys_does_not_know_--largerthan.mdwn
@@ -46,3 +46,5 @@ as if I have misspelled the option:
 
 I am using it for my research project (data science/predictions in plant breeding) and it allows me to keep track of the
 current model iteration and associated results. Thank you for this! 
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/git-annex_findkeys_does_not_know_--largerthan/comment_1_f6484f69669439ef49513b84d3bd91cf._comment b/doc/bugs/git-annex_findkeys_does_not_know_--largerthan/comment_1_f6484f69669439ef49513b84d3bd91cf._comment
new file mode 100644
index 0000000000..05ea2c90a0
--- /dev/null
+++ b/doc/bugs/git-annex_findkeys_does_not_know_--largerthan/comment_1_f6484f69669439ef49513b84d3bd91cf._comment
@@ -0,0 +1,12 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2023-11-28T15:48:09Z"
+ content="""
+Not all options in git-annex-matching-options can be used by findkeys. It
+mentions this when it says "Some of these options can also be used by
+commands to specify which keys they act on."
+
+However in this case, --largerthan and --smallerthan could in fact be made
+to operate on keys, and I've done so.
+"""]]