export --json: Fill in the file field

Like import was using ActionItemWorkTreeFile, it's ok to use it for export,
even though it might not correspond with a file in the work tree.
And renamed it to ActionItemTreeFile to make that clearer.

Note that when an export has to rename files, it still uses
ActionItemOther, so file will still be null in that case, but as no file is
being transferred, that seems ok.
This commit is contained in:
Joey Hess 2021-03-12 14:09:19 -04:00
parent f87c63d998
commit 6481991208
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
10 changed files with 37 additions and 22 deletions

View file

@ -3,6 +3,7 @@ git-annex (8.20210311) UNRELEASED; urgency=medium
* export: When a submodule is in the tree to be exported, skip it. * export: When a submodule is in the tree to be exported, skip it.
* import: When the previously exported tree contained a submodule, * import: When the previously exported tree contained a submodule,
preserve it in the imported tree so it does not get deleted. preserve it in the imported tree so it does not get deleted.
* export --json: Fill in the file field.
-- Joey Hess <id@joeyh.name> Fri, 12 Mar 2021 12:06:37 -0400 -- Joey Hess <id@joeyh.name> Fri, 12 Mar 2021 12:06:37 -0400

View file

@ -110,7 +110,7 @@ seek o = startConcurrency commandStages $ do
{- Pass file off to git-add. -} {- Pass file off to git-add. -}
startSmall :: AddOptions -> SeekInput -> RawFilePath -> CommandStart startSmall :: AddOptions -> SeekInput -> RawFilePath -> CommandStart
startSmall o si file = startSmall o si file =
starting "add" (ActionItemWorkTreeFile file) si $ starting "add" (ActionItemTreeFile file) si $
next $ addSmall (checkGitIgnoreOption o) file next $ addSmall (checkGitIgnoreOption o) file
addSmall :: CheckGitIgnore -> RawFilePath -> Annex Bool addSmall :: CheckGitIgnore -> RawFilePath -> Annex Bool
@ -120,7 +120,7 @@ addSmall ci file = do
startSmallOverridden :: AddOptions -> SeekInput -> RawFilePath -> CommandStart startSmallOverridden :: AddOptions -> SeekInput -> RawFilePath -> CommandStart
startSmallOverridden o si file = startSmallOverridden o si file =
starting "add" (ActionItemWorkTreeFile file) si $ next $ do starting "add" (ActionItemTreeFile file) si $ next $ do
showNote "adding content to git repository" showNote "adding content to git repository"
addFile Small (checkGitIgnoreOption o) file addFile Small (checkGitIgnoreOption o) file
@ -148,7 +148,7 @@ start o si file addunlockedmatcher = do
Just s Just s
| not (isRegularFile s) && not (isSymbolicLink s) -> stop | not (isRegularFile s) && not (isSymbolicLink s) -> stop
| otherwise -> | otherwise ->
starting "add" (ActionItemWorkTreeFile file) si $ starting "add" (ActionItemTreeFile file) si $
if isSymbolicLink s if isSymbolicLink s
then next $ addFile Small (checkGitIgnoreOption o) file then next $ addFile Small (checkGitIgnoreOption o) file
else perform o file addunlockedmatcher else perform o file addunlockedmatcher
@ -157,13 +157,13 @@ start o si file addunlockedmatcher = do
Just s | isSymbolicLink s -> fixuplink key Just s | isSymbolicLink s -> fixuplink key
_ -> add _ -> add
fixuplink key = fixuplink key =
starting "add" (ActionItemWorkTreeFile file) si $ starting "add" (ActionItemTreeFile file) si $
addingExistingLink file key $ do addingExistingLink file key $ do
liftIO $ removeFile (fromRawFilePath file) liftIO $ removeFile (fromRawFilePath file)
addLink (checkGitIgnoreOption o) file key Nothing addLink (checkGitIgnoreOption o) file key Nothing
next $ cleanup key =<< inAnnex key next $ cleanup key =<< inAnnex key
fixuppointer key = fixuppointer key =
starting "add" (ActionItemWorkTreeFile file) si $ starting "add" (ActionItemTreeFile file) si $
addingExistingLink file key $ do addingExistingLink file key $ do
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file) Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file)
next $ addFile Large (checkGitIgnoreOption o) file next $ addFile Large (checkGitIgnoreOption o) file

View file

@ -270,7 +270,7 @@ startExport r db cvar allfilledvar ti = do
loc = mkExportLocation f loc = mkExportLocation f
f = getTopFilePath (Git.LsTree.file ti) f = getTopFilePath (Git.LsTree.file ti)
af = AssociatedFile (Just f) af = AssociatedFile (Just f)
ai = ActionItemOther (Just (fromRawFilePath f)) ai = ActionItemTreeFile f
si = SeekInput [] si = SeekInput []
notrecordedpresent ek = (||) notrecordedpresent ek = (||)
<$> liftIO (notElem loc <$> getExportedLocation db ek) <$> liftIO (notElem loc <$> getExportedLocation db ek)
@ -332,7 +332,7 @@ startUnexport r db f shas = do
where where
loc = mkExportLocation f' loc = mkExportLocation f'
f' = getTopFilePath f f' = getTopFilePath f
ai = ActionItemOther (Just (fromRawFilePath f')) ai = ActionItemTreeFile f'
si = SeekInput [] si = SeekInput []
startUnexport' :: Remote -> ExportHandle -> TopFilePath -> Key -> CommandStart startUnexport' :: Remote -> ExportHandle -> TopFilePath -> Key -> CommandStart
@ -342,7 +342,7 @@ startUnexport' r db f ek =
where where
loc = mkExportLocation f' loc = mkExportLocation f'
f' = getTopFilePath f f' = getTopFilePath f
ai = ActionItemOther (Just (fromRawFilePath f')) ai = ActionItemTreeFile f'
si = SeekInput [] si = SeekInput []
-- Unlike a usual drop from a repository, this does not check that -- Unlike a usual drop from a repository, this does not check that
@ -384,7 +384,7 @@ startRecoverIncomplete r db sha oldf
| otherwise = do | otherwise = do
ek <- exportKey sha ek <- exportKey sha
let loc = exportTempName ek let loc = exportTempName ek
let ai = ActionItemOther (Just (fromRawFilePath (fromExportLocation loc))) let ai = ActionItemTreeFile (fromExportLocation loc)
let si = SeekInput [] let si = SeekInput []
starting ("unexport " ++ name r) ai si $ do starting ("unexport " ++ name r) ai si $ do
liftIO $ removeExportedLocation db ek oldloc liftIO $ removeExportedLocation db ek oldloc

View file

@ -145,7 +145,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
, stop , stop
) )
where where
ai = ActionItemWorkTreeFile destfile ai = ActionItemTreeFile destfile
si = SeekInput [] si = SeekInput []
deletedup k = do deletedup k = do

View file

@ -69,7 +69,7 @@ start si (file, newkey) = ifAnnexed file go stop
| otherwise = starting "rekey" ai si $ | otherwise = starting "rekey" ai si $
perform file oldkey newkey perform file oldkey newkey
ai = ActionItemWorkTreeFile file ai = ActionItemTreeFile file
perform :: RawFilePath -> Key -> Key -> CommandPerform perform :: RawFilePath -> Key -> Key -> CommandPerform
perform file oldkey newkey = do perform file oldkey newkey = do

View file

@ -96,7 +96,7 @@ perform o remotemap key ai = do
mapM_ (showRemoteUrls remotemap) urls mapM_ (showRemoteUrls remotemap) urls
Just formatter -> liftIO $ do Just formatter -> liftIO $ do
let vs = Command.Find.formatVars key let vs = Command.Find.formatVars key
(AssociatedFile (actionItemWorkTreeFile ai)) (AssociatedFile (actionItemFile ai))
let showformatted muuid murl = putStr $ let showformatted muuid murl = putStr $
Utility.Format.format formatter $ Utility.Format.format formatter $
M.fromList $ vs ++ catMaybes M.fromList $ vs ++ catMaybes

View file

@ -83,7 +83,7 @@ showStartKey :: String -> Key -> ActionItem -> SeekInput -> Annex ()
showStartKey command key ai si = outputMessage json $ showStartKey command key ai si = outputMessage json $
encodeBS' command <> " " <> actionItemDesc ai <> " " encodeBS' command <> " " <> actionItemDesc ai <> " "
where where
json = JSON.start command (actionItemWorkTreeFile ai) (Just key) si json = JSON.start command (actionItemFile ai) (Just key) si
showStartOther :: String -> Maybe String -> SeekInput -> Annex () showStartOther :: String -> Maybe String -> SeekInput -> Annex ()
showStartOther command mdesc si = outputMessage json $ encodeBS' $ showStartOther command mdesc si = outputMessage json $ encodeBS' $
@ -97,7 +97,7 @@ showStartMessage (StartMessage command ai si) = case ai of
ActionItemKey k -> showStartKey command k ai si ActionItemKey k -> showStartKey command k ai si
ActionItemBranchFilePath _ k -> showStartKey command k ai si ActionItemBranchFilePath _ k -> showStartKey command k ai si
ActionItemFailedTransfer t _ -> showStartKey command (transferKey t) ai si ActionItemFailedTransfer t _ -> showStartKey command (transferKey t) ai si
ActionItemWorkTreeFile file -> showStart command file si ActionItemTreeFile file -> showStart command file si
ActionItemOther msg -> showStartOther command msg si ActionItemOther msg -> showStartOther command msg si
OnlyActionOn _ ai' -> showStartMessage (StartMessage command ai' si) OnlyActionOn _ ai' -> showStartMessage (StartMessage command ai' si)
showStartMessage (StartUsualMessages command ai si) = do showStartMessage (StartUsualMessages command ai si) = do

View file

@ -22,7 +22,7 @@ data ActionItem
| ActionItemKey Key | ActionItemKey Key
| ActionItemBranchFilePath BranchFilePath Key | ActionItemBranchFilePath BranchFilePath Key
| ActionItemFailedTransfer Transfer TransferInfo | ActionItemFailedTransfer Transfer TransferInfo
| ActionItemWorkTreeFile RawFilePath | ActionItemTreeFile RawFilePath
| ActionItemOther (Maybe String) | ActionItemOther (Maybe String)
-- Use to avoid more than one thread concurrently processing the -- Use to avoid more than one thread concurrently processing the
-- same Key. -- same Key.
@ -64,7 +64,7 @@ actionItemDesc (ActionItemKey k) = serializeKey' k
actionItemDesc (ActionItemBranchFilePath bfp _) = descBranchFilePath bfp actionItemDesc (ActionItemBranchFilePath bfp _) = descBranchFilePath bfp
actionItemDesc (ActionItemFailedTransfer t i) = actionItemDesc $ actionItemDesc (ActionItemFailedTransfer t i) = actionItemDesc $
ActionItemAssociatedFile (associatedFile i) (transferKey t) ActionItemAssociatedFile (associatedFile i) (transferKey t)
actionItemDesc (ActionItemWorkTreeFile f) = f actionItemDesc (ActionItemTreeFile f) = f
actionItemDesc (ActionItemOther s) = encodeBS' (fromMaybe "" s) actionItemDesc (ActionItemOther s) = encodeBS' (fromMaybe "" s)
actionItemDesc (OnlyActionOn _ ai) = actionItemDesc ai actionItemDesc (OnlyActionOn _ ai) = actionItemDesc ai
@ -73,15 +73,15 @@ actionItemKey (ActionItemAssociatedFile _ k) = Just k
actionItemKey (ActionItemKey k) = Just k actionItemKey (ActionItemKey k) = Just k
actionItemKey (ActionItemBranchFilePath _ k) = Just k actionItemKey (ActionItemBranchFilePath _ k) = Just k
actionItemKey (ActionItemFailedTransfer t _) = Just (transferKey t) actionItemKey (ActionItemFailedTransfer t _) = Just (transferKey t)
actionItemKey (ActionItemWorkTreeFile _) = Nothing actionItemKey (ActionItemTreeFile _) = Nothing
actionItemKey (ActionItemOther _) = Nothing actionItemKey (ActionItemOther _) = Nothing
actionItemKey (OnlyActionOn _ ai) = actionItemKey ai actionItemKey (OnlyActionOn _ ai) = actionItemKey ai
actionItemWorkTreeFile :: ActionItem -> Maybe RawFilePath actionItemFile :: ActionItem -> Maybe RawFilePath
actionItemWorkTreeFile (ActionItemAssociatedFile (AssociatedFile af) _) = af actionItemFile (ActionItemAssociatedFile (AssociatedFile af) _) = af
actionItemWorkTreeFile (ActionItemWorkTreeFile f) = Just f actionItemFile (ActionItemTreeFile f) = Just f
actionItemWorkTreeFile (OnlyActionOn _ ai) = actionItemWorkTreeFile ai actionItemFile (OnlyActionOn _ ai) = actionItemFile ai
actionItemWorkTreeFile _ = Nothing actionItemFile _ = Nothing
actionItemTransferDirection :: ActionItem -> Maybe Direction actionItemTransferDirection :: ActionItem -> Maybe Direction
actionItemTransferDirection (ActionItemFailedTransfer t _) = Just $ actionItemTransferDirection (ActionItemFailedTransfer t _) = Just $

View file

@ -22,3 +22,5 @@ This behavior was observed using the 4shared service, but I believe git-annex kn
Thx! Thx!
[[!tag projects/datalad]] [[!tag projects/datalad]]
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,12 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2021-03-12T18:09:48Z"
content="""
I've fixed this.
However, there is still a case where the file field is null, which is when
an already exported file is renamed. Since nothing is transferred in that
case, and 2 files are involved which doesn't fit the one file in the json,
I left it as-is.
"""]]