]> dgit.raspbian.org Git - git-annex.git/commitdiff
better key matching with a regexp
authorJoey Hess <joeyh@joeyh.name>
Wed, 14 Jul 2021 20:28:07 +0000 (16:28 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 14 Jul 2021 20:31:17 +0000 (16:31 -0400)
Handles keys that are substrings of other keys, as well as pointer files
that contain a newline after the key.

Note that -S does not match regexp, while -G does by default. Docs are
not clear, determined experimentally. The only other difference in
changing to -G is that if a file used to contain the key and changed
in some way, while still containing the key, -G will match and -S would
not. So eg, annex links that git annex fix rewrites will match, and
files that change lock status will match. Which is an improvement anyway.

Sponsored-by: Jochen Bartl on Patreon
Command/WhereUsed.hs
doc/bugs/whereused_false_match_on_longer_key.mdwn

index 0117ffe60c3fbc9ed8bcc202b0138202e61236a3..a4c986d8ce56403aa4b3653be9542ee6ee0987c7 100644 (file)
@@ -140,11 +140,24 @@ searchLog key ps a = Annex.inRepo $ \repo -> do
                , Param "--no-abbrev"
                -- Only find the most recent commit, for speed.
                , Param "-n1"
-               -- Find commits that contain the key.
-               , Param ("-S" ++ fromRawFilePath (keyFile key))
+               -- Be sure to treat -G as a regexp.
+               , Param "--basic-regexp"
+               -- Find commits that contain the key. The object has to
+               -- end with the key to avoid confusion with longer keys,
+               -- so a regexp is used. Since annex pointer files
+               -- may contain a newline followed by perhaps something
+               -- else, that is also matched.
+               , Param ("-G" ++ escapeRegexp (fromRawFilePath (keyFile key)) ++ "($|\n)")
                -- Skip commits where the file was deleted,
                -- only find those where it was added or modified.
                , Param "--diff-filter=ACMRTUX"
                -- Output the raw diff.
                , Param "--raw"
                ] ++ ps
+
+escapeRegexp :: String -> String
+escapeRegexp = concatMap esc
+  where
+       esc c
+               | isAscii c && isAlphaNum c = [c]
+               | otherwise = ['[', c, ']']
index 30a5f0ef36a64b4a3fd8ac4dca03622eedffbe20..19b1f9769b4c3e57b97475677bd125f994724055 100644 (file)
@@ -5,3 +5,5 @@ One way this is likely to happen is SHA256 keys with and without extension,
 for the same content. Or WORM keys with similar filenames.
 
 --[[Joey]]
+
+> [[fixed|done]] --[[Joey]]