summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-22 17:52:39 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-22 17:52:39 -0400
commita8d013c98a83dc641591174e76f4de848d95d2fe (patch)
tree342f854f31c29519d161f6f551837ef6f13ebf2d /Assistant
parent95c82b2a633f8cc7c3035d75afa8665f78982373 (diff)
combine PendingAddChanges for the same file into one
In v6 unlocked mode, this fixes a problem that was making eg, echo > file cause the assistant to copy the file to the annex object, instead of hard linking it. That because 2 change events were seen (one for opening the file and one for closing) and processed together the file was then locked down twice. Which meant it had mutiple hard links, and so prevented linkAnnex from hard linking it. There might be scenarios where multiple events come in, but staggered such that a file gets locked down repeatedly, and it would still be copied to the annex object in that case.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Threads/Committer.hs3
-rw-r--r--Assistant/Types/Changes.hs24
2 files changed, 25 insertions, 2 deletions
diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs
index c7633d590..0bdbb0378 100644
--- a/Assistant/Threads/Committer.hs
+++ b/Assistant/Threads/Committer.hs
@@ -55,7 +55,8 @@ commitThread = namedThread "Committer" $ do
=<< annexDelayAdd <$> Annex.getGitConfig
msg <- liftAnnex Command.Sync.commitMsg
waitChangeTime $ \(changes, time) -> do
- readychanges <- handleAdds havelsof delayadd changes
+ readychanges <- handleAdds havelsof delayadd $
+ simplifyChanges changes
if shouldCommit False time (length readychanges) readychanges
then do
debug
diff --git a/Assistant/Types/Changes.hs b/Assistant/Types/Changes.hs
index 8c2d02cab..70c40523a 100644
--- a/Assistant/Types/Changes.hs
+++ b/Assistant/Types/Changes.hs
@@ -1,10 +1,12 @@
{- git-annex assistant change tracking
-
- - Copyright 2012-2013 Joey Hess <id@joeyh.name>
+ - Copyright 2012-2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE BangPatterns #-}
+
module Assistant.Types.Changes where
import Types.KeySource
@@ -14,6 +16,7 @@ import Annex.Ingest
import Control.Concurrent.STM
import Data.Time.Clock
+import qualified Data.Set as S
{- An un-ordered pool of Changes that have been noticed and should be
- staged and committed. Changes will typically be in order, but ordering
@@ -76,3 +79,22 @@ finishedChange c@(InProcessAddChange {}) k = Change
, changeInfo = AddKeyChange k
}
finishedChange c _ = c
+
+{- Combine PendingAddChanges that are for the same file.
+ - Multiple such often get noticed when eg, a file is opened and then
+ - closed in quick succession. -}
+simplifyChanges :: [Change] -> [Change]
+simplifyChanges [c] = [c]
+simplifyChanges cl = go cl S.empty []
+ where
+ go [] _ l = reverse l
+ go (c:cs) seen l
+ | isPendingAddChange c =
+ if S.member f seen
+ then go cs seen l
+ else
+ let !seen' = S.insert f seen
+ in go cs seen' (c:l)
+ | otherwise = go cs seen (c:l)
+ where
+ f = changeFile c