use -z with git-ls-files, to support files with odd chars

This commit is contained in:
Joey Hess 2010-10-29 17:37:05 -04:00
parent c9347693d7
commit 8e158b7cec

View file

@ -201,24 +201,30 @@ pipeRead repo params = assertLocal repo $ do
{- Passed a location, recursively scans for all files that {- Passed a location, recursively scans for all files that
- are checked into git at that location. -} - are checked into git at that location. -}
inRepo :: Repo -> FilePath -> IO [FilePath] inRepo :: Repo -> FilePath -> IO [FilePath]
inRepo repo location = do inRepo repo location = pipeNullSplit repo
s <- pipeRead repo ["ls-files", "--cached", "--exclude-standard", location] ["ls-files", "--cached", "--exclude-standard", "-z", location]
return $ lines s
{- Passed a location, recursively scans for all files that are not checked {- Passed a location, recursively scans for all files that are not checked
- into git, and not gitignored. -} - into git, and not gitignored. -}
notInRepo :: Repo -> FilePath -> IO [FilePath] notInRepo :: Repo -> FilePath -> IO [FilePath]
notInRepo repo location = do notInRepo repo location = pipeNullSplit repo
s <- pipeRead repo ["ls-files", "--others", "--exclude-standard", location] ["ls-files", "--others", "--exclude-standard", "-z", location]
return $ lines s
{- Passed a location, returns a list of the files that are staged for {- Passed a location, returns a list of the files, staged for
- commit that are being added, moved, or changed (but not deleted). -} - commit, that are being added, moved, or changed (but not deleted). -}
stagedFiles :: Repo -> FilePath -> IO [FilePath] stagedFiles :: Repo -> FilePath -> IO [FilePath]
stagedFiles repo location = do stagedFiles repo location = pipeNullSplit repo
fs0 <- pipeRead repo ["diff", "--cached", "--name-only", ["diff", "--cached", "--name-only", "--diff-filter=ACMRT", "-z",
"--diff-filter=ACMRT", "-z", "HEAD", location] "HEAD", location]
return $ filter (not . null) $ split "\0" fs0
{- Reads null terminated output of a git command (as enabled by the -z
- parameter), and splits it into a list of files. -}
pipeNullSplit :: Repo -> [String] -> IO [FilePath]
pipeNullSplit repo params = do
fs0 <- pipeRead repo params
return $ split0 fs0
where
split0 s = filter (not . null) $ split "\0" s
{- Runs git config and populates a repo with its config. -} {- Runs git config and populates a repo with its config. -}
configRead :: Repo -> IO Repo configRead :: Repo -> IO Repo