]> dgit.raspbian.org Git - git-annex.git/commitdiff
examinekey: Added a "file" format variable
authorJoey Hess <joeyh@joeyh.name>
Mon, 16 Nov 2020 13:56:32 +0000 (09:56 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 16 Nov 2020 13:59:11 +0000 (09:59 -0400)
For consistency with find, and for easier scripting.

CHANGELOG
Command/ExamineKey.hs
Command/Find.hs
Command/Whereis.hs
doc/git-annex-examinekey.mdwn
doc/todo/calckey___91__--path__93___given_a_checksum_and_filename__63__/comment_6_aa8c191593789900e966a37f9117dd97._comment [new file with mode: 0644]

index 0052f51165861faef6d0993de0d7f3fba32ea7f1..3b6aa86d272c0d640ea87214fd1583bbc90302b5 100644 (file)
--- 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 <id@joeyh.name>  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
index 4fe092d9abeb051bc27608482ba3b374f12b96ab..668a2f5636f4b05b6c04126687dc32e445662c55 100644 (file)
@@ -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 
index d3604d806e73a3783376f05e98ba547cff8bdd5e..96f1f3b8bc30b0998085689ea9731888ce417ec7 100644 (file)
@@ -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)
index ec4026968c49287b0605399212b94bdd4e4db0e9..e8d103bdb8b5d74ea204dec62c6f28bc979de17d 100644 (file)
@@ -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
index 19c4be112aa77362abf16bb6118ec7d5615177d3..2f7948afc33ac7fd75c67d3856381f07e96a0bce 100644 (file)
@@ -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 (file)
index 0000000..9eb50aa
--- /dev/null
@@ -0,0 +1,7 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 6"""
+ date="2020-11-16T13:52:12Z"
+ content="""
+Good idea, I added ${file}
+"""]]