summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--Command/MetaData.hs4
-rw-r--r--Types/MetaData.hs10
-rw-r--r--doc/git-annex-metadata.mdwn9
4 files changed, 23 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8b16788a2..0557fe63b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/Command/MetaData.hs b/Command/MetaData.hs
index d10fc9921..f3a39dee9 100644
--- a/Command/MetaData.hs
+++ b/Command/MetaData.hs
@@ -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
diff --git a/Types/MetaData.hs b/Types/MetaData.hs
index 9e153ffb9..bc27c345f 100644
--- a/Types/MetaData.hs
+++ b/Types/MetaData.hs
@@ -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
diff --git a/doc/git-annex-metadata.mdwn b/doc/git-annex-metadata.mdwn
index fde4443dc..fa1a884b3 100644
--- a/doc/git-annex-metadata.mdwn
+++ b/doc/git-annex-metadata.mdwn
@@ -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