toplevel lastchanged field

This commit is contained in:
Joey Hess 2014-03-19 19:10:35 -04:00
parent 3d48de183d
commit f64c2d6138
4 changed files with 29 additions and 11 deletions

View file

@ -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"

View file

@ -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

7
debian/changelog vendored
View file

@ -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

View file

@ -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