synthesize RmChange when a directory is deleted
This gets directory renames closer to being fully detected. There's close to no extra overhead to doing it this way.
This commit is contained in:
parent
c15023a8b4
commit
f340fd324c
3 changed files with 26 additions and 13 deletions
|
@ -80,7 +80,7 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
|
||||||
changes <- getChanges
|
changes <- getChanges
|
||||||
-- See if now's a good time to commit.
|
-- See if now's a good time to commit.
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
case (shouldCommit now changes, lonelychange changes) of
|
case (shouldCommit now changes, possiblyrename changes) of
|
||||||
(True, False) -> a (changes, now)
|
(True, False) -> a (changes, now)
|
||||||
(True, True) -> do
|
(True, True) -> do
|
||||||
-- Wait for other, related changes to arrive.
|
-- Wait for other, related changes to arrive.
|
||||||
|
@ -92,10 +92,13 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
|
||||||
_ -> refill changes
|
_ -> refill changes
|
||||||
where
|
where
|
||||||
{- Did we perhaps only get one of the AddChange and RmChange pair
|
{- Did we perhaps only get one of the AddChange and RmChange pair
|
||||||
- that make up a rename? -}
|
- that make up a file rename? Or some of the pairs that make up
|
||||||
lonelychange [(PendingAddChange _ _)] = True
|
- a directory rename?
|
||||||
lonelychange [c] | isRmChange c = True
|
-}
|
||||||
lonelychange _ = False
|
possiblyrename cs = all renamepart cs
|
||||||
|
|
||||||
|
renamepart (PendingAddChange _ _) = True
|
||||||
|
renamepart c = isRmChange c
|
||||||
|
|
||||||
isRmChange :: Change -> Bool
|
isRmChange :: Change -> Bool
|
||||||
isRmChange (Change { changeInfo = i }) | i == RmChange = True
|
isRmChange (Change { changeInfo = i }) | i == RmChange = True
|
||||||
|
|
|
@ -43,6 +43,7 @@ import Data.Bits.Utils
|
||||||
import Data.Typeable
|
import Data.Typeable
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
|
import Data.Time.Clock
|
||||||
|
|
||||||
checkCanWatch :: Annex ()
|
checkCanWatch :: Annex ()
|
||||||
checkCanWatch
|
checkCanWatch
|
||||||
|
@ -251,17 +252,26 @@ onDel file _ = do
|
||||||
|
|
||||||
{- A directory has been deleted, or moved, so tell git to remove anything
|
{- A directory has been deleted, or moved, so tell git to remove anything
|
||||||
- that was inside it from its cache. Since it could reappear at any time,
|
- that was inside it from its cache. Since it could reappear at any time,
|
||||||
- use --cached to only delete it from the index.
|
- use --cached to only delete it from the index.
|
||||||
-
|
-
|
||||||
- Note: This could use unstageFile, but would need to run another git
|
- This queues up a lot of RmChanges, which assists the Committer in
|
||||||
- command to get the recursive list of files in the directory, so rm is
|
- pairing up renamed files when the directory was renamed. -}
|
||||||
- just as good. -}
|
|
||||||
onDelDir :: Handler
|
onDelDir :: Handler
|
||||||
onDelDir dir _ = do
|
onDelDir dir _ = do
|
||||||
debug ["directory deleted", dir]
|
debug ["directory deleted", dir]
|
||||||
liftAnnex $ Annex.Queue.addCommand "rm"
|
(fs, clean) <- liftAnnex $ inRepo $ LsFiles.deleted [dir]
|
||||||
[Params "--quiet -r --cached --ignore-unmatch --"] [dir]
|
|
||||||
madeChange dir RmDirChange
|
liftAnnex $ forM_ fs $ \f -> Annex.Queue.addUpdateIndex =<<
|
||||||
|
inRepo (Git.UpdateIndex.unstageFile f)
|
||||||
|
|
||||||
|
-- Get the events queued up as fast as possible, so the
|
||||||
|
-- committer sees them all in one block.
|
||||||
|
now <- liftIO getCurrentTime
|
||||||
|
forM_ fs $ \f -> recordChange $ Change now f RmChange
|
||||||
|
|
||||||
|
void $ liftIO $ clean
|
||||||
|
liftAnnex $ Annex.Queue.flushWhenFull
|
||||||
|
noChange
|
||||||
|
|
||||||
{- Called when there's an error with inotify or kqueue. -}
|
{- Called when there's an error with inotify or kqueue. -}
|
||||||
onErr :: Handler
|
onErr :: Handler
|
||||||
|
|
|
@ -14,7 +14,7 @@ import Utility.TSet
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
|
|
||||||
data ChangeInfo = AddChange Key | LinkChange (Maybe Key) | RmChange | RmDirChange
|
data ChangeInfo = AddChange Key | LinkChange (Maybe Key) | RmChange
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
changeInfoKey :: ChangeInfo -> Maybe Key
|
changeInfoKey :: ChangeInfo -> Maybe Key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue