diff --git a/Annex/MetaData/StandardFields.hs b/Annex/MetaData/StandardFields.hs index 00b810593f..d41fb1506f 100644 --- a/Annex/MetaData/StandardFields.hs +++ b/Annex/MetaData/StandardFields.hs @@ -10,6 +10,7 @@ module Annex.MetaData.StandardFields ( yearMetaField, monthMetaField, lastChangedField, + mkLastChangedField, isLastChangedField ) where @@ -26,13 +27,21 @@ yearMetaField = mkMetaFieldUnchecked "year" monthMetaField :: MetaField monthMetaField = mkMetaFieldUnchecked "month" -lastChangedField :: MetaField -> MetaField -lastChangedField f = mkMetaFieldUnchecked (fromMetaField f ++ lastchanged) +lastChangedField :: MetaField +lastChangedField = mkMetaFieldUnchecked lastchanged + +mkLastChangedField :: MetaField -> MetaField +mkLastChangedField f = mkMetaFieldUnchecked (fromMetaField f ++ lastchangedSuffix) isLastChangedField :: MetaField -> Bool -isLastChangedField f = lastchanged `isSuffixOf` s && s /= lastchanged +isLastChangedField f + | f == lastChangedField = True + | otherwise = lastchanged `isSuffixOf` s && s /= lastchangedSuffix where s = fromMetaField f lastchanged :: String -lastchanged = "-lastchanged" +lastchanged = "lastchanged" + +lastchangedSuffix :: String +lastchangedSuffix = "-lastchanged" diff --git a/Logs/MetaData.hs b/Logs/MetaData.hs index e1d2044cca..b682ca005e 100644 --- a/Logs/MetaData.hs +++ b/Logs/MetaData.hs @@ -67,16 +67,22 @@ getCurrentMetaData k = do return $ currentMetaData $ unionMetaData loggedmeta (lastchanged ls loggedmeta) where - lastchanged ls (MetaData wanted) = + lastchanged [] _ = emptyMetaData + lastchanged ls (MetaData currentlyset) = let m = foldl' (flip M.union) M.empty (map genlastchanged ls) - in MetaData $ M.mapKeys lastChangedField $ + in MetaData $ + -- Add a overall lastchanged using the oldest log + -- item (log is in ascending order). + M.insert lastChangedField (lastchangedval $ Prelude.last ls) $ + M.mapKeys mkLastChangedField $ -- Only include fields that are currently set. - m `M.intersection` wanted + m `M.intersection` currentlyset -- Makes each field have the timestamp as its value. genlastchanged l = let MetaData m = value l - ts = S.singleton $ toMetaValue $ showts $ changed l + ts = lastchangedval l in M.map (const ts) m + lastchangedval l = S.singleton $ toMetaValue $ showts $ changed l showts = formatTime defaultTimeLocale "%F@%H-%M-%S" . posixSecondsToUTCTime {- Adds in some metadata, which can override existing values, or unset diff --git a/debian/changelog b/debian/changelog index f082cbbfbb..7034eaaed3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -27,9 +27,10 @@ git-annex (5.20140307) UNRELEASED; urgency=medium * map: Fix crash when one of the remotes of a repo is a local directory that does not exist, or is not a git repo. * rsync special remote: Fix slashes when used on Windows. - * Each for each metadata field, there's now an automatically maintained - "$field-lastchanged" that gives the timestamp of the last change to that - field. + * For each metadata field, there's now an automatically maintained + "$field-lastchanged" that gives the date of the last change to that + field. Also the "lastchanged" field for the date of the last change + to any of a file's metadata. * Windows: Fix some filename encoding bugs. -- Joey Hess Thu, 06 Mar 2014 16:17:01 -0400 diff --git a/doc/metadata.mdwn b/doc/metadata.mdwn index b2d020348d..9f3c314fa2 100644 --- a/doc/metadata.mdwn +++ b/doc/metadata.mdwn @@ -31,6 +31,8 @@ Here are some metadata fields that git-annex has special support for: * `$field-lastchanged` - This is automatically maintained for each field that's set, and gives the date and time of the most recent change to the field. It cannot be modified directly. +* `lastchanged` - This is automatically maintained, giving the data and time + of the last change to any of the metadata of a file. To make git-annex automatically set the year and month when adding files, run `git config annex.genmetadata true`. Also, see