From dffe9499630a8dded76b23ef762f03aa264dc45c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Nov 2010 14:54:29 -0400 Subject: [PATCH] Optimize both pre-commit and lock subcommands. isLocked was doing the expensive check before the cheap one. Let's not fork git diff twice per file when committing, especially. git diff is still run more than strictly necessary (ie, more than once) if multiple unlocked files are being committed. But much better now. --- Command/Lock.hs | 18 ++++++++++-------- Command/PreCommit.hs | 5 +++-- debian/changelog | 6 ++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Command/Lock.hs b/Command/Lock.hs index 955749e93d..6ae59221c8 100644 --- a/Command/Lock.hs +++ b/Command/Lock.hs @@ -37,14 +37,16 @@ perform file = do liftIO $ Git.run g ["checkout", "--", file] return $ Just $ return True -- no cleanup needed -{- Checks if a file is unlocked for edit. - - - - But, without the symlink to the annex, cannot tell for sure if the - - file was annexed before. So, check if git thinks the file's type has - - changed (from a symlink to a regular file). -} +{- Checks if a file is unlocked for edit. -} isLocked :: FilePath -> Annex Bool isLocked file = do - g <- Annex.gitRepo - typechanged <- liftIO $ Git.typeChangedFiles g file + -- check if it's a symlink first, as that's cheapest s <- liftIO $ getSymbolicLinkStatus file - return $ (not $ elem file typechanged) || isSymbolicLink s + if (isSymbolicLink s) + then return True -- Symlinked files are always locked. + else do + -- Not a symlink, so see if the type has changed, + -- if so it is presumed to have been unlocked. + g <- Annex.gitRepo + typechanged <- liftIO $ Git.typeChangedFiles g file + return $ not $ elem file typechanged diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs index cd6ce6f080..72cece8d50 100644 --- a/Command/PreCommit.hs +++ b/Command/PreCommit.hs @@ -22,7 +22,7 @@ import qualified Command.Add start :: SubCmdStartString start file = do -- If a file is unlocked for edit, add its new content to the - -- annex, -} + -- annex. -} locked <- Command.Lock.isLocked file when (not locked) $ do pairs <- Backend.chooseBackends [file] @@ -30,7 +30,8 @@ start file = do unless (ok) $ do error $ "failed to add " ++ file ++ "; canceling commit" -- git commit will have staged the file's content; - -- drop that and stage the symlink + -- drop that and run command queued by Add.state to + -- stage the symlink g <- Annex.gitRepo liftIO $ Git.run g ["reset", "-q", "--", file] Annex.queueRun diff --git a/debian/changelog b/debian/changelog index 0c09eb7ea4..a4c8bceac0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +git-annex (0.05) UNRELEASED; urgency=low + + * Optimize both pre-commit and lock subcommands. + + -- Joey Hess Thu, 11 Nov 2010 14:52:05 -0400 + git-annex (0.04) unstable; urgency=low * Add unlock subcommand, which replaces the symlink with a copy of