pre-commit: Update metadata when committing changes to annexed files within a view.

So the user can now switch to a view and then move files around within it
to manage metadata. For example, moving a file into a new directory
when in the tags=* view adds a tag to it.

Implementation is fairly efficient. One diff-index, which is no more
expensive than the first stage of a git commit, followed by possibly
some cat-file --batch traffic to find the key (when deleting a file).
Very similar to what's done in direct mode when committing. And like
direct mode when updating the WC after a merge, it has to buffer the
diff-tree values in order to make 2 passes over them.

When not in a view, pre-commit now does one extra git symbolic-ref,
which is tiny overhead.

This commit was sponsored by Andrew Eskridge.
This commit is contained in:
Joey Hess 2014-02-19 14:14:44 -04:00
parent 02259d2a55
commit 39ebfa1a2e
6 changed files with 103 additions and 23 deletions

View file

@ -22,12 +22,14 @@ module Types.MetaData (
toMetaValue,
mkMetaValue,
unsetMetaValue,
unsetMetaData,
fromMetaValue,
fromMetaData,
newMetaData,
updateMetaData,
unionMetaData,
differenceMetaData,
isSet,
currentMetaData,
currentMetaDataValues,
metaDataValues,
@ -137,6 +139,10 @@ mkMetaValue = MetaValue
unsetMetaValue :: MetaValue -> MetaValue
unsetMetaValue (MetaValue _ s) = MetaValue (CurrentlySet False) s
{- Marks all MetaValues as no longer currently set. -}
unsetMetaData :: MetaData -> MetaData
unsetMetaData (MetaData m) = MetaData $ M.map (S.map unsetMetaValue) m
fromMetaField :: MetaField -> String
fromMetaField (MetaField f) = f