summaryrefslogtreecommitdiff
path: root/Git/UpdateIndex.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Git/UpdateIndex.hs')
-rw-r--r--Git/UpdateIndex.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/Git/UpdateIndex.hs b/Git/UpdateIndex.hs
index ecd154a..55c5b3b 100644
--- a/Git/UpdateIndex.hs
+++ b/Git/UpdateIndex.hs
@@ -1,6 +1,6 @@
{- git-update-index library
-
- - Copyright 2011-2013 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2013 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -19,7 +19,8 @@ module Git.UpdateIndex (
updateIndexLine,
stageFile,
unstageFile,
- stageSymlink
+ stageSymlink,
+ stageDiffTreeItem,
) where
import Common
@@ -28,6 +29,7 @@ import Git.Types
import Git.Command
import Git.FilePath
import Git.Sha
+import qualified Git.DiffTreeItem as Diff
{- Streamers are passed a callback and should feed it lines in the form
- read by update-index, and generated by ls-tree. -}
@@ -95,7 +97,10 @@ stageFile sha filetype file repo = do
unstageFile :: FilePath -> Repo -> IO Streamer
unstageFile file repo = do
p <- toTopFilePath file repo
- return $ pureStreamer $ "0 " ++ fromRef nullSha ++ "\t" ++ indexPath p
+ return $ unstageFile' p
+
+unstageFile' :: TopFilePath -> Streamer
+unstageFile' p = pureStreamer $ "0 " ++ fromRef nullSha ++ "\t" ++ indexPath p
{- A streamer that adds a symlink to the index. -}
stageSymlink :: FilePath -> Sha -> Repo -> IO Streamer
@@ -106,5 +111,11 @@ stageSymlink file sha repo = do
<*> toTopFilePath file repo
return $ pureStreamer line
+{- A streamer that applies a DiffTreeItem to the index. -}
+stageDiffTreeItem :: Diff.DiffTreeItem -> Streamer
+stageDiffTreeItem d = case toBlobType (Diff.dstmode d) of
+ Nothing -> unstageFile' (Diff.file d)
+ Just t -> pureStreamer $ updateIndexLine (Diff.dstsha d) t (Diff.file d)
+
indexPath :: TopFilePath -> InternalGitPath
indexPath = toInternalGitPath . getTopFilePath