diff options
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/CatFile.hs | 3 | ||||
-rw-r--r-- | Annex/MetaData.hs | 30 |
2 files changed, 21 insertions, 12 deletions
diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 54a4d1099..87d179a62 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -87,8 +87,7 @@ catKey' modeguaranteed ref mode | modeguaranteed = catObject ref | otherwise = L.take 8192 <$> catObject ref -{- Looks up the file mode corresponding to the Ref using the running - - cat-file. +{- Looks up the key corresponding to the Ref using the running cat-file. - - Currently this always has to look in HEAD, because cat-file --batch - does not offer a way to specify that we want to look up a tree object diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs index ef235b51f..b7850a868 100644 --- a/Annex/MetaData.hs +++ b/Annex/MetaData.hs @@ -11,6 +11,7 @@ import Common.Annex import qualified Annex import Types.MetaData import Logs.MetaData +import Annex.CatFile import qualified Data.Set as S import qualified Data.Map as M @@ -27,18 +28,27 @@ yearMetaField = MetaField "year" monthMetaField :: MetaField monthMetaField = MetaField "month" -{- Generates metadata for a file that has just been ingested into the - - annex. Passed the FileStatus of the content file. +{- Adds metadata for a file that has just been ingested into the + - annex, but has not yet been committed to git. - - - Does not overwrite any existing metadata values for the key. + - When the file has been modified, the metadata is copied over + - from the old key to the new key. Note that it looks at the old key as + - committed to HEAD -- the new key may or may not have already been staged + - in th annex. + - + - Also, can generate new metadata, if configured to do so. -} -genMetaData :: Key -> FileStatus -> Annex () -genMetaData key status = whenM (annexGenMetaData <$> Annex.getGitConfig) $ do - metadata <- getCurrentMetaData key - let metadata' = genMetaData' status metadata - unless (metadata' == emptyMetaData) $ - addMetaData key metadata' - +genMetaData :: Key -> FilePath -> FileStatus -> Annex () +genMetaData key file status = do + maybe noop (flip copyMetaData key) =<< catKeyFileHEAD file + whenM (annexGenMetaData <$> Annex.getGitConfig) $ do + metadata <- getCurrentMetaData key + let metadata' = genMetaData' status metadata + unless (metadata' == emptyMetaData) $ + addMetaData key metadata' + +{- Generates metadata from the FileStatus. + - Does not overwrite any existing metadata values. -} genMetaData' :: FileStatus -> MetaData -> MetaData genMetaData' status old = MetaData $ M.fromList $ filter isnew [ (yearMetaField, S.singleton $ toMetaValue $ show y) |