optimise last commit

Rather than re-adding a direct mode file unnecessarily when it's not
changed, just re-stage the symlink.
This commit is contained in:
Joey Hess 2013-04-02 12:58:56 -04:00
parent 31cbde8190
commit 8c52b20cc7

View file

@ -184,24 +184,29 @@ onAdd matcher file filestatus
| otherwise = noChange | otherwise = noChange
{- In direct mode, add events are received for both new files, and {- In direct mode, add events are received for both new files, and
- modified existing files. - modified existing files. -}
-
- It's possible to get an add event for an existing file that is not
- really modified, but it might have just been deleted and been put back,
- so it's restaged to make sure. -}
onAddDirect :: FileMatcher -> Handler onAddDirect :: FileMatcher -> Handler
onAddDirect matcher file fs = do onAddDirect matcher file fs = do
debug ["add direct", file]
v <- liftAnnex $ catKeyFile file v <- liftAnnex $ catKeyFile file
case (v, fs) of case (v, fs) of
(Just key, Just filestatus) -> (Just key, Just filestatus) ->
ifM (liftAnnex $ sameFileStatus key filestatus) ifM (liftAnnex $ sameFileStatus key filestatus)
( add matcher file {- It's possible to get an add event for
- an existing file that is not
- really modified, but it might have
- just been deleted and been put back,
- so it symlink is restaged to make sure. -}
( do
link <- liftAnnex $ calcGitLink file key
addLink file link (Just key)
, do , do
debug ["changed direct", file]
liftAnnex $ changedDirect key file liftAnnex $ changedDirect key file
add matcher file add matcher file
) )
_ -> add matcher file _ -> do
debug ["add direct", file]
add matcher file
{- A symlink might be an arbitrary symlink, which is just added. {- A symlink might be an arbitrary symlink, which is just added.
- Or, if it is a git-annex symlink, ensure it points to the content - Or, if it is a git-annex symlink, ensure it points to the content
@ -220,7 +225,7 @@ onAddSymlink isdirect file filestatus = go =<< liftAnnex (Backend.lookupFile fil
unless isdirect $ do unless isdirect $ do
liftIO $ removeFile file liftIO $ removeFile file
liftAnnex $ Backend.makeAnnexLink link file liftAnnex $ Backend.makeAnnexLink link file
addlink link (Just key) addLink file link (Just key)
) )
go Nothing = do -- other symlink go Nothing = do -- other symlink
mlink <- liftIO (catchMaybeIO $ readSymbolicLink file) mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
@ -238,15 +243,16 @@ onAddSymlink isdirect file filestatus = go =<< liftAnnex (Backend.lookupFile fil
- links too.) - links too.)
-} -}
ensurestaged (Just link) mk daemonstatus ensurestaged (Just link) mk daemonstatus
| scanComplete daemonstatus = addlink link mk | scanComplete daemonstatus = addLink file link mk
| otherwise = case filestatus of | otherwise = case filestatus of
Just s Just s
| not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange | not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange
_ -> addlink link mk _ -> addLink file link mk
ensurestaged Nothing _ _ = noChange ensurestaged Nothing _ _ = noChange
{- For speed, tries to reuse the existing blob for symlink target. -} {- For speed, tries to reuse the existing blob for symlink target. -}
addlink link mk = do addLink :: FilePath -> FilePath -> Maybe Key -> Assistant (Maybe Change)
addLink file link mk = do
debug ["add symlink", file] debug ["add symlink", file]
liftAnnex $ do liftAnnex $ do
v <- catObjectDetails $ Ref $ ':':file v <- catObjectDetails $ Ref $ ':':file