aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-02-29 13:00:46 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-02-29 13:00:46 -0400
commit25b87aadd8bdca484f1fb073c38e169ee2bc7503 (patch)
treea34a85fd37f979ac64f617bef01a1957a0a2b622
parent5b23c5d3baa15ca1200b2ee349b924c1d8395665 (diff)
metadata: Added -r to remove all current values of a field.
-rw-r--r--Annex/MetaData.hs2
-rw-r--r--Command/MetaData.hs6
-rw-r--r--Types/MetaData.hs15
-rw-r--r--debian/changelog6
-rw-r--r--doc/git-annex-metadata.mdwn25
5 files changed, 38 insertions, 16 deletions
diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs
index cc00baca5..d8d8177c4 100644
--- a/Annex/MetaData.hs
+++ b/Annex/MetaData.hs
@@ -61,7 +61,7 @@ dateMetaData mtime old = MetaData $ M.fromList $ filter isnew
parseModMeta :: String -> Either String ModMeta
parseModMeta p = case lastMaybe f of
Just '+' -> AddMeta <$> mkMetaField f' <*> v
- Just '-' -> DelMeta <$> mkMetaField f' <*> v
+ Just '-' -> DelMeta <$> mkMetaField f' <*> (Just <$> v)
Just '?' -> MaybeSetMeta <$> mkMetaField f' <*> v
_ -> SetMeta <$> mkMetaField f <*> v
where
diff --git a/Command/MetaData.hs b/Command/MetaData.hs
index 1209a5836..e2afccb9b 100644
--- a/Command/MetaData.hs
+++ b/Command/MetaData.hs
@@ -46,10 +46,14 @@ optParser desc = MetaDataOptions
( long "tag" <> short 't' <> metavar "TAG"
<> help "set a tag"
))
- <|> (DelMeta tagMetaField . toMetaValue <$> strOption
+ <|> (DelMeta tagMetaField . Just . toMetaValue <$> strOption
( long "untag" <> short 'u' <> metavar "TAG"
<> help "remove a tag"
))
+ <|> option (eitherReader (\f -> DelMeta <$> mkMetaField f <*> pure Nothing))
+ ( long "remove" <> short 'r' <> metavar "FIELD"
+ <> help "remove all values of a field"
+ )
seek :: MetaDataOptions -> CommandSeek
seek o = do
diff --git a/Types/MetaData.hs b/Types/MetaData.hs
index 976f37e46..198fe5d7d 100644
--- a/Types/MetaData.hs
+++ b/Types/MetaData.hs
@@ -219,9 +219,13 @@ metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m)
{- Ways that existing metadata can be modified -}
data ModMeta
= AddMeta MetaField MetaValue
- | DelMeta MetaField MetaValue
- | SetMeta MetaField MetaValue -- removes any existing values
- | MaybeSetMeta MetaField MetaValue -- when field has no existing value
+ | DelMeta MetaField (Maybe MetaValue)
+ -- ^ delete value of a field. With Just, only that specific value
+ -- is deleted; with Nothing, all current values are deleted.
+ | SetMeta MetaField MetaValue
+ -- ^ removes any existing values
+ | MaybeSetMeta MetaField MetaValue
+ -- ^ set when field has no existing value
deriving (Show)
{- Applies a ModMeta, generating the new MetaData.
@@ -229,7 +233,10 @@ data ModMeta
- values set in the input metadata. It only contains changed values. -}
modMeta :: MetaData -> ModMeta -> MetaData
modMeta _ (AddMeta f v) = updateMetaData f v emptyMetaData
-modMeta _ (DelMeta f oldv) = updateMetaData f (unsetMetaValue oldv) emptyMetaData
+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 (SetMeta f v) = updateMetaData f v $
foldr (updateMetaData f) emptyMetaData $
map unsetMetaValue $ S.toList $ currentMetaDataValues f m
diff --git a/debian/changelog b/debian/changelog
index 880a5ba09..721c5b3aa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+git-annex (6.20160230) UNRELEASED; urgency=medium
+
+ * metadata: Added -r to remove all current values of a field.
+
+ -- Joey Hess <id@joeyh.name> Mon, 29 Feb 2016 13:00:30 -0400
+
git-annex (6.20160229) unstable; urgency=medium
* Update perlmagick build dependency. Closes: #789225
diff --git a/doc/git-annex-metadata.mdwn b/doc/git-annex-metadata.mdwn
index 39bb7f2fd..448784b50 100644
--- a/doc/git-annex-metadata.mdwn
+++ b/doc/git-annex-metadata.mdwn
@@ -19,34 +19,39 @@ When run without any -s or -t parameters, displays the current metadata.
# OPTIONS
-* `-g field`
+* `-g field` / `--get field`
Get the value(s) of a single field.
The values will be output one per line, with no other output, so
this is suitable for use in a script.
-* `-s field=value`
+* `-s field=value` / `--set field=value`
Set a field's value, removing any old values.
-* `-s field+=value`
+* `-s field+=value` / `--set field+=value`
Add an additional value, preserving any old values.
-* `-s field-=value`
+* `-s field?=value` / `--set field?=value`
- Remove a value.
+ Set a value, but only if the field does not already have a value set.
-* `-s field?=value`
+* `-s field-=value` / `--set field-=value`
- Set a value, but only if the field does not already have a value set.
-
-* `-t tag`
+ Remove a value from a field, leaving any other values that the field has
+ set.
+
+* `-r field` / `--remove field`
+
+ Remove all current values of the field.
+
+* `-t tag` / `--tag tag`
Set a tag. Note that a tag is just a value of the "tag" field.
-* `-u tag`
+* `-u tag` / `--unset tag`
Unset a tag.