summaryrefslogtreecommitdiff
path: root/Command/Lock.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-11 14:54:29 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-11 14:54:29 -0400
commitdffe9499630a8dded76b23ef762f03aa264dc45c (patch)
tree5dcbfff9b0a5ba070c85336fcb643f6a528816f4 /Command/Lock.hs
parent8a8987579f8efe290e5084202a416f72eec491a6 (diff)
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.
Diffstat (limited to 'Command/Lock.hs')
-rw-r--r--Command/Lock.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/Command/Lock.hs b/Command/Lock.hs
index 955749e93..6ae59221c 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