diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs index cc00baca5b..d8d8177c46 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 1209a58360..e2afccb9b6 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 976f37e464..198fe5d7d5 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 880a5ba09c..721c5b3aa3 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 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 39bb7f2fd7..448784b50a 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` - - Remove a value. - -* `-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` + +* `-s field-=value` / `--set field-=value` + + 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.