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.
This commit is contained in:
Joey Hess 2015-12-22 17:52:39 -04:00
parent d8a8c77a8f
commit c4152654d2
Failed to extract signature
2 changed files with 25 additions and 2 deletions

View file

@ -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

View file

@ -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