aboutsummaryrefslogtreecommitdiff
path: root/Logs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-09-28 12:56:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-09-28 12:56:35 -0400
commitbf4c5f82de894139789136457c04dd048956c617 (patch)
tree6fee6710a07cd51d28bef8d57da2195422810230 /Logs
parent5b3ff3fb3c8c4191e0d0a7653014d0b5fd9a0120 (diff)
Warn when metadata is inherited from a previous version of a file
to avoid the user being surprised in cases where that behavior is not desired or expected This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Logs')
-rw-r--r--Logs/MetaData.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/Logs/MetaData.hs b/Logs/MetaData.hs
index 92e396541..0393702bc 100644
--- a/Logs/MetaData.hs
+++ b/Logs/MetaData.hs
@@ -55,6 +55,9 @@ getMetaDataLog key = do
config <- Annex.getGitConfig
readLog $ metaDataLogFile config key
+logToCurrentMetaData :: [LogEntry MetaData] -> MetaData
+logToCurrentMetaData = currentMetaData . combineMetaData . map value
+
{- Go through the log from oldest to newest, and combine it all
- into a single MetaData representing the current state.
-
@@ -64,7 +67,7 @@ getMetaDataLog key = do
getCurrentMetaData :: Key -> Annex MetaData
getCurrentMetaData k = do
ls <- S.toAscList <$> getMetaDataLog k
- let loggedmeta = currentMetaData $ combineMetaData $ map value ls
+ let loggedmeta = logToCurrentMetaData ls
return $ currentMetaData $ unionMetaData loggedmeta
(lastchanged ls loggedmeta)
where
@@ -177,13 +180,18 @@ simplifyLog s = case sl of
- repository.
-
- Any metadata already attached to the new key is not preserved.
+ -
+ - Returns True when metadata was copied.
-}
-copyMetaData :: Key -> Key -> Annex ()
+copyMetaData :: Key -> Key -> Annex Bool
copyMetaData oldkey newkey
- | oldkey == newkey = noop
+ | oldkey == newkey = return False
| otherwise = do
l <- getMetaDataLog oldkey
- unless (S.null l) $ do
- config <- Annex.getGitConfig
- Annex.Branch.change (metaDataLogFile config newkey) $
- const $ showLog l
+ if logToCurrentMetaData (S.toAscList l) == emptyMetaData
+ then return False
+ else do
+ config <- Annex.getGitConfig
+ Annex.Branch.change (metaDataLogFile config newkey) $
+ const $ showLog l
+ return True