add support for staging other types of blobs, like symlinks, into the index

Also added a utility TopFilePath type, which could stand to be used more
widely.
This commit is contained in:
Joey Hess 2012-06-06 14:26:15 -04:00
parent 993e6459a3
commit 91db540769
4 changed files with 53 additions and 7 deletions

View file

@ -8,15 +8,17 @@
module Git.UpdateIndex (
Streamer,
stream_update_index,
ls_tree,
update_index_line,
ls_tree
) where
import System.Cmd.Utils
import Common
import Git
import Git.Types
import Git.Command
import Git.FilePath
{- Streamers are passed a callback and should feed it lines in the form
- read by update-index, and generated by ls-tree. -}
@ -37,13 +39,14 @@ stream_update_index repo as = do
hPutStr h s
hPutStr h "\0"
{- Generates a line suitable to be fed into update-index, to add
- a given file with a given sha. -}
update_index_line :: Sha -> FilePath -> String
update_index_line sha file = "100644 blob " ++ show sha ++ "\t" ++ file
{- Gets the current tree for a ref. -}
ls_tree :: Ref -> Repo -> Streamer
ls_tree (Ref x) repo streamer = mapM_ streamer =<< pipeNullSplit params repo
where
params = map Param ["ls-tree", "-z", "-r", "--full-tree", x]
{- Generates a line suitable to be fed into update-index, to add
- a given file with a given sha. -}
update_index_line :: Sha -> BlobType -> TopFilePath -> String
update_index_line sha filetype file =
show filetype ++ " blob " ++ show sha ++ "\t" ++ getTopFilePath file