summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-28 14:19:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-28 14:21:30 -0400
commit92e5d28ca83d057a3d8f5d7d30806642de699172 (patch)
treea4021ec369a077dd3916c98e3ebfd9e368302afc /Command.hs
parent1f9ce9e9a5f6d7eaf149f42de559cb9830c7f28e (diff)
precommit: Optimise to avoid calling git-check-attr more than once.
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs32
1 files changed, 16 insertions, 16 deletions
diff --git a/Command.hs b/Command.hs
index 4d10a9e7f..7f3063abb 100644
--- a/Command.hs
+++ b/Command.hs
@@ -41,8 +41,9 @@ type SubCmdCleanup = Annex Bool
- functions. -}
type SubCmdSeekStrings = SubCmdStartString -> SubCmdSeek
type SubCmdStartString = String -> SubCmdStart
+type BackendFile = (FilePath, Maybe Backend)
type SubCmdSeekBackendFiles = SubCmdStartBackendFile -> SubCmdSeek
-type SubCmdStartBackendFile = (FilePath, Maybe Backend) -> SubCmdStart
+type SubCmdStartBackendFile = BackendFile -> SubCmdStart
type SubCmdSeekNothing = SubCmdStart -> SubCmdSeek
type SubCmdStartNothing = SubCmdStart
@@ -116,17 +117,6 @@ withFilesNotInGit a params = do
repo <- Annex.gitRepo
newfiles <- liftIO $ mapM (Git.notInRepo repo) params
backendPairs a $ filter notState $ foldl (++) [] newfiles
-withFilesUnlocked :: SubCmdSeekBackendFiles
-withFilesUnlocked a params = do
- -- unlocked files have changed type from a symlink to a regular file
- repo <- Annex.gitRepo
- typechangedfiles <- liftIO $ mapM (Git.typeChangedFiles repo) params
- unlockedfiles <- liftIO $ filterM notSymlink $ foldl (++) [] typechangedfiles
- backendPairs a $ filter notState unlockedfiles
-backendPairs :: SubCmdSeekBackendFiles
-backendPairs a files = do
- pairs <- Backend.chooseBackends files
- return $ map a pairs
withString :: SubCmdSeekStrings
withString a params = return [a $ unwords params]
withStrings :: SubCmdSeekStrings
@@ -136,12 +126,17 @@ withFilesToBeCommitted a params = do
repo <- Annex.gitRepo
tocommit <- liftIO $ mapM (Git.stagedFiles repo) params
return $ map a $ filter notState $ foldl (++) [] tocommit
-withUnlockedFilesToBeCommitted :: SubCmdSeekStrings
-withUnlockedFilesToBeCommitted a params = do
+withFilesUnlocked :: SubCmdSeekBackendFiles
+withFilesUnlocked = withFilesUnlocked' Git.typeChangedFiles
+withFilesUnlockedToBeCommitted :: SubCmdSeekBackendFiles
+withFilesUnlockedToBeCommitted = withFilesUnlocked' Git.typeChangedStagedFiles
+withFilesUnlocked' :: (Git.Repo -> FilePath -> IO [FilePath]) -> SubCmdSeekBackendFiles
+withFilesUnlocked' typechanged a params = do
+ -- unlocked files have changed type from a symlink to a regular file
repo <- Annex.gitRepo
- typechangedfiles <- liftIO $ mapM (Git.typeChangedStagedFiles repo) params
+ typechangedfiles <- liftIO $ mapM (typechanged repo) params
unlockedfiles <- liftIO $ filterM notSymlink $ foldl (++) [] typechangedfiles
- return $ map a $ filter notState unlockedfiles
+ backendPairs a $ filter notState unlockedfiles
withKeys :: SubCmdSeekStrings
withKeys a params = return $ map a params
withTempFile :: SubCmdSeekStrings
@@ -150,6 +145,11 @@ withNothing :: SubCmdSeekNothing
withNothing a [] = return [a]
withNothing _ _ = return []
+backendPairs :: SubCmdSeekBackendFiles
+backendPairs a files = do
+ pairs <- Backend.chooseBackends files
+ return $ map a pairs
+
{- Default to acting on all files matching the seek action if
- none are specified. -}
withAll :: SubCmdSeekStrings -> SubCmdSeekStrings