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.
This commit is contained in:
Joey Hess 2011-07-14 16:56:06 -04:00
parent 0c46cbab09
commit ded2591124
10 changed files with 26 additions and 20 deletions

View file

@ -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