From 8b8506748c362241d39cbf4cf04714f8462489da Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 17 Oct 2013 14:51:19 -0400 Subject: use TopFilePath for DiffTree and LsTree --- Git/DiffTree.hs | 5 +++-- Git/FilePath.hs | 6 ++++++ Git/LsTree.hs | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'Git') diff --git a/Git/DiffTree.hs b/Git/DiffTree.hs index 62330612c..e7787caee 100644 --- a/Git/DiffTree.hs +++ b/Git/DiffTree.hs @@ -20,6 +20,7 @@ import Common import Git import Git.Sha import Git.Command +import Git.FilePath import qualified Git.Filename import qualified Git.Ref @@ -29,7 +30,7 @@ data DiffTreeItem = DiffTreeItem , srcsha :: Sha -- nullSha if file was added , dstsha :: Sha -- nullSha if file was deleted , status :: String - , file :: FilePath + , file :: TopFilePath } deriving Show {- Diffs two tree Refs. -} @@ -86,7 +87,7 @@ parseDiffTree l = go l [] , srcsha = fromMaybe (error "bad srcsha") $ extractSha ssha , dstsha = fromMaybe (error "bad dstsha") $ extractSha dsha , status = s - , file = Git.Filename.decode f + , file = asTopFilePath $ Git.Filename.decode f } where readmode = fst . Prelude.head . readOct diff --git a/Git/FilePath.hs b/Git/FilePath.hs index 891f9991d..37d740f25 100644 --- a/Git/FilePath.hs +++ b/Git/FilePath.hs @@ -14,6 +14,7 @@ module Git.FilePath ( TopFilePath, + fromTopFilePath, getTopFilePath, toTopFilePath, asTopFilePath, @@ -27,6 +28,11 @@ import Git {- A FilePath, relative to the top of the git repository. -} newtype TopFilePath = TopFilePath { getTopFilePath :: FilePath } + deriving (Show) + +{- Returns an absolute FilePath. -} +fromTopFilePath :: TopFilePath -> Git.Repo -> FilePath +fromTopFilePath p repo = absPathFrom (repoPath repo) (getTopFilePath p) {- The input FilePath can be absolute, or relative to the CWD. -} toTopFilePath :: FilePath -> Git.Repo -> IO TopFilePath diff --git a/Git/LsTree.hs b/Git/LsTree.hs index 6e4cd8470..031dba0cf 100644 --- a/Git/LsTree.hs +++ b/Git/LsTree.hs @@ -20,13 +20,14 @@ import Common import Git import Git.Command import Git.Sha +import Git.FilePath import qualified Git.Filename data TreeItem = TreeItem { mode :: FileMode , typeobj :: String , sha :: String - , file :: FilePath + , file :: TopFilePath } deriving Show {- Lists the complete contents of a tree, with lazy output. -} @@ -48,7 +49,7 @@ parseLsTree l = TreeItem { mode = fst $ Prelude.head $ readOct m , typeobj = t , sha = s - , file = Git.Filename.decode f + , file = asTopFilePath $ Git.Filename.decode f } where -- l = SP SP TAB -- cgit v1.2.3