calckey: New plumbing command, calculates the key that would be used to refer to a file
This commit is contained in:
parent
9d952fe9d1
commit
1bfea9b3e5
6 changed files with 104 additions and 0 deletions
|
@ -25,6 +25,7 @@ import qualified Command.Copy
|
||||||
import qualified Command.Get
|
import qualified Command.Get
|
||||||
import qualified Command.Fsck
|
import qualified Command.Fsck
|
||||||
import qualified Command.LookupKey
|
import qualified Command.LookupKey
|
||||||
|
import qualified Command.CalcKey
|
||||||
import qualified Command.ContentLocation
|
import qualified Command.ContentLocation
|
||||||
import qualified Command.ExamineKey
|
import qualified Command.ExamineKey
|
||||||
import qualified Command.MatchExpression
|
import qualified Command.MatchExpression
|
||||||
|
@ -162,6 +163,7 @@ cmds testoptparser testrunner =
|
||||||
, Command.Ungroup.cmd
|
, Command.Ungroup.cmd
|
||||||
, Command.Vicfg.cmd
|
, Command.Vicfg.cmd
|
||||||
, Command.LookupKey.cmd
|
, Command.LookupKey.cmd
|
||||||
|
, Command.CalcKey.cmd
|
||||||
, Command.ContentLocation.cmd
|
, Command.ContentLocation.cmd
|
||||||
, Command.ExamineKey.cmd
|
, Command.ExamineKey.cmd
|
||||||
, Command.MatchExpression.cmd
|
, Command.MatchExpression.cmd
|
||||||
|
|
28
Command/CalcKey.hs
Normal file
28
Command/CalcKey.hs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{- git-annex command
|
||||||
|
-
|
||||||
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
||||||
|
-
|
||||||
|
- 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
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -6,6 +6,8 @@ git-annex (6.20160419) UNRELEASED; urgency=medium
|
||||||
fixed to not hang when it cannot find locale files.
|
fixed to not hang when it cannot find locale files.
|
||||||
* reinject: When src file's content cannot be verified, leave it alone,
|
* reinject: When src file's content cannot be verified, leave it alone,
|
||||||
instead of deleting it.
|
instead of deleting it.
|
||||||
|
* calckey: New plumbing command, calculates the key that would be used
|
||||||
|
to refer to a file.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Tue, 19 Apr 2016 12:57:15 -0400
|
-- Joey Hess <id@joeyh.name> Tue, 19 Apr 2016 12:57:15 -0400
|
||||||
|
|
||||||
|
|
35
doc/git-annex-calckey.mdwn
Normal file
35
doc/git-annex-calckey.mdwn
Normal file
|
@ -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 <id@joeyh.name>
|
||||||
|
|
||||||
|
Warning: Automatically converted into a man page by mdwn2man. Edit with care.
|
|
@ -530,6 +530,12 @@ subdirectories).
|
||||||
|
|
||||||
See [[git-annex-lookupkey]](1) for details.
|
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 ..]`
|
* `contentlocation [key ..]`
|
||||||
|
|
||||||
Looks up location of annexed content for a key.
|
Looks up location of annexed content for a key.
|
||||||
|
|
|
@ -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)
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue