From 7d5b25515ce8e22116f95e3679953ea956b4f04f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 15 Dec 2013 14:02:23 -0400 Subject: [PATCH] Add plumbing-level lookupkey command. --- Annex/CatFile.hs | 2 +- Command/LookupKey.hs | 26 ++++++++++++++++++++++++++ GitAnnex.hs | 2 ++ debian/changelog | 1 + doc/git-annex.mdwn | 7 +++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Command/LookupKey.hs diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 812d032c6a..54a4d10991 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -119,7 +119,7 @@ catKeyChecked needhead ref@(Ref r) = - For command-line git-annex use, that doesn't matter. It's perfectly - reasonable for things staged in the index after the currently running - git-annex process to not be noticed by it. However, we do want to see - - what's in the index, since it may have uncommitted changes not in HEAD> + - what's in the index, since it may have uncommitted changes not in HEAD - - For the assistant, this is much more of a problem, since it commits - files and then needs to be able to immediately look up their keys. diff --git a/Command/LookupKey.hs b/Command/LookupKey.hs new file mode 100644 index 0000000000..7964213fe3 --- /dev/null +++ b/Command/LookupKey.hs @@ -0,0 +1,26 @@ +{- git-annex command + - + - Copyright 2013 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.LookupKey where + +import Common.Annex +import Command +import Annex.CatFile +import Types.Key + +def :: [Command] +def = [notBareRepo $ + command "lookupkey" (paramRepeating paramFile) seek + SectionPlumbing "looks up key used for file"] + +seek :: [CommandSeek] +seek = [withStrings start] + +start :: String -> CommandStart +start file = do + liftIO . maybe exitFailure (putStrLn . key2file) =<< catKeyFile file + stop diff --git a/GitAnnex.hs b/GitAnnex.hs index 5b69a2d9dd..8ea0c9569e 100644 --- a/GitAnnex.hs +++ b/GitAnnex.hs @@ -20,6 +20,7 @@ import qualified Command.Drop import qualified Command.Move import qualified Command.Copy import qualified Command.Get +import qualified Command.LookupKey import qualified Command.FromKey import qualified Command.DropKey import qualified Command.TransferKey @@ -124,6 +125,7 @@ cmds = concat , Command.Schedule.def , Command.Ungroup.def , Command.Vicfg.def + , Command.LookupKey.def , Command.FromKey.def , Command.DropKey.def , Command.TransferKey.def diff --git a/debian/changelog b/debian/changelog index 128a161f6d..f39df1f8d4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ git-annex (5.20131214) UNRELEASED; urgency=low * Fix test suite to cover lock --force change. + * Add plumbing-level lookupkey command. -- Joey Hess Sun, 15 Dec 2013 13:32:49 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 4602849c2d..5d61b8b40f 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -727,6 +727,13 @@ subdirectories). point to annexed content. Also handles injecting changes to unlocked files into the annex. +* `lookupkey [file ...]` + + This plumbing-level command looks up the key used for a file in the + index. The key is output to stdout. If there is no key (because + the file is not added to git, or is not a git-annex managed file), + nothing is output, and it exits nonzero. + * `fromkey key file` This plumbing-level command can be used to manually set up a file