summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-03-19 19:10:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-03-19 19:10:55 -0400
commit000155ea54690088b95b10fefa67711c5ab2a7ba (patch)
tree56e06297e36e1198fe2fce4ffe9c7c024fd2bed8
parent6ed3cabd704f61ffa3e99d4222c8cf71a27526f1 (diff)
toplevel lastchanged field
-rw-r--r--Annex/MetaData/StandardFields.hs17
-rw-r--r--Logs/MetaData.hs14
-rw-r--r--debian/changelog7
-rw-r--r--doc/metadata.mdwn2
4 files changed, 29 insertions, 11 deletions
diff --git a/Annex/MetaData/StandardFields.hs b/Annex/MetaData/StandardFields.hs
index 00b810593..d41fb1506 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 e1d2044cc..b682ca005 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 f082cbbfb..7034eaaed 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 <joeyh@debian.org> Thu, 06 Mar 2014 16:17:01 -0400
diff --git a/doc/metadata.mdwn b/doc/metadata.mdwn
index b2d020348..9f3c314fa 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