--metadata lexicographical comparisons
authorJoey Hess <joeyh@joeyh.name>
Mon, 12 Dec 2022 17:33:24 +0000 (13:33 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 12 Dec 2022 17:33:24 +0000 (13:33 -0400)
Change --metadata comparisons < > <= and >= to fall back to lexicographical
comparisons when one or both values being compared are not numbers.

Sponsored-by: Erik Bjäreholt on Patreon
Annex/MetaData.hs
CHANGELOG
doc/git-annex-matching-options.mdwn
doc/todo/--metadata_fieldname__62____61__VALUE_string_comparison.mdwn

index 4b57b1663a9d6aa6e596d409031f8a8b77498704..2263e3e0c6140ad6c530237f600add9b4e47ed16 100644 (file)
@@ -104,15 +104,17 @@ parseMetaDataMatcher p = (,)
        (f, op_v) = break (`elem` "=<>") p
        matcher = case op_v of
                ('=':v) -> checkglob v
-               ('<':'=':v) -> checkcmp (<=) v
-               ('<':v) -> checkcmp (<) v
-               ('>':'=':v) -> checkcmp (>=) v
-               ('>':v) -> checkcmp (>) v
+               ('<':'=':v) -> checkcmp (<=) (<=) v
+               ('<':v) -> checkcmp (<) (<) v
+               ('>':'=':v) -> checkcmp (>=) (>=) v
+               ('>':v) -> checkcmp (>) (>) v
                _ -> checkglob ""
        checkglob v =
                let cglob = compileGlob v CaseInsensative (GlobFilePath False)
                in matchGlob cglob . decodeBS . fromMetaValue
-       checkcmp cmp v v' = case (doubleval v, doubleval (decodeBS (fromMetaValue v'))) of
-               (Just d, Just d') -> d' `cmp` d
-               _ -> False
+       checkcmp cmp cmp' v mv' = 
+               let v' = decodeBS (fromMetaValue mv')
+               in case (doubleval v, doubleval v') of
+                       (Just d, Just d') -> d' `cmp` d
+                       _ -> v' `cmp'` v
        doubleval v = readish v :: Maybe Double
index d4678860058df1031d882317036c65dea6b40e88..709790fdb5564cbc10c1b0d2a3655e2759a9ffc5 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,11 @@
+git-annex (10.20221213) UNRELEASED; urgency=medium
+
+  * Change --metadata comparisons < > <= and >= to fall back to
+    lexicographical comparisons when one or both values being compared
+    are not numbers.
+
+ -- Joey Hess <id@joeyh.name>  Mon, 12 Dec 2022 13:04:54 -0400
+
 git-annex (10.20221212) upstream; urgency=medium
 
   * Fix a hang that occasionally occurred during commands such as move,
index 199063a15418c61a9da2ccb5ce4bbb8086a5a9f4..510aeb1c7674fdba579e1390c28b29de7c2732ca 100644 (file)
@@ -142,11 +142,15 @@ in either of two repositories.
   matches the glob. The values of metadata fields are matched case
   insensitively.
 
-* `--metadata field<number` / `--metadata field>number`
-* `--metadata field<=number` / `--metadata field>=number`
+* `--metadata field<value` / `--metadata field>value`
+* `--metadata field<=value` / `--metadata field>=value`
 
-  Matches only when there is a metadata field attached with a value that
-  is a number and is less than or greater than the specified number.
+  Matches only when there is a metadata field attached with a value
+  that is less then or greater than the specified value, respectively.
+
+  When both values are numbers, the comparison is done numerically.
+  When one value is not a number, the values are instead compared
+  lexicographically.
 
   (Note that you will need to quote the second parameter to avoid
   the shell doing redirection.)
index f721d7bf19efbeed44890691d444f1292300f9dc..a7eea78b1363a101986a9d2a3a464328914642b6 100644 (file)
@@ -91,3 +91,5 @@ file9
 ```
 
 Yann / @nobodyinperson
+
+> [[fixed|done]] --[[Joey]]