diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-23 00:08:29 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-23 00:08:29 -0400 |
commit | 704fa2fa789b453d354f2f375b0b42481c8990f6 (patch) | |
tree | afb28b2548c067be546b22fa6b04fa8b5d76c3fd /Types | |
parent | e0ae2f6bba897367ae23bfb1a6584ebd4843452e (diff) |
annex.genmetadata can be set to make git-annex automatically set metadata (year and month) when adding files
Diffstat (limited to 'Types')
-rw-r--r-- | Types/GitConfig.hs | 2 | ||||
-rw-r--r-- | Types/MetaData.hs | 20 |
2 files changed, 10 insertions, 12 deletions
diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index ab3dbd7b9..65984a108 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -49,6 +49,7 @@ data GitConfig = GitConfig , annexAutoUpgrade :: AutoUpgrade , annexExpireUnused :: Maybe (Maybe Duration) , annexSecureEraseCommand :: Maybe String + , annexGenMetaData :: Bool , coreSymlinks :: Bool , gcryptId :: Maybe String } @@ -81,6 +82,7 @@ extractGitConfig r = GitConfig , annexExpireUnused = maybe Nothing Just . parseDuration <$> getmaybe (annex "expireunused") , annexSecureEraseCommand = getmaybe (annex "secure-erase-command") + , annexGenMetaData = getbool (annex "genmetadata") False , coreSymlinks = getbool "core.symlinks" True , gcryptId = getmaybe "core.gcrypt-id" } diff --git a/Types/MetaData.hs b/Types/MetaData.hs index 617c122a6..b941cb59b 100644 --- a/Types/MetaData.hs +++ b/Types/MetaData.hs @@ -17,7 +17,6 @@ module Types.MetaData ( MetaSerializable, toMetaField, mkMetaField, - tagMetaField, fromMetaField, toMetaValue, mkMetaValue, @@ -25,7 +24,7 @@ module Types.MetaData ( unsetMetaData, fromMetaValue, fromMetaData, - newMetaData, + emptyMetaData, updateMetaData, unionMetaData, differenceMetaData, @@ -81,7 +80,7 @@ instance MetaSerializable MetaData where serialize (MetaData m) = unwords $ concatMap go $ M.toList m where go (f, vs) = serialize f : map serialize (S.toList vs) - deserialize = Just . getfield newMetaData . words + deserialize = Just . getfield emptyMetaData . words where getfield m [] = m getfield m (w:ws) = maybe m (getvalues m ws) (deserialize w) @@ -152,8 +151,8 @@ fromMetaValue (MetaValue _ f) = f fromMetaData :: MetaData -> [(MetaField, S.Set MetaValue)] fromMetaData (MetaData m) = M.toList m -newMetaData :: MetaData -newMetaData = MetaData M.empty +emptyMetaData :: MetaData +emptyMetaData = MetaData M.empty {- Can be used to set a value, or to unset it, depending on whether - the MetaValue has CurrentlySet or not. -} @@ -202,10 +201,10 @@ data ModMeta - Note that the new MetaData does not include all the - values set in the input metadata. It only contains changed values. -} modMeta :: MetaData -> ModMeta -> MetaData -modMeta _ (AddMeta f v) = updateMetaData f v newMetaData -modMeta _ (DelMeta f oldv) = updateMetaData f (unsetMetaValue oldv) newMetaData +modMeta _ (AddMeta f v) = updateMetaData f v emptyMetaData +modMeta _ (DelMeta f oldv) = updateMetaData f (unsetMetaValue oldv) emptyMetaData modMeta m (SetMeta f v) = updateMetaData f v $ - foldr (updateMetaData f) newMetaData $ + foldr (updateMetaData f) emptyMetaData $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m {- Parses field=value, field+=value, field-=value -} @@ -233,9 +232,6 @@ mkMetaField f = maybe (Left $ badField f) Right (toMetaField f) badField :: String -> String badField f = "Illegal metadata field name, \"" ++ f ++ "\"" -tagMetaField :: MetaField -tagMetaField = MetaField "tag" - {- Avoid putting too many fields in the map; extremely large maps make - the seriaization test slow due to the sheer amount of data. - It's unlikely that more than 100 fields of metadata will be used. -} @@ -254,7 +250,7 @@ prop_metadata_sane :: MetaData -> MetaField -> MetaValue -> Bool prop_metadata_sane m f v = and [ S.member v $ metaDataValues f m' , not (isSet v) || S.member v (currentMetaDataValues f m') - , differenceMetaData m' newMetaData == m' + , differenceMetaData m' emptyMetaData == m' ] where m' = updateMetaData f v m |