reinject: Added --guesskeys option
Sponsored-by: Noam Kremen on Patreon
This commit is contained in:
parent
19cac6fa14
commit
d98aa35b3b
3 changed files with 46 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
git-annex (10.20230627) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* reinject: Added --guesskeys option.
|
||||||
|
|
||||||
|
-- Joey Hess <id@joeyh.name> Mon, 26 Jun 2023 13:10:40 -0400
|
||||||
|
|
||||||
git-annex (10.20230626) upstream; urgency=medium
|
git-annex (10.20230626) upstream; urgency=medium
|
||||||
|
|
||||||
* Split out two new commands, git-annex pull and git-annex push.
|
* Split out two new commands, git-annex pull and git-annex push.
|
||||||
|
|
|
@ -29,6 +29,7 @@ cmd = withAnnexOptions [backendOption, jsonOptions] $
|
||||||
data ReinjectOptions = ReinjectOptions
|
data ReinjectOptions = ReinjectOptions
|
||||||
{ params :: CmdParams
|
{ params :: CmdParams
|
||||||
, knownOpt :: Bool
|
, knownOpt :: Bool
|
||||||
|
, guessKeysOpt :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser ReinjectOptions
|
optParser :: CmdParamsDesc -> Parser ReinjectOptions
|
||||||
|
@ -39,9 +40,16 @@ optParser desc = ReinjectOptions
|
||||||
<> help "inject all known files"
|
<> help "inject all known files"
|
||||||
<> hidden
|
<> hidden
|
||||||
)
|
)
|
||||||
|
<*> switch
|
||||||
|
( long "guesskeys"
|
||||||
|
<> help "inject files that are named like keys"
|
||||||
|
<> hidden
|
||||||
|
)
|
||||||
|
|
||||||
seek :: ReinjectOptions -> CommandSeek
|
seek :: ReinjectOptions -> CommandSeek
|
||||||
seek os
|
seek os
|
||||||
|
| guessKeysOpt os && knownOpt os = giveup "Cannot combine --known with --guesskeys"
|
||||||
|
| guessKeysOpt os = withStrings (commandAction . startGuessKeys) (params os)
|
||||||
| knownOpt os = withStrings (commandAction . startKnown) (params os)
|
| knownOpt os = withStrings (commandAction . startKnown) (params os)
|
||||||
| otherwise = withPairs (commandAction . startSrcDest) (params os)
|
| otherwise = withPairs (commandAction . startSrcDest) (params os)
|
||||||
|
|
||||||
|
@ -66,6 +74,24 @@ startSrcDest (si, (src, dest))
|
||||||
src' = toRawFilePath src
|
src' = toRawFilePath src
|
||||||
ai = ActionItemOther (Just (QuotedPath src'))
|
ai = ActionItemOther (Just (QuotedPath src'))
|
||||||
|
|
||||||
|
startGuessKeys :: FilePath -> CommandStart
|
||||||
|
startGuessKeys src = starting "reinject" ai si $ notAnnexed src' $
|
||||||
|
case fileKey (toRawFilePath (takeFileName src)) of
|
||||||
|
Just key -> ifM (verifyKeyContent key src')
|
||||||
|
( perform src' key
|
||||||
|
, do
|
||||||
|
qp <- coreQuotePath <$> Annex.getGitConfig
|
||||||
|
giveup $ decodeBS $ quote qp $ QuotedPath src'
|
||||||
|
<> " does not have expected content"
|
||||||
|
)
|
||||||
|
Nothing -> do
|
||||||
|
warning "Not named like an object file; skipping"
|
||||||
|
next $ return True
|
||||||
|
where
|
||||||
|
src' = toRawFilePath src
|
||||||
|
ai = ActionItemOther (Just (QuotedPath src'))
|
||||||
|
si = SeekInput [src]
|
||||||
|
|
||||||
startKnown :: FilePath -> CommandStart
|
startKnown :: FilePath -> CommandStart
|
||||||
startKnown src = starting "reinject" ai si $ notAnnexed src' $ do
|
startKnown src = starting "reinject" ai si $ notAnnexed src' $ do
|
||||||
(key, _) <- genKey ks nullMeterUpdate =<< defaultBackend
|
(key, _) <- genKey ks nullMeterUpdate =<< defaultBackend
|
||||||
|
|
|
@ -54,6 +54,20 @@ needing to specify the dest file.
|
||||||
Specify the key-value backend to use when checking if a file is known
|
Specify the key-value backend to use when checking if a file is known
|
||||||
with the `--known` option.
|
with the `--known` option.
|
||||||
|
|
||||||
|
* `--guesskeys`
|
||||||
|
|
||||||
|
With this option, each specified source file is checked to see if it
|
||||||
|
has the name of a git-annex key, and if so it is imported as the content
|
||||||
|
of that key.
|
||||||
|
|
||||||
|
This can be used to pluck git-annex objects out of `lost+found`,
|
||||||
|
as long as the original filename has not been lost,
|
||||||
|
and is particularly useful when using key-value backends that don't hash
|
||||||
|
to the content of a file.
|
||||||
|
|
||||||
|
When the key-value backend does support hashing, the content of the file
|
||||||
|
is verified before importing it.
|
||||||
|
|
||||||
* `--json`
|
* `--json`
|
||||||
|
|
||||||
Enable JSON output. This is intended to be parsed by programs that use
|
Enable JSON output. This is intended to be parsed by programs that use
|
||||||
|
|
Loading…
Reference in a new issue