addunused, dropunused: Support --json and --json-error-messages
This also changes addunused to display the names of the files that it adds. That seems like a general usability improvement, and not displaying the input number does not seem likely to be a problem to a user, since the filename is based on the key. Displaying the filename was necessary to get it and the key included in the json. dropunused does not include the key in the json. It would be possible to add, but would need more changes. And I doubt that dropunused --json would be used in a situation where a program cared which keys were dropped. Note that drop --unused does have the key in its json, so such a program could just use it. Or could just dropkey --batch with the specific keys it wants to drop if it cares about specific keys. Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
972fd05688
commit
1a9af823bc
7 changed files with 69 additions and 39 deletions
|
@ -38,10 +38,12 @@ git-annex (10.20230408) UNRELEASED; urgency=medium
|
||||||
* initremote: Avoid creating a remote that is not encrypted when gpg is
|
* initremote: Avoid creating a remote that is not encrypted when gpg is
|
||||||
broken.
|
broken.
|
||||||
* Support --json and --json-error-messages in more commands
|
* Support --json and --json-error-messages in more commands
|
||||||
(fix, log, migrate, rekey, rmurl, setpresentkey, unannex, undo)
|
(addunused, dropunused, fix, log, migrate, rekey, rmurl,
|
||||||
|
setpresentkey, unannex, undo)
|
||||||
* log: When --raw-date is used, display only seconds from the epoch, as
|
* log: When --raw-date is used, display only seconds from the epoch, as
|
||||||
documented, omitting a trailing "s" that was included in the output
|
documented, omitting a trailing "s" that was included in the output
|
||||||
before.
|
before.
|
||||||
|
* addunused: Display the names of the files that it adds.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Sat, 08 Apr 2023 13:57:18 -0400
|
-- Joey Hess <id@joeyh.name> Sat, 08 Apr 2023 13:57:18 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex command
|
{- git-annex command
|
||||||
-
|
-
|
||||||
- Copyright 2012 Joey Hess <id@joeyh.name>
|
- Copyright 2012-2023 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU AGPL version 3 or higher.
|
- Licensed under the GNU AGPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -15,7 +15,8 @@ import Annex.Ingest
|
||||||
import Command.Unused (withUnusedMaps, UnusedMaps(..), startUnused)
|
import Command.Unused (withUnusedMaps, UnusedMaps(..), startUnused)
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "addunused" SectionMaintenance
|
cmd = withAnnexOptions [jsonOptions] $
|
||||||
|
command "addunused" SectionMaintenance
|
||||||
"add back unused files"
|
"add back unused files"
|
||||||
(paramRepeating paramNumRange) (withParams seek)
|
(paramRepeating paramNumRange) (withParams seek)
|
||||||
|
|
||||||
|
@ -23,20 +24,20 @@ seek :: CmdParams -> CommandSeek
|
||||||
seek = withUnusedMaps start
|
seek = withUnusedMaps start
|
||||||
|
|
||||||
start :: UnusedMaps -> Int -> CommandStart
|
start :: UnusedMaps -> Int -> CommandStart
|
||||||
start = startUnused "addunused" perform
|
start = startUnused go (other "bad") (other "tmp")
|
||||||
(performOther "bad")
|
where
|
||||||
(performOther "tmp")
|
go n key = do
|
||||||
|
let file = "unused." <> keyFile key
|
||||||
perform :: Key -> CommandPerform
|
starting "addunused"
|
||||||
perform key = next $ do
|
(ActionItemTreeFile file)
|
||||||
|
(SeekInput [show n]) $
|
||||||
|
next $ do
|
||||||
logStatus key InfoPresent
|
logStatus key InfoPresent
|
||||||
addSymlink file key Nothing
|
addSymlink file key Nothing
|
||||||
return True
|
return True
|
||||||
where
|
|
||||||
file = "unused." <> keyFile key
|
|
||||||
|
|
||||||
{- The content is not in the annex, but in another directory, and
|
{- The content is not in the annex, but in another directory, and
|
||||||
- it seems better to error out, rather than moving bad/tmp content into
|
- it seems better to error out, rather than moving bad/tmp content
|
||||||
- the annex. -}
|
- into the annex. -}
|
||||||
performOther :: String -> Key -> CommandPerform
|
other n _ _ = giveup $ "cannot addunused " ++ n ++ "content"
|
||||||
performOther other _ = giveup $ "cannot addunused " ++ other ++ "content"
|
|
||||||
|
|
|
@ -20,7 +20,8 @@ import Annex.Content
|
||||||
import qualified Utility.RawFilePath as R
|
import qualified Utility.RawFilePath as R
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "dropunused" SectionMaintenance
|
cmd = withAnnexOptions [jsonOptions] $
|
||||||
|
command "dropunused" SectionMaintenance
|
||||||
"drop unused file content"
|
"drop unused file content"
|
||||||
(paramRepeating paramNumRange) (seek <$$> optParser)
|
(paramRepeating paramNumRange) (seek <$$> optParser)
|
||||||
|
|
||||||
|
@ -42,10 +43,15 @@ seek o = do
|
||||||
withUnusedMaps (start from numcopies mincopies) (rangesToDrop o)
|
withUnusedMaps (start from numcopies mincopies) (rangesToDrop o)
|
||||||
|
|
||||||
start :: Maybe Remote -> NumCopies -> MinCopies -> UnusedMaps -> Int -> CommandStart
|
start :: Maybe Remote -> NumCopies -> MinCopies -> UnusedMaps -> Int -> CommandStart
|
||||||
start from numcopies mincopies = startUnused "dropunused"
|
start from numcopies mincopies = startUnused
|
||||||
(perform from numcopies mincopies)
|
(go (perform from numcopies mincopies))
|
||||||
(performOther gitAnnexBadLocation)
|
(go (performOther gitAnnexBadLocation))
|
||||||
(performOther gitAnnexTmpObjectLocation)
|
(go (performOther gitAnnexTmpObjectLocation))
|
||||||
|
where
|
||||||
|
go a n key = starting "dropunused"
|
||||||
|
(ActionItemOther $ Just $ UnquotedString $ show n)
|
||||||
|
(SeekInput [show n])
|
||||||
|
(a key)
|
||||||
|
|
||||||
perform :: Maybe Remote -> NumCopies -> MinCopies -> Key -> CommandPerform
|
perform :: Maybe Remote -> NumCopies -> MinCopies -> Key -> CommandPerform
|
||||||
perform from numcopies mincopies key = case from of
|
perform from numcopies mincopies key = case from of
|
||||||
|
|
|
@ -322,12 +322,12 @@ unusedSpec m spec
|
||||||
|
|
||||||
{- Seek action for unused content. Finds the number in the maps, and
|
{- Seek action for unused content. Finds the number in the maps, and
|
||||||
- calls one of 3 actions, depending on the type of unused file. -}
|
- calls one of 3 actions, depending on the type of unused file. -}
|
||||||
startUnused :: String
|
startUnused
|
||||||
-> (Key -> CommandPerform)
|
:: (Int -> Key -> CommandStart)
|
||||||
-> (Key -> CommandPerform)
|
-> (Int -> Key -> CommandStart)
|
||||||
-> (Key -> CommandPerform)
|
-> (Int -> Key -> CommandStart)
|
||||||
-> UnusedMaps -> Int -> CommandStart
|
-> UnusedMaps -> Int -> CommandStart
|
||||||
startUnused message unused badunused tmpunused maps n = search
|
startUnused unused badunused tmpunused maps n = search
|
||||||
[ (unusedMap maps, unused)
|
[ (unusedMap maps, unused)
|
||||||
, (unusedBadMap maps, badunused)
|
, (unusedBadMap maps, badunused)
|
||||||
, (unusedTmpMap maps, tmpunused)
|
, (unusedTmpMap maps, tmpunused)
|
||||||
|
@ -337,7 +337,4 @@ startUnused message unused badunused tmpunused maps n = search
|
||||||
search ((m, a):rest) =
|
search ((m, a):rest) =
|
||||||
case M.lookup n m of
|
case M.lookup n m of
|
||||||
Nothing -> search rest
|
Nothing -> search rest
|
||||||
Just key -> starting message
|
Just key -> a n key
|
||||||
(ActionItemOther $ Just $ UnquotedString $ show n)
|
|
||||||
(SeekInput [])
|
|
||||||
(a key)
|
|
||||||
|
|
|
@ -15,7 +15,17 @@ The files will have names starting with "unused."
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
* The [[git-annex-common-options]](1) can be used.
|
* `--json`
|
||||||
|
|
||||||
|
Enable JSON output. This is intended to be parsed by programs that use
|
||||||
|
git-annex. Each line of output is a JSON object.
|
||||||
|
|
||||||
|
* `--json-error-messages`
|
||||||
|
|
||||||
|
Messages that would normally be output to standard error are included in
|
||||||
|
the JSON instead.
|
||||||
|
|
||||||
|
* The [[git-annex-common-options]](1) can also be used.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,16 @@ Or, specify "all" to drop all unused data.
|
||||||
the last repository that is storing their content. Data loss can
|
the last repository that is storing their content. Data loss can
|
||||||
result from using this option.
|
result from using this option.
|
||||||
|
|
||||||
|
* `--json`
|
||||||
|
|
||||||
|
Enable JSON output. This is intended to be parsed by programs that use
|
||||||
|
git-annex. Each line of output is a JSON object.
|
||||||
|
|
||||||
|
* `--json-error-messages`
|
||||||
|
|
||||||
|
Messages that would normally be output to standard error are included in
|
||||||
|
the JSON instead.
|
||||||
|
|
||||||
* Also the [[git-annex-common-options]](1) can be used.
|
* Also the [[git-annex-common-options]](1) can be used.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
@ -36,6 +46,10 @@ Or, specify "all" to drop all unused data.
|
||||||
|
|
||||||
[[git-annex-unused]](1)
|
[[git-annex-unused]](1)
|
||||||
|
|
||||||
|
[[git-annex-drop]](1)
|
||||||
|
|
||||||
|
[[git-annex-copy]](1)
|
||||||
|
|
||||||
# AUTHOR
|
# AUTHOR
|
||||||
|
|
||||||
Joey Hess <id@joeyh.name>
|
Joey Hess <id@joeyh.name>
|
||||||
|
|
|
@ -23,16 +23,16 @@ These commands have been updated to support --json:
|
||||||
* git-annex-rekey
|
* git-annex-rekey
|
||||||
* git-annex-undo
|
* git-annex-undo
|
||||||
* git-annex-migrate
|
* git-annex-migrate
|
||||||
|
* git-annex-addunused
|
||||||
|
* git-annex-dropunused
|
||||||
|
|
||||||
Provisional list of commands that don't support --json and maybe should:
|
Provisional list of commands that don't support --json and maybe should:
|
||||||
|
|
||||||
(Feel free to reorder things to the top)
|
(Feel free to reorder things to the top)
|
||||||
|
|
||||||
* git-annex-addunused
|
|
||||||
* git-annex-adjust
|
* git-annex-adjust
|
||||||
* git-annex-configremote
|
* git-annex-configremote
|
||||||
* git-annex-dead
|
* git-annex-dead
|
||||||
* git-annex-dropunused
|
|
||||||
* git-annex-enableremote
|
* git-annex-enableremote
|
||||||
* git-annex-expire
|
* git-annex-expire
|
||||||
* git-annex-importfeed
|
* git-annex-importfeed
|
||||||
|
|
Loading…
Reference in a new issue