unused: Support --json and --json-error-messages
Generalized AddJSONActionItemField to allow it to add several fields. Not entirely happy with that, since the names of the fields have to be carefully chosen to not conflict with other json fields. And fields added that way can't be parsed back in FromJSON, except for the "fields" field that is special cased for metadata. Still, I couldn't see another way to do it. Also, omit file:null from the json output. Which does affect other commands, eg git-annex whereis --all --json. Hopefully that won't break something that expects a null file. If it did, that could be reverted, but it would be ugly to have file:null in the unused --json Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
dd90c7abda
commit
c208442292
6 changed files with 40 additions and 16 deletions
|
@ -12,7 +12,7 @@ import Annex.MetaData
|
|||
import Annex.VectorClock
|
||||
import Logs.MetaData
|
||||
import Annex.WorkTree
|
||||
import Messages.JSON (JSONActionItem(..), AddJSONActionItemFields(..))
|
||||
import Messages.JSON (JSONActionItem(..), AddJSONActionItemField(..))
|
||||
import Types.Messages
|
||||
import Utility.Aeson
|
||||
import Utility.SafeOutput
|
||||
|
@ -127,7 +127,7 @@ perform c o k = case getSet o of
|
|||
cleanup :: Key -> CommandCleanup
|
||||
cleanup k = do
|
||||
m <- getCurrentMetaData k
|
||||
case toJSON' (AddJSONActionItemFields m) of
|
||||
case toJSON' (AddJSONActionItemField "fields" m) of
|
||||
Object o -> maybeShowJSON $ AesonObject o
|
||||
_ -> noop
|
||||
showLongNote $ UnquotedString $ unlines $ concatMap showmeta $
|
||||
|
|
|
@ -34,15 +34,19 @@ import Logs.View (is_branchView)
|
|||
import Annex.BloomFilter
|
||||
import qualified Database.Keys
|
||||
import Annex.InodeSentinal
|
||||
import Utility.Aeson
|
||||
import Messages.JSON (AddJSONActionItemField(..))
|
||||
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Char8 as S8
|
||||
import Data.Char
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "unused" SectionMaintenance "look for unused file content"
|
||||
paramNothing (seek <$$> optParser)
|
||||
cmd = withAnnexOptions [jsonOptions] $
|
||||
command "unused" SectionMaintenance "look for unused file content"
|
||||
paramNothing (seek <$$> optParser)
|
||||
|
||||
data UnusedOptions = UnusedOptions
|
||||
{ fromRemote :: Maybe RemoteName
|
||||
|
@ -105,13 +109,18 @@ checkRemoteUnused remotename refspec = go =<< Remote.nameToUUID remotename
|
|||
Just ks -> excludeReferenced refspec ks
|
||||
Nothing -> giveup "This repository is read-only."
|
||||
|
||||
check :: FilePath -> ([(Int, Key)] -> String) -> Annex [Key] -> Int -> Annex Int
|
||||
check file msg a c = do
|
||||
check :: String -> ([(Int, Key)] -> String) -> Annex [Key] -> Int -> Annex Int
|
||||
check fileprefix msg a c = do
|
||||
l <- a
|
||||
let unusedlist = number c l
|
||||
unless (null l) $
|
||||
showLongNote $ UnquotedString $ msg unusedlist
|
||||
updateUnusedLog (toRawFilePath file) (M.fromList unusedlist)
|
||||
let v = V.fromList $ map (\(n, k) -> (show n, serializeKey k)) unusedlist
|
||||
let f = (if null fileprefix then "unused" else fileprefix) ++ "-list"
|
||||
case toJSON' (AddJSONActionItemField f v) of
|
||||
Object o -> maybeShowJSON $ AesonObject o
|
||||
_ -> noop
|
||||
updateUnusedLog (toRawFilePath fileprefix) (M.fromList unusedlist)
|
||||
return $ c + length l
|
||||
|
||||
number :: Int -> [a] -> [(Int, a)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue