From 6481991208f4fb3dbc2b60899c3bf2e37c76c9f3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Mar 2021 14:09:19 -0400 Subject: [PATCH] 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. --- CHANGELOG | 1 + Command/Add.hs | 10 +++++----- Command/Export.hs | 8 ++++---- Command/Import.hs | 2 +- Command/ReKey.hs | 2 +- Command/Whereis.hs | 2 +- Messages.hs | 4 ++-- Types/ActionItem.hs | 16 ++++++++-------- ...xport__96___have_file__58__null_property.mdwn | 2 ++ ...t_1_bf743f047b8063b8ecbd8c87d12fa475._comment | 12 ++++++++++++ 10 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property/comment_1_bf743f047b8063b8ecbd8c87d12fa475._comment diff --git a/CHANGELOG b/CHANGELOG index 77d0938944..a7524723d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ git-annex (8.20210311) UNRELEASED; urgency=medium * export: When a submodule is in the tree to be exported, skip it. * import: When the previously exported tree contained a submodule, preserve it in the imported tree so it does not get deleted. + * export --json: Fill in the file field. -- Joey Hess Fri, 12 Mar 2021 12:06:37 -0400 diff --git a/Command/Add.hs b/Command/Add.hs index 7ded87490c..246a2242f7 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -110,7 +110,7 @@ seek o = startConcurrency commandStages $ do {- Pass file off to git-add. -} startSmall :: AddOptions -> SeekInput -> RawFilePath -> CommandStart startSmall o si file = - starting "add" (ActionItemWorkTreeFile file) si $ + starting "add" (ActionItemTreeFile file) si $ next $ addSmall (checkGitIgnoreOption o) file addSmall :: CheckGitIgnore -> RawFilePath -> Annex Bool @@ -120,7 +120,7 @@ addSmall ci file = do startSmallOverridden :: AddOptions -> SeekInput -> RawFilePath -> CommandStart startSmallOverridden o si file = - starting "add" (ActionItemWorkTreeFile file) si $ next $ do + starting "add" (ActionItemTreeFile file) si $ next $ do showNote "adding content to git repository" addFile Small (checkGitIgnoreOption o) file @@ -148,7 +148,7 @@ start o si file addunlockedmatcher = do Just s | not (isRegularFile s) && not (isSymbolicLink s) -> stop | otherwise -> - starting "add" (ActionItemWorkTreeFile file) si $ + starting "add" (ActionItemTreeFile file) si $ if isSymbolicLink s then next $ addFile Small (checkGitIgnoreOption o) file else perform o file addunlockedmatcher @@ -157,13 +157,13 @@ start o si file addunlockedmatcher = do Just s | isSymbolicLink s -> fixuplink key _ -> add fixuplink key = - starting "add" (ActionItemWorkTreeFile file) si $ + starting "add" (ActionItemTreeFile file) si $ addingExistingLink file key $ do liftIO $ removeFile (fromRawFilePath file) addLink (checkGitIgnoreOption o) file key Nothing next $ cleanup key =<< inAnnex key fixuppointer key = - starting "add" (ActionItemWorkTreeFile file) si $ + starting "add" (ActionItemTreeFile file) si $ addingExistingLink file key $ do Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file) next $ addFile Large (checkGitIgnoreOption o) file diff --git a/Command/Export.hs b/Command/Export.hs index dd0cb5d91f..6187d8dc51 100644 --- a/Command/Export.hs +++ b/Command/Export.hs @@ -270,7 +270,7 @@ startExport r db cvar allfilledvar ti = do loc = mkExportLocation f f = getTopFilePath (Git.LsTree.file ti) af = AssociatedFile (Just f) - ai = ActionItemOther (Just (fromRawFilePath f)) + ai = ActionItemTreeFile f si = SeekInput [] notrecordedpresent ek = (||) <$> liftIO (notElem loc <$> getExportedLocation db ek) @@ -332,7 +332,7 @@ startUnexport r db f shas = do where loc = mkExportLocation f' f' = getTopFilePath f - ai = ActionItemOther (Just (fromRawFilePath f')) + ai = ActionItemTreeFile f' si = SeekInput [] startUnexport' :: Remote -> ExportHandle -> TopFilePath -> Key -> CommandStart @@ -342,7 +342,7 @@ startUnexport' r db f ek = where loc = mkExportLocation f' f' = getTopFilePath f - ai = ActionItemOther (Just (fromRawFilePath f')) + ai = ActionItemTreeFile f' si = SeekInput [] -- Unlike a usual drop from a repository, this does not check that @@ -384,7 +384,7 @@ startRecoverIncomplete r db sha oldf | otherwise = do ek <- exportKey sha let loc = exportTempName ek - let ai = ActionItemOther (Just (fromRawFilePath (fromExportLocation loc))) + let ai = ActionItemTreeFile (fromExportLocation loc) let si = SeekInput [] starting ("unexport " ++ name r) ai si $ do liftIO $ removeExportedLocation db ek oldloc diff --git a/Command/Import.hs b/Command/Import.hs index d10310a9bf..d133d0f306 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -145,7 +145,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) = , stop ) where - ai = ActionItemWorkTreeFile destfile + ai = ActionItemTreeFile destfile si = SeekInput [] deletedup k = do diff --git a/Command/ReKey.hs b/Command/ReKey.hs index ec94d98856..368fb42ef2 100644 --- a/Command/ReKey.hs +++ b/Command/ReKey.hs @@ -69,7 +69,7 @@ start si (file, newkey) = ifAnnexed file go stop | otherwise = starting "rekey" ai si $ perform file oldkey newkey - ai = ActionItemWorkTreeFile file + ai = ActionItemTreeFile file perform :: RawFilePath -> Key -> Key -> CommandPerform perform file oldkey newkey = do diff --git a/Command/Whereis.hs b/Command/Whereis.hs index e8d103bdb8..c329dde73d 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -96,7 +96,7 @@ perform o remotemap key ai = do mapM_ (showRemoteUrls remotemap) urls Just formatter -> liftIO $ do let vs = Command.Find.formatVars key - (AssociatedFile (actionItemWorkTreeFile ai)) + (AssociatedFile (actionItemFile ai)) let showformatted muuid murl = putStr $ Utility.Format.format formatter $ M.fromList $ vs ++ catMaybes diff --git a/Messages.hs b/Messages.hs index 7ad270bf99..ce6e7a2334 100644 --- a/Messages.hs +++ b/Messages.hs @@ -83,7 +83,7 @@ showStartKey :: String -> Key -> ActionItem -> SeekInput -> Annex () showStartKey command key ai si = outputMessage json $ encodeBS' command <> " " <> actionItemDesc ai <> " " 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 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 ActionItemBranchFilePath _ k -> showStartKey command k 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 OnlyActionOn _ ai' -> showStartMessage (StartMessage command ai' si) showStartMessage (StartUsualMessages command ai si) = do diff --git a/Types/ActionItem.hs b/Types/ActionItem.hs index fcb8c64345..b5d52f5401 100644 --- a/Types/ActionItem.hs +++ b/Types/ActionItem.hs @@ -22,7 +22,7 @@ data ActionItem | ActionItemKey Key | ActionItemBranchFilePath BranchFilePath Key | ActionItemFailedTransfer Transfer TransferInfo - | ActionItemWorkTreeFile RawFilePath + | ActionItemTreeFile RawFilePath | ActionItemOther (Maybe String) -- Use to avoid more than one thread concurrently processing the -- same Key. @@ -64,7 +64,7 @@ actionItemDesc (ActionItemKey k) = serializeKey' k actionItemDesc (ActionItemBranchFilePath bfp _) = descBranchFilePath bfp actionItemDesc (ActionItemFailedTransfer t i) = actionItemDesc $ ActionItemAssociatedFile (associatedFile i) (transferKey t) -actionItemDesc (ActionItemWorkTreeFile f) = f +actionItemDesc (ActionItemTreeFile f) = f actionItemDesc (ActionItemOther s) = encodeBS' (fromMaybe "" s) actionItemDesc (OnlyActionOn _ ai) = actionItemDesc ai @@ -73,15 +73,15 @@ actionItemKey (ActionItemAssociatedFile _ k) = Just k actionItemKey (ActionItemKey k) = Just k actionItemKey (ActionItemBranchFilePath _ k) = Just k actionItemKey (ActionItemFailedTransfer t _) = Just (transferKey t) -actionItemKey (ActionItemWorkTreeFile _) = Nothing +actionItemKey (ActionItemTreeFile _) = Nothing actionItemKey (ActionItemOther _) = Nothing actionItemKey (OnlyActionOn _ ai) = actionItemKey ai -actionItemWorkTreeFile :: ActionItem -> Maybe RawFilePath -actionItemWorkTreeFile (ActionItemAssociatedFile (AssociatedFile af) _) = af -actionItemWorkTreeFile (ActionItemWorkTreeFile f) = Just f -actionItemWorkTreeFile (OnlyActionOn _ ai) = actionItemWorkTreeFile ai -actionItemWorkTreeFile _ = Nothing +actionItemFile :: ActionItem -> Maybe RawFilePath +actionItemFile (ActionItemAssociatedFile (AssociatedFile af) _) = af +actionItemFile (ActionItemTreeFile f) = Just f +actionItemFile (OnlyActionOn _ ai) = actionItemFile ai +actionItemFile _ = Nothing actionItemTransferDirection :: ActionItem -> Maybe Direction actionItemTransferDirection (ActionItemFailedTransfer t _) = Just $ diff --git a/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property.mdwn b/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property.mdwn index 612e037f88..a80653d04b 100644 --- a/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property.mdwn +++ b/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property.mdwn @@ -22,3 +22,5 @@ This behavior was observed using the 4shared service, but I believe git-annex kn Thx! [[!tag projects/datalad]] + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property/comment_1_bf743f047b8063b8ecbd8c87d12fa475._comment b/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property/comment_1_bf743f047b8063b8ecbd8c87d12fa475._comment new file mode 100644 index 0000000000..29681baafe --- /dev/null +++ b/doc/bugs/JSON_results_for___96__export__96___have_file__58__null_property/comment_1_bf743f047b8063b8ecbd8c87d12fa475._comment @@ -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. +"""]]