From aa6919737cf0130d675abb2da18a38b37d497be1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Dec 2022 13:33:24 -0400 Subject: [PATCH] --metadata lexicographical comparisons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 16 +++++++++------- CHANGELOG | 8 ++++++++ doc/git-annex-matching-options.mdwn | 12 ++++++++---- ...dname__62____61__VALUE_string_comparison.mdwn | 2 ++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs index 4b57b1663a..2263e3e0c6 100644 --- a/Annex/MetaData.hs +++ b/Annex/MetaData.hs @@ -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 diff --git a/CHANGELOG b/CHANGELOG index d467886005..709790fdb5 100644 --- 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 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, diff --git a/doc/git-annex-matching-options.mdwn b/doc/git-annex-matching-options.mdwn index 199063a154..510aeb1c76 100644 --- a/doc/git-annex-matching-options.mdwn +++ b/doc/git-annex-matching-options.mdwn @@ -142,11 +142,15 @@ in either of two repositories. matches the glob. The values of metadata fields are matched case insensitively. -* `--metadata fieldnumber` -* `--metadata field<=number` / `--metadata field>=number` +* `--metadata fieldvalue` +* `--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.) diff --git a/doc/todo/--metadata_fieldname__62____61__VALUE_string_comparison.mdwn b/doc/todo/--metadata_fieldname__62____61__VALUE_string_comparison.mdwn index f721d7bf19..a7eea78b13 100644 --- a/doc/todo/--metadata_fieldname__62____61__VALUE_string_comparison.mdwn +++ b/doc/todo/--metadata_fieldname__62____61__VALUE_string_comparison.mdwn @@ -91,3 +91,5 @@ file9 ``` Yann / @nobodyinperson + +> [[fixed|done]] --[[Joey]]