From 1bfea9b3e5b6a831bccf7d75ee16964a850b105a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Apr 2016 13:49:42 -0400 Subject: [PATCH] calckey: New plumbing command, calculates the key that would be used to refer to a file --- CmdLine/GitAnnex.hs | 2 ++ Command/CalcKey.hs | 28 +++++++++++++++ debian/changelog | 2 ++ doc/git-annex-calckey.mdwn | 35 +++++++++++++++++++ doc/git-annex.mdwn | 6 ++++ ..._2ff1a97aea8c0a565a23d5f007e4490c._comment | 31 ++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 Command/CalcKey.hs create mode 100644 doc/git-annex-calckey.mdwn create mode 100644 doc/todo/import_--reinject/comment_4_2ff1a97aea8c0a565a23d5f007e4490c._comment diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index b8c97a30aa..c3049cf9e7 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -25,6 +25,7 @@ import qualified Command.Copy import qualified Command.Get import qualified Command.Fsck import qualified Command.LookupKey +import qualified Command.CalcKey import qualified Command.ContentLocation import qualified Command.ExamineKey import qualified Command.MatchExpression @@ -162,6 +163,7 @@ cmds testoptparser testrunner = , Command.Ungroup.cmd , Command.Vicfg.cmd , Command.LookupKey.cmd + , Command.CalcKey.cmd , Command.ContentLocation.cmd , Command.ExamineKey.cmd , Command.MatchExpression.cmd diff --git a/Command/CalcKey.hs b/Command/CalcKey.hs new file mode 100644 index 0000000000..e018079cb4 --- /dev/null +++ b/Command/CalcKey.hs @@ -0,0 +1,28 @@ +{- git-annex command + - + - Copyright 2016 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.CalcKey where + +import Command +import Backend (genKey) +import Types.KeySource + +cmd :: Command +cmd = noCommit $ noMessages $ dontCheck repoExists $ + command "calckey" SectionPlumbing + "calculates the key that would be used to refer to a file" + (paramRepeating paramFile) + (batchable run (pure ())) + +run :: () -> String -> Annex Bool +run _ file = do + mkb <- genKey (KeySource file file Nothing) Nothing + case mkb of + Just (k, _) -> do + liftIO $ putStrLn $ key2file k + return True + Nothing -> return False diff --git a/debian/changelog b/debian/changelog index f63e3957ee..2636403e2c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ git-annex (6.20160419) UNRELEASED; urgency=medium fixed to not hang when it cannot find locale files. * reinject: When src file's content cannot be verified, leave it alone, instead of deleting it. + * calckey: New plumbing command, calculates the key that would be used + to refer to a file. -- Joey Hess Tue, 19 Apr 2016 12:57:15 -0400 diff --git a/doc/git-annex-calckey.mdwn b/doc/git-annex-calckey.mdwn new file mode 100644 index 0000000000..84fafba4b1 --- /dev/null +++ b/doc/git-annex-calckey.mdwn @@ -0,0 +1,35 @@ +# NAME + +git-annex calckey - calculates the key that would be used to refer to a file + +# SYNOPSIS + +git annex calckey `[file ...]` + +# DESCRIPTION + +This plumbing-level command calculates the key that would be used +to refer to a file. The file is not added to the annex by this command. +The key is output to stdout. + +The backend used is the first listed in the annex.backends configuration +setting. For example, to force use of the SHA1 backend: + + git annex calckey -c annex.backends=SHA1 file + +# OPTIONS + +* `--batch` + + Enable batch mode, in which a line containing the filename is read from + stdin, the key is output to stdout (with a trailing newline), and repeat. + +# SEE ALSO + +[[git-annex]](1) + +# AUTHOR + +Joey Hess + +Warning: Automatically converted into a man page by mdwn2man. Edit with care. diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index b9d9221fda..1b80fe00b2 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -530,6 +530,12 @@ subdirectories). See [[git-annex-lookupkey]](1) for details. +* `calckey [file ...]` + + Calculates the key that would be used to refer to a file. + + See [[git-annex-calckey]](1) for details. + * `contentlocation [key ..]` Looks up location of annexed content for a key. diff --git a/doc/todo/import_--reinject/comment_4_2ff1a97aea8c0a565a23d5f007e4490c._comment b/doc/todo/import_--reinject/comment_4_2ff1a97aea8c0a565a23d5f007e4490c._comment new file mode 100644 index 0000000000..8c6004a00a --- /dev/null +++ b/doc/todo/import_--reinject/comment_4_2ff1a97aea8c0a565a23d5f007e4490c._comment @@ -0,0 +1,31 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 4""" + date="2016-04-20T17:22:06Z" + content=""" +I think this would fit better as an option to `git annex reinject` than +it would to `git annex import`. The latter has too many options anyway. + +It would not be hard to add something like `git annex reinject +--all-known-files`, which would check if a source file hashes to a known +key and ingest its content into the annex if so, otherwise leaving the +source file along. + +That would reinject files that had been added to the repo long ago, and +then were deleted. I don't know if that would be considered suprising +behavior, but it's hard to only ingest files that have a current link in +the repo (because a. git-annex keeps no such index (mostly) and b. branches and c. +tags). Even if it was surprising behavior to reinject old deleted files, +I suppose `git annex unused` could be used to drop such old unused file +contents after reinjecting them. + +There's also the problem of different backends; it seems such a thing would +need to hash a file 5 different ways to make sure no hash of it is known. + +As to adding plumbing, I'm always open to ideas for more useful plumbing. + +* You can use `git annex find` to get eg, a list of keys of files in the + currently checked out branch. +* I've added a `git annex calckey` that can calculate the key that would be + used for a file. (eg, hashing it) +"""]]