summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-12 14:46:28 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-12 14:46:47 -0400
commitdb92795125fd5d9df3b1cf50f92c1e046645f8bf (patch)
treee5832b6e06ab04946a176129ed3a0a78c1a60577 /Annex
parent5abc2da9d1f4f6043370158fb1c0569eccf29941 (diff)
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.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Branch.hs11
1 files changed, 10 insertions, 1 deletions
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 ()