diff --git a/CHANGELOG b/CHANGELOG index 0052f51165..3b6aa86d27 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +git-annex (8.20201117) UNRELEASED; urgency=medium + + * examinekey: Added a "file" format variable for consistency with find, + and for easier scripting. + + -- Joey Hess Mon, 16 Nov 2020 09:38:32 -0400 + git-annex (8.20201116) upstream; urgency=medium * move: Fix a regression in the last release that made move --to not diff --git a/Command/ExamineKey.hs b/Command/ExamineKey.hs index 4fe092d9ab..668a2f5636 100644 --- a/Command/ExamineKey.hs +++ b/Command/ExamineKey.hs @@ -9,7 +9,7 @@ module Command.ExamineKey where import Command import qualified Utility.Format -import Command.Find (parseFormatOption, showFormatted, keyVars) +import Command.Find (parseFormatOption, showFormatted, formatVars) import Annex.Link import Backend import Types.Backend @@ -57,7 +57,7 @@ run o _ input = do showFormatted (format o) (serializeKey' k) $ [ ("objectpath", fromRawFilePath objectpath) , ("objectpointer", fromRawFilePath objectpointer) - ] ++ keyVars k + ] ++ formatVars k af return True where -- Parse the input, which is either a key, or in batch mode diff --git a/Command/Find.hs b/Command/Find.hs index d3604d806e..96f1f3b8bc 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -75,7 +75,8 @@ seek o = do start :: FindOptions -> SeekInput -> RawFilePath -> Key -> CommandStart start o _ file key = startingCustomOutput key $ do - showFormatted (formatOption o) file $ ("file", fromRawFilePath file) : keyVars key + showFormatted (formatOption o) file + (formatVars key (AssociatedFile (Just file))) next $ return True startKeys :: FindOptions -> (SeekInput, Key, ActionItem) -> CommandStart @@ -92,8 +93,9 @@ showFormatted format unformatted vars = Utility.Format.format formatter $ M.fromList vars -keyVars :: Key -> [(String, String)] -keyVars key = +formatVars :: Key -> AssociatedFile -> [(String, String)] +formatVars key (AssociatedFile af) = + (maybe id (\f l -> (("file", fromRawFilePath f) : l)) af) [ ("key", serializeKey key) , ("backend", decodeBS $ formatKeyVariety $ fromKey keyVariety key) , ("bytesize", size show) diff --git a/Command/Whereis.hs b/Command/Whereis.hs index ec4026968c..e8d103bdb8 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -95,10 +95,8 @@ perform o remotemap key ai = do mapM_ (showRemoteUrls remotemap) urls Just formatter -> liftIO $ do - let vs = catMaybes - [ fmap (("file",) . fromRawFilePath) - (actionItemWorkTreeFile ai) - ] ++ Command.Find.keyVars key + let vs = Command.Find.formatVars key + (AssociatedFile (actionItemWorkTreeFile ai)) let showformatted muuid murl = putStr $ Utility.Format.format formatter $ M.fromList $ vs ++ catMaybes diff --git a/doc/git-annex-examinekey.mdwn b/doc/git-annex-examinekey.mdwn index 19c4be112a..2f7948afc3 100644 --- a/doc/git-annex-examinekey.mdwn +++ b/doc/git-annex-examinekey.mdwn @@ -28,7 +28,8 @@ that can be determined purely by looking at the key. These variables are also available for use in formats: ${key}, ${backend}, ${bytesize}, ${humansize}, ${keyname}, ${hashdirlower}, ${hashdirmixed}, - ${mtime} (for the mtime field of a WORM key). + ${mtime} (for the mtime field of a WORM key), ${file} (when a filename is + provided to examinekey). Also, '\\n' is a newline, '\\000' is a NULL, etc. diff --git a/doc/todo/calckey___91__--path__93___given_a_checksum_and_filename__63__/comment_6_aa8c191593789900e966a37f9117dd97._comment b/doc/todo/calckey___91__--path__93___given_a_checksum_and_filename__63__/comment_6_aa8c191593789900e966a37f9117dd97._comment new file mode 100644 index 0000000000..9eb50aa4a6 --- /dev/null +++ b/doc/todo/calckey___91__--path__93___given_a_checksum_and_filename__63__/comment_6_aa8c191593789900e966a37f9117dd97._comment @@ -0,0 +1,7 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 6""" + date="2020-11-16T13:52:12Z" + content=""" +Good idea, I added ${file} +"""]]