aboutsummaryrefslogtreecommitdiff
path: root/Git/DiffTree.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-11-13 16:41:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-11-14 14:41:07 -0400
commita471f380bd56373bf9613c3b4bfe7448318a0619 (patch)
tree356263e3de291e19d60a4ed3461706f5062877b0 /Git/DiffTree.hs
parent49e97f31528351af46437bcccfa645d949bc85a1 (diff)
undo command
This commit was sponsored by Andrew Cant.
Diffstat (limited to 'Git/DiffTree.hs')
-rw-r--r--Git/DiffTree.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/Git/DiffTree.hs b/Git/DiffTree.hs
index 489afa86c..d2148458c 100644
--- a/Git/DiffTree.hs
+++ b/Git/DiffTree.hs
@@ -7,10 +7,12 @@
module Git.DiffTree (
DiffTreeItem(..),
+ isDiffOf,
diffTree,
diffTreeRecursive,
diffIndex,
diffWorkTree,
+ diffLog,
) where
import Numeric
@@ -33,6 +35,13 @@ data DiffTreeItem = DiffTreeItem
, file :: TopFilePath
} deriving Show
+{- Checks if the DiffTreeItem modifies a file with a given name
+ - or under a directory by that name. -}
+isDiffOf :: DiffTreeItem -> TopFilePath -> Bool
+isDiffOf diff f = case getTopFilePath f of
+ "" -> True -- top of repo contains all
+ d -> d `dirContains` getTopFilePath (file diff)
+
{- Diffs two tree Refs. -}
diffTree :: Ref -> Ref -> Repo -> IO ([DiffTreeItem], IO Bool)
diffTree src dst = getdiff (Param "diff-tree")
@@ -66,16 +75,23 @@ diffIndex' ref params repo =
, return ([], return True)
)
+{- Runs git log in --raw mode to get the changes that were made in
+ - a particular commit. The output format is adjusted to be the same
+ - as diff-tree --raw._-}
+diffLog :: [CommandParam] -> Repo -> IO ([DiffTreeItem], IO Bool)
+diffLog params = getdiff (Param "log")
+ (Param "-n1" : Param "--abbrev=40" : Param "--pretty=format:" : params)
+
getdiff :: CommandParam -> [CommandParam] -> Repo -> IO ([DiffTreeItem], IO Bool)
getdiff command params repo = do
(diff, cleanup) <- pipeNullSplit ps repo
- return (parseDiffTree diff, cleanup)
+ return (parseDiffRaw diff, cleanup)
where
ps = command : Params "-z --raw --no-renames -l0" : params
-{- Parses diff-tree output. -}
-parseDiffTree :: [String] -> [DiffTreeItem]
-parseDiffTree l = go l []
+{- Parses --raw output used by diff-tree and git-log. -}
+parseDiffRaw :: [String] -> [DiffTreeItem]
+parseDiffRaw l = go l []
where
go [] c = c
go (info:f:rest) c = go rest (mk info f : c)