From db92795125fd5d9df3b1cf50f92c1e046645f8bf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2015 14:46:28 -0400 Subject: Avoid unncessary write to the location log when a file is unlocked and then added back with unchanged content. Implemented with no additional overhead of compares etc. This is safe to do for presence logs because of their locality of change; a given repo's presence logs are only ever changed in that repo, or in a repo that has just been actively changing the content of that repo. So, we don't need to worry about a split-brain situation where there'd be disagreement about the location of a key in a repo. And so, it's ok to not update the timestamp when that's the only change that would be made due to logging presence info. --- Annex/Branch.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Annex') diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 5436132d8..ad96a2073 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -18,6 +18,7 @@ module Annex.Branch ( get, getHistorical, change, + maybeChange, commit, forceCommit, files, @@ -224,7 +225,15 @@ getRef ref file = withIndex $ decodeBS <$> catFile ref file - modifes the current content of the file on the branch. -} change :: FilePath -> (String -> String) -> Annex () -change file a = lockJournal $ \jl -> a <$> getLocal file >>= set jl file +change file f = lockJournal $ \jl -> f <$> getLocal file >>= set jl file + +{- Applies a function which can modify the content of a file, or not. -} +maybeChange :: FilePath -> (String -> Maybe String) -> Annex () +maybeChange file f = lockJournal $ \jl -> do + v <- getLocal file + case f v of + Just v' | v' /= v -> set jl file v' + _ -> noop {- Records new content of a file into the journal -} set :: JournalLocked -> FilePath -> String -> Annex () -- cgit v1.2.3