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:
parent
b4d13c75a1
commit
812d90022b
4 changed files with 23 additions and 1 deletions
|
@ -2,6 +2,7 @@ git-annex (6.20170926) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* webdav: Improve error message for failed request to include the request
|
* webdav: Improve error message for failed request to include the request
|
||||||
method and path.
|
method and path.
|
||||||
|
* metadata: Added --remove-all.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Thu, 28 Sep 2017 12:01:39 -0400
|
-- Joey Hess <id@joeyh.name> Thu, 28 Sep 2017 12:01:39 -0400
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,10 @@ optParser desc = MetaDataOptions
|
||||||
( long "remove" <> short 'r' <> metavar "FIELD"
|
( long "remove" <> short 'r' <> metavar "FIELD"
|
||||||
<> help "remove all values of a field"
|
<> help "remove all values of a field"
|
||||||
)
|
)
|
||||||
|
<|> flag' DelAllMeta
|
||||||
|
( long "remove-all"
|
||||||
|
<> help "remove all metadata"
|
||||||
|
)
|
||||||
|
|
||||||
seek :: MetaDataOptions -> CommandSeek
|
seek :: MetaDataOptions -> CommandSeek
|
||||||
seek o = case batchOption o of
|
seek o = case batchOption o of
|
||||||
|
|
|
@ -244,12 +244,17 @@ removeEmptyFields (MetaData m) = MetaData $ M.filter (not . S.null) m
|
||||||
metaDataValues :: MetaField -> MetaData -> S.Set MetaValue
|
metaDataValues :: MetaField -> MetaData -> S.Set MetaValue
|
||||||
metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m)
|
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 -}
|
{- Ways that existing metadata can be modified -}
|
||||||
data ModMeta
|
data ModMeta
|
||||||
= AddMeta MetaField MetaValue
|
= AddMeta MetaField MetaValue
|
||||||
| DelMeta MetaField (Maybe MetaValue)
|
| DelMeta MetaField (Maybe MetaValue)
|
||||||
-- ^ delete value of a field. With Just, only that specific value
|
-- ^ 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)
|
| SetMeta MetaField (S.Set MetaValue)
|
||||||
-- ^ removes any existing values
|
-- ^ removes any existing values
|
||||||
| MaybeSetMeta MetaField MetaValue
|
| MaybeSetMeta MetaField MetaValue
|
||||||
|
@ -265,6 +270,9 @@ modMeta _ (DelMeta f (Just oldv)) =
|
||||||
updateMetaData f (unsetMetaValue oldv) emptyMetaData
|
updateMetaData f (unsetMetaValue oldv) emptyMetaData
|
||||||
modMeta m (DelMeta f Nothing) = MetaData $ M.singleton f $
|
modMeta m (DelMeta f Nothing) = MetaData $ M.singleton f $
|
||||||
S.fromList $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m
|
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 $
|
modMeta m (SetMeta f s) = updateMetaData' f s $
|
||||||
foldr (updateMetaData f) emptyMetaData $
|
foldr (updateMetaData f) emptyMetaData $
|
||||||
map unsetMetaValue $ S.toList $ currentMetaDataValues f m
|
map unsetMetaValue $ S.toList $ currentMetaDataValues f m
|
||||||
|
|
|
@ -60,6 +60,15 @@ automatically.
|
||||||
|
|
||||||
Unset a tag.
|
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`
|
* `--force`
|
||||||
|
|
||||||
By default, `git annex metadata` refuses to recursively set metadata
|
By default, `git annex metadata` refuses to recursively set metadata
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue