metadata: Added --remove-all.

Motivation is to remove all metadata when it gets copied from a previous
version of the file, and that is not deisrable.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2017-09-28 12:36:10 -04:00
parent b4d13c75a1
commit 812d90022b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 23 additions and 1 deletions

View file

@ -2,6 +2,7 @@ git-annex (6.20170926) UNRELEASED; urgency=medium
* webdav: Improve error message for failed request to include the request
method and path.
* metadata: Added --remove-all.
-- Joey Hess <id@joeyh.name> Thu, 28 Sep 2017 12:01:39 -0400

View file

@ -64,6 +64,10 @@ optParser desc = MetaDataOptions
( long "remove" <> short 'r' <> metavar "FIELD"
<> help "remove all values of a field"
)
<|> flag' DelAllMeta
( long "remove-all"
<> help "remove all metadata"
)
seek :: MetaDataOptions -> CommandSeek
seek o = case batchOption o of

View file

@ -244,12 +244,17 @@ removeEmptyFields (MetaData m) = MetaData $ M.filter (not . S.null) m
metaDataValues :: MetaField -> MetaData -> S.Set MetaValue
metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m)
mapMetaData :: (S.Set MetaValue -> S.Set MetaValue) -> MetaData -> MetaData
mapMetaData f (MetaData m) = MetaData (M.map f m)
{- Ways that existing metadata can be modified -}
data ModMeta
= AddMeta MetaField MetaValue
| DelMeta MetaField (Maybe MetaValue)
-- ^ delete value of a field. With Just, only that specific value
-- is deleted; with Nothing, all current values are deleted.
-- is deleted; with Nothing, all current values are deleted.a
| DelAllMeta
-- ^ delete all currently set metadata
| SetMeta MetaField (S.Set MetaValue)
-- ^ removes any existing values
| MaybeSetMeta MetaField MetaValue
@ -265,6 +270,9 @@ modMeta _ (DelMeta f (Just oldv)) =
updateMetaData f (unsetMetaValue oldv) emptyMetaData
modMeta m (DelMeta f Nothing) = MetaData $ M.singleton f $
S.fromList $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m
modMeta m DelAllMeta = mapMetaData
(S.fromList . map unsetMetaValue . S.toList)
(currentMetaData m)
modMeta m (SetMeta f s) = updateMetaData' f s $
foldr (updateMetaData f) emptyMetaData $
map unsetMetaValue $ S.toList $ currentMetaDataValues f m

View file

@ -60,6 +60,15 @@ automatically.
Unset a tag.
* `--remove-all`
Remove all metadata from the specified files.
When a file is modified and the new version added, git-annex will copy
over the metadata from the old version of the file. In situations where
you don't want that copied metadata, you can use this option to remove
it.
* `--force`
By default, `git annex metadata` refuses to recursively set metadata