From 8ba1f8f3327288bba9e27081d1aa651adbaa1e3e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 2 Apr 2013 12:58:56 -0400 Subject: optimise last commit Rather than re-adding a direct mode file unnecessarily when it's not changed, just re-stage the symlink. --- Assistant/Threads/Watcher.hs | 50 +++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs index 89cef6ea7..c41b17434 100644 --- a/Assistant/Threads/Watcher.hs +++ b/Assistant/Threads/Watcher.hs @@ -184,24 +184,29 @@ onAdd matcher file filestatus | otherwise = noChange {- In direct mode, add events are received for both new files, and - - 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. -} + - modified existing files. -} onAddDirect :: FileMatcher -> Handler onAddDirect matcher file fs = do - debug ["add direct", file] v <- liftAnnex $ catKeyFile file case (v, fs) of (Just key, Just 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 + debug ["changed direct", file] liftAnnex $ changedDirect key 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. - 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 liftIO $ removeFile file liftAnnex $ Backend.makeAnnexLink link file - addlink link (Just key) + addLink file link (Just key) ) go Nothing = do -- other symlink mlink <- liftIO (catchMaybeIO $ readSymbolicLink file) @@ -238,24 +243,25 @@ onAddSymlink isdirect file filestatus = go =<< liftAnnex (Backend.lookupFile fil - links too.) -} ensurestaged (Just link) mk daemonstatus - | scanComplete daemonstatus = addlink link mk + | scanComplete daemonstatus = addLink file link mk | otherwise = case filestatus of Just s | not (afterLastDaemonRun (statusChangeTime s) daemonstatus) -> noChange - _ -> addlink link mk + _ -> addLink file link mk ensurestaged Nothing _ _ = noChange - {- For speed, tries to reuse the existing blob for symlink target. -} - addlink link mk = do - debug ["add symlink", file] - liftAnnex $ do - v <- catObjectDetails $ Ref $ ':':file - case v of - Just (currlink, sha) - | s2w8 link == L.unpack currlink -> - stageSymlink file sha - _ -> stageSymlink file =<< hashSymlink link - madeChange file $ LinkChange mk +{- For speed, tries to reuse the existing blob for symlink target. -} +addLink :: FilePath -> FilePath -> Maybe Key -> Assistant (Maybe Change) +addLink file link mk = do + debug ["add symlink", file] + liftAnnex $ do + v <- catObjectDetails $ Ref $ ':':file + case v of + Just (currlink, sha) + | s2w8 link == L.unpack currlink -> + stageSymlink file sha + _ -> stageSymlink file =<< hashSymlink link + madeChange file $ LinkChange mk onDel :: Handler onDel file _ = do -- cgit v1.2.3