nice git ack space optimisation when setting the same metadata value for multiple files
This commit is contained in:
parent
0e9a72b356
commit
a18eae9a0f
2 changed files with 22 additions and 14 deletions
|
@ -14,6 +14,7 @@ import Logs.MetaData
|
||||||
import Types.MetaData
|
import Types.MetaData
|
||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
import Data.Time.Clock.POSIX
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions [setOption] $ command "metadata" paramPaths seek
|
def = [withOptions [setOption] $ command "metadata" paramPaths seek
|
||||||
|
@ -30,19 +31,20 @@ setOption = Option ['s'] ["set"] (ReqArg mkmod "field[+-]=value") "set metadata"
|
||||||
seek :: CommandSeek
|
seek :: CommandSeek
|
||||||
seek ps = do
|
seek ps = do
|
||||||
modmeta <- Annex.getState Annex.modmeta
|
modmeta <- Annex.getState Annex.modmeta
|
||||||
withFilesInGit (whenAnnexed $ start modmeta) ps
|
now <- liftIO getPOSIXTime
|
||||||
|
withFilesInGit (whenAnnexed $ start now modmeta) ps
|
||||||
|
|
||||||
start :: [ModMeta] -> FilePath -> (Key, Backend) -> CommandStart
|
start :: POSIXTime -> [ModMeta] -> FilePath -> (Key, Backend) -> CommandStart
|
||||||
start ms file (k, _) = do
|
start now ms file (k, _) = do
|
||||||
showStart "metadata" file
|
showStart "metadata" file
|
||||||
next $ perform k ms
|
next $ perform now ms k
|
||||||
|
|
||||||
perform :: Key -> [ModMeta] -> CommandPerform
|
perform :: POSIXTime -> [ModMeta] -> Key -> CommandPerform
|
||||||
perform k [] = next $ cleanup k
|
perform _ [] k = next $ cleanup k
|
||||||
perform k ms = do
|
perform now ms k = do
|
||||||
oldm <- getCurrentMetaData k
|
oldm <- getCurrentMetaData k
|
||||||
let m = foldl' unionMetaData newMetaData $ map (modMeta oldm) ms
|
let m = foldl' unionMetaData newMetaData $ map (modMeta oldm) ms
|
||||||
addMetaData k m
|
addMetaData' k m now
|
||||||
next $ cleanup k
|
next $ cleanup k
|
||||||
|
|
||||||
cleanup :: Key -> CommandCleanup
|
cleanup :: Key -> CommandCleanup
|
||||||
|
|
|
@ -31,6 +31,7 @@ module Logs.MetaData (
|
||||||
setMetaData,
|
setMetaData,
|
||||||
unsetMetaData,
|
unsetMetaData,
|
||||||
addMetaData,
|
addMetaData,
|
||||||
|
addMetaData',
|
||||||
currentMetaData,
|
currentMetaData,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -70,12 +71,17 @@ setMetaData' isset k field s = addMetaData k $
|
||||||
{- Adds in some metadata, which can override existing values, or unset
|
{- Adds in some metadata, which can override existing values, or unset
|
||||||
- them, but otherwise leaves any existing metadata as-is. -}
|
- them, but otherwise leaves any existing metadata as-is. -}
|
||||||
addMetaData :: Key -> MetaData -> Annex ()
|
addMetaData :: Key -> MetaData -> Annex ()
|
||||||
addMetaData k metadata = do
|
addMetaData k metadata = addMetaData' k metadata =<< liftIO getPOSIXTime
|
||||||
now <- liftIO getPOSIXTime
|
|
||||||
Annex.Branch.change (metaDataLogFile k) $
|
{- Reusing the same timestamp when making changes to the metadata
|
||||||
showLog . simplifyLog
|
- of multiple keys is a nice optimisation. The same metadata lines
|
||||||
. S.insert (LogEntry now metadata)
|
- will tend to be generated across the different log files, and so
|
||||||
. parseLog
|
- git will be able to pack the data more efficiently. -}
|
||||||
|
addMetaData' :: Key -> MetaData -> POSIXTime -> Annex ()
|
||||||
|
addMetaData' k metadata now = Annex.Branch.change (metaDataLogFile k) $
|
||||||
|
showLog . simplifyLog
|
||||||
|
. S.insert (LogEntry now metadata)
|
||||||
|
. parseLog
|
||||||
|
|
||||||
{- Simplify a log, removing historical values that are no longer
|
{- Simplify a log, removing historical values that are no longer
|
||||||
- needed.
|
- needed.
|
||||||
|
|
Loading…
Add table
Reference in a new issue