diff options
Diffstat (limited to 'Git')
-rw-r--r-- | Git/CatFile.hs | 2 | ||||
-rw-r--r-- | Git/LsFiles.hs | 43 | ||||
-rw-r--r-- | Git/LsTree.hs | 6 | ||||
-rw-r--r-- | Git/Queue.hs | 8 | ||||
-rw-r--r-- | Git/UnionMerge.hs | 54 |
5 files changed, 58 insertions, 55 deletions
diff --git a/Git/CatFile.hs b/Git/CatFile.hs index 64857c66a..51fa585a8 100644 --- a/Git/CatFile.hs +++ b/Git/CatFile.hs @@ -25,7 +25,7 @@ type CatFileHandle = (PipeHandle, Handle, Handle) {- Starts git cat-file running in batch mode in a repo and returns a handle. -} catFileStart :: Repo -> IO CatFileHandle catFileStart repo = hPipeBoth "git" $ toCommand $ - Git.gitCommandLine repo [Param "cat-file", Param "--batch"] + Git.gitCommandLine [Param "cat-file", Param "--batch"] repo {- Stops git cat-file. -} catFileStop :: CatFileHandle -> IO () diff --git a/Git/LsFiles.hs b/Git/LsFiles.hs index 28e007a4d..bceee26fc 100644 --- a/Git/LsFiles.hs +++ b/Git/LsFiles.hs @@ -19,51 +19,52 @@ import Git import Utility.SafeCommand {- Scans for files that are checked into git at the specified locations. -} -inRepo :: Repo -> [FilePath] -> IO [FilePath] -inRepo repo l = pipeNullSplit repo $ Params "ls-files --cached -z --" : map File l +inRepo :: [FilePath] -> Repo -> IO [FilePath] +inRepo l repo = pipeNullSplit (Params "ls-files --cached -z --" : map File l) repo {- Scans for files at the specified locations that are not checked into git. -} -notInRepo :: Repo -> Bool -> [FilePath] -> IO [FilePath] -notInRepo repo include_ignored l = pipeNullSplit repo $ - [Params "ls-files --others"] ++ exclude ++ - [Params "-z --"] ++ map File l +notInRepo :: Bool -> [FilePath] -> Repo -> IO [FilePath] +notInRepo include_ignored l repo = pipeNullSplit params repo where + params = [Params "ls-files --others"] ++ exclude ++ + [Params "-z --"] ++ map File l exclude | include_ignored = [] | otherwise = [Param "--exclude-standard"] {- Returns a list of all files that are staged for commit. -} -staged :: Repo -> [FilePath] -> IO [FilePath] -staged repo l = staged' repo l [] +staged :: [FilePath] -> Repo -> IO [FilePath] +staged = staged' [] {- Returns a list of the files, staged for commit, that are being added, - moved, or changed (but not deleted), from the specified locations. -} -stagedNotDeleted :: Repo -> [FilePath] -> IO [FilePath] -stagedNotDeleted repo l = staged' repo l [Param "--diff-filter=ACMRT"] +stagedNotDeleted :: [FilePath] -> Repo -> IO [FilePath] +stagedNotDeleted = staged' [Param "--diff-filter=ACMRT"] -staged' :: Repo -> [FilePath] -> [CommandParam] -> IO [FilePath] -staged' repo l middle = pipeNullSplit repo $ start ++ middle ++ end +staged' :: [CommandParam] -> [FilePath] -> Repo -> IO [FilePath] +staged' middle l = pipeNullSplit $ start ++ middle ++ end where start = [Params "diff --cached --name-only -z"] end = Param "--" : map File l {- Returns a list of files that have unstaged changes. -} -changedUnstaged :: Repo -> [FilePath] -> IO [FilePath] -changedUnstaged repo l = pipeNullSplit repo $ - Params "diff --name-only -z --" : map File l +changedUnstaged :: [FilePath] -> Repo -> IO [FilePath] +changedUnstaged l = pipeNullSplit params + where + params = Params "diff --name-only -z --" : map File l {- Returns a list of the files in the specified locations that are staged - for commit, and whose type has changed. -} -typeChangedStaged :: Repo -> [FilePath] -> IO [FilePath] -typeChangedStaged repo l = typeChanged' repo l [Param "--cached"] +typeChangedStaged :: [FilePath] -> Repo -> IO [FilePath] +typeChangedStaged = typeChanged' [Param "--cached"] {- Returns a list of the files in the specified locations whose type has - changed. Files only staged for commit will not be included. -} -typeChanged :: Repo -> [FilePath] -> IO [FilePath] -typeChanged repo l = typeChanged' repo l [] +typeChanged :: [FilePath] -> Repo -> IO [FilePath] +typeChanged = typeChanged' [] -typeChanged' :: Repo -> [FilePath] -> [CommandParam] -> IO [FilePath] -typeChanged' repo l middle = pipeNullSplit repo $ start ++ middle ++ end +typeChanged' :: [CommandParam] -> [FilePath] -> Repo -> IO [FilePath] +typeChanged' middle l = pipeNullSplit $ start ++ middle ++ end where start = [Params "diff --name-only --diff-filter=T -z"] end = Param "--" : map File l diff --git a/Git/LsTree.hs b/Git/LsTree.hs index c072ef5be..1fcdf13ed 100644 --- a/Git/LsTree.hs +++ b/Git/LsTree.hs @@ -29,9 +29,9 @@ data TreeItem = TreeItem } deriving Show {- Lists the contents of a Treeish -} -lsTree :: Repo -> Treeish -> IO [TreeItem] -lsTree repo t = map parseLsTree <$> - pipeNullSplitB repo [Params "ls-tree --full-tree -z -r --", File t] +lsTree :: Treeish -> Repo -> IO [TreeItem] +lsTree t repo = map parseLsTree <$> + pipeNullSplitB [Params "ls-tree --full-tree -z -r --", File t] repo {- Parses a line of ls-tree output. - (The --long format is not currently supported.) -} diff --git a/Git/Queue.hs b/Git/Queue.hs index 25b9ffad0..70c766d04 100644 --- a/Git/Queue.hs +++ b/Git/Queue.hs @@ -72,8 +72,8 @@ full :: Queue -> Bool full (Queue n _) = n > maxSize {- Runs a queue on a git repository. -} -flush :: Repo -> Queue -> IO Queue -flush repo (Queue _ m) = do +flush :: Queue -> Repo -> IO Queue +flush (Queue _ m) repo = do forM_ (M.toList m) $ uncurry $ runAction repo return empty @@ -87,6 +87,6 @@ runAction :: Repo -> Action -> [FilePath] -> IO () runAction repo action files = pOpen WriteToPipe "xargs" ("-0":"git":params) feedxargs where - params = toCommand $ gitCommandLine repo - (Param (getSubcommand action):getParams action) + params = toCommand $ gitCommandLine + (Param (getSubcommand action):getParams action) repo feedxargs h = hPutStr h $ join "\0" files diff --git a/Git/UnionMerge.hs b/Git/UnionMerge.hs index 859a66ca0..32966c846 100644 --- a/Git/UnionMerge.hs +++ b/Git/UnionMerge.hs @@ -27,24 +27,25 @@ import Git - - Should be run with a temporary index file configured by Git.useIndex. -} -merge :: Repo -> String -> String -> IO () -merge g x y = do - a <- ls_tree g x - b <- merge_trees g x y - update_index g (a++b) +merge :: String -> String -> Repo -> IO () +merge x y repo = do + a <- ls_tree x repo + b <- merge_trees x y repo + update_index repo (a++b) {- Merges a list of branches into the index. Previously staged changed in - the index are preserved (and participate in the merge). -} merge_index :: Repo -> [String] -> IO () -merge_index g bs = update_index g =<< concat <$> mapM (merge_tree_index g) bs +merge_index repo bs = + update_index repo =<< concat <$> mapM (\b -> merge_tree_index b repo) bs {- Feeds a list into update-index. Later items in the list can override - earlier ones, so the list can be generated from any combination of - ls_tree, merge_trees, and merge_tree_index. -} update_index :: Repo -> [String] -> IO () -update_index g l = togit ["update-index", "-z", "--index-info"] (join "\0" l) +update_index repo l = togit ["update-index", "-z", "--index-info"] (join "\0" l) where - togit ps content = pipeWrite g (map Param ps) (L.pack content) + togit ps content = pipeWrite (map Param ps) (L.pack content) repo >>= forceSuccess {- Generates a line suitable to be fed into update-index, to add @@ -53,27 +54,28 @@ update_index_line :: String -> FilePath -> String update_index_line sha file = "100644 blob " ++ sha ++ "\t" ++ file {- Gets the contents of a tree in a format suitable for update_index. -} -ls_tree :: Repo -> String -> IO [String] -ls_tree g x = pipeNullSplit g $ - map Param ["ls-tree", "-z", "-r", "--full-tree", x] +ls_tree :: String -> Repo -> IO [String] +ls_tree x = pipeNullSplit params + where + params = map Param ["ls-tree", "-z", "-r", "--full-tree", x] {- For merging two trees. -} -merge_trees :: Repo -> String -> String -> IO [String] -merge_trees g x y = calc_merge g $ "diff-tree":diff_opts ++ [x, y] +merge_trees :: String -> String -> Repo -> IO [String] +merge_trees x y = calc_merge $ "diff-tree":diff_opts ++ [x, y] {- For merging a single tree into the index. -} -merge_tree_index :: Repo -> String -> IO [String] -merge_tree_index g x = calc_merge g $ "diff-index":diff_opts ++ ["--cached", x] +merge_tree_index :: String -> Repo -> IO [String] +merge_tree_index x = calc_merge $ "diff-index":diff_opts ++ ["--cached", x] diff_opts :: [String] diff_opts = ["--raw", "-z", "-r", "--no-renames", "-l0"] {- Calculates how to perform a merge, using git to get a raw diff, - and returning a list suitable for update_index. -} -calc_merge :: Repo -> [String] -> IO [String] -calc_merge g differ = do - diff <- pipeNullSplit g $ map Param differ - l <- mapM (mergeFile g) (pairs diff) +calc_merge :: [String] -> Repo -> IO [String] +calc_merge differ repo = do + diff <- pipeNullSplit (map Param differ) repo + l <- mapM (\p -> mergeFile p repo) (pairs diff) return $ catMaybes l where pairs [] = [] @@ -81,9 +83,9 @@ calc_merge g differ = do pairs (a:b:rest) = (a,b):pairs rest {- Injects some content into git, returning its hash. -} -hashObject :: Repo -> L.ByteString -> IO String -hashObject repo content = getSha subcmd $ do - (h, s) <- pipeWriteRead repo (map Param params) content +hashObject :: L.ByteString -> Repo -> IO String +hashObject content repo = getSha subcmd $ do + (h, s) <- pipeWriteRead (map Param params) content repo L.length s `seq` do forceSuccess h reap -- XXX unsure why this is needed @@ -95,13 +97,13 @@ hashObject repo content = getSha subcmd $ do {- Given an info line from a git raw diff, and the filename, generates - a line suitable for update_index that union merges the two sides of the - diff. -} -mergeFile :: Repo -> (String, FilePath) -> IO (Maybe String) -mergeFile g (info, file) = case filter (/= nullsha) [asha, bsha] of +mergeFile :: (String, FilePath) -> Repo -> IO (Maybe String) +mergeFile (info, file) repo = case filter (/= nullsha) [asha, bsha] of [] -> return Nothing (sha:[]) -> return $ Just $ update_index_line sha file shas -> do - content <- pipeRead g $ map Param ("show":shas) - sha <- hashObject g $ unionmerge content + content <- pipeRead (map Param ("show":shas)) repo + sha <- hashObject (unionmerge content) repo return $ Just $ update_index_line sha file where [_colonamode, _bmode, asha, bsha, _status] = words info |