diff --git a/Command/WhereUsed.hs b/Command/WhereUsed.hs index 0117ffe60c..a4c986d8ce 100644 --- a/Command/WhereUsed.hs +++ b/Command/WhereUsed.hs @@ -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, ']'] diff --git a/doc/bugs/whereused_false_match_on_longer_key.mdwn b/doc/bugs/whereused_false_match_on_longer_key.mdwn index 30a5f0ef36..19b1f9769b 100644 --- a/doc/bugs/whereused_false_match_on_longer_key.mdwn +++ b/doc/bugs/whereused_false_match_on_longer_key.mdwn @@ -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]]