use ShellParam type

So, I have a type checked safe handling of filenames starting with dashes,
throughout the code.
This commit is contained in:
Joey Hess 2011-02-28 16:10:16 -04:00
parent 7e5678bcf7
commit fcdc4797a9
24 changed files with 151 additions and 124 deletions

View file

@ -17,6 +17,7 @@ import System.IO
import System.Cmd.Utils
import Data.String.Utils
import Control.Monad (unless, forM_)
import Utility
import qualified GitRepo as Git
@ -24,7 +25,7 @@ import qualified GitRepo as Git
- is not included, and must be able to be appended after the params. -}
data Action = Action {
getSubcommand :: String,
getParams :: [String]
getParams :: [ShellParam]
} deriving (Show, Eq, Ord)
{- A queue of actions to perform (in any order) on a git repository,
@ -37,7 +38,7 @@ empty :: Queue
empty = M.empty
{- Adds an action to a queue. -}
add :: Queue -> String -> [String] -> FilePath -> Queue
add :: Queue -> String -> [ShellParam] -> FilePath -> Queue
add queue subcommand params file = M.insertWith (++) action [file] queue
where
action = Action subcommand params
@ -55,7 +56,7 @@ runAction :: Git.Repo -> Action -> [FilePath] -> IO ()
runAction repo action files = do
unless (null files) runxargs
where
runxargs = pOpen WriteToPipe "xargs" ("-0":gitcmd) feedxargs
gitcmd = "git" : Git.gitCommandLine repo
(getSubcommand action:getParams action)
runxargs = pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs
params = toShell $ Git.gitCommandLine repo
(Param (getSubcommand action):getParams action)
feedxargs h = hPutStr h $ join "\0" files