summaryrefslogtreecommitdiff
path: root/Git/Queue.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-07-14 16:56:06 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-07-14 17:15:37 -0400
commitded259112449f592bc42207e89c82268f3795f12 (patch)
tree6a3e624445cbd063e32f3f0247a552f0ff47074a /Git/Queue.hs
parent0c46cbab09af8cc8761668885e58944d397b856d (diff)
unannex: Clean up use of git commit -a.
This was more complex than would be expected. unannex has to use git commit -a since it's removing files from git; git commit filelist won't do. Allow commands to be added to the Git queue that have no associated files, and run such commands once.
Diffstat (limited to 'Git/Queue.hs')
-rw-r--r--Git/Queue.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/Git/Queue.hs b/Git/Queue.hs
index e1ec0cd31..e080476b7 100644
--- a/Git/Queue.hs
+++ b/Git/Queue.hs
@@ -53,15 +53,15 @@ empty :: Queue
empty = Queue 0 M.empty
{- Adds an action to a queue. -}
-add :: Queue -> String -> [CommandParam] -> FilePath -> Queue
-add (Queue n m) subcommand params file = Queue (n + 1) m'
+add :: Queue -> String -> [CommandParam] -> [FilePath] -> Queue
+add (Queue n m) subcommand params files = Queue (n + 1) m'
where
action = Action subcommand params
-- There are probably few items in the map, but there
-- can be a lot of files per item. So, optimise adding
-- files.
- m' = M.insertWith' const action files m
- files = file:(M.findWithDefault [] action m)
+ m' = M.insertWith' const action fs m
+ fs = files ++ (M.findWithDefault [] action m)
{- Number of items in a queue. -}
size :: Queue -> Int
@@ -79,11 +79,14 @@ flush repo (Queue _ m) = do
{- Runs an Action on a list of files in a git repository.
-
- - Complicated by commandline length limits. -}
+ - Complicated by commandline length limits.
+ -
+ - Intentionally runs the command even if the list of files is empty;
+ - this allows queueing commands that do not need a list of files. -}
runAction :: Repo -> Action -> [FilePath] -> IO ()
-runAction repo action files = unless (null files) runxargs
+runAction repo action files =
+ pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs
where
- runxargs = pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs
params = toCommand $ gitCommandLine repo
(Param (getSubcommand action):getParams action)
feedxargs h = hPutStr h $ join "\0" files