use TopFilePath for DiffTree and LsTree

This commit is contained in:
Joey Hess 2013-10-17 14:51:19 -04:00
parent f40ed91276
commit d785432f78
3 changed files with 12 additions and 4 deletions

View file

@ -20,6 +20,7 @@ import Common
import Git import Git
import Git.Sha import Git.Sha
import Git.Command import Git.Command
import Git.FilePath
import qualified Git.Filename import qualified Git.Filename
import qualified Git.Ref import qualified Git.Ref
@ -29,7 +30,7 @@ data DiffTreeItem = DiffTreeItem
, srcsha :: Sha -- nullSha if file was added , srcsha :: Sha -- nullSha if file was added
, dstsha :: Sha -- nullSha if file was deleted , dstsha :: Sha -- nullSha if file was deleted
, status :: String , status :: String
, file :: FilePath , file :: TopFilePath
} deriving Show } deriving Show
{- Diffs two tree Refs. -} {- Diffs two tree Refs. -}
@ -86,7 +87,7 @@ parseDiffTree l = go l []
, srcsha = fromMaybe (error "bad srcsha") $ extractSha ssha , srcsha = fromMaybe (error "bad srcsha") $ extractSha ssha
, dstsha = fromMaybe (error "bad dstsha") $ extractSha dsha , dstsha = fromMaybe (error "bad dstsha") $ extractSha dsha
, status = s , status = s
, file = Git.Filename.decode f , file = asTopFilePath $ Git.Filename.decode f
} }
where where
readmode = fst . Prelude.head . readOct readmode = fst . Prelude.head . readOct

View file

@ -14,6 +14,7 @@
module Git.FilePath ( module Git.FilePath (
TopFilePath, TopFilePath,
fromTopFilePath,
getTopFilePath, getTopFilePath,
toTopFilePath, toTopFilePath,
asTopFilePath, asTopFilePath,
@ -27,6 +28,11 @@ import Git
{- A FilePath, relative to the top of the git repository. -} {- A FilePath, relative to the top of the git repository. -}
newtype TopFilePath = TopFilePath { getTopFilePath :: FilePath } 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. -} {- The input FilePath can be absolute, or relative to the CWD. -}
toTopFilePath :: FilePath -> Git.Repo -> IO TopFilePath toTopFilePath :: FilePath -> Git.Repo -> IO TopFilePath

View file

@ -20,13 +20,14 @@ import Common
import Git import Git
import Git.Command import Git.Command
import Git.Sha import Git.Sha
import Git.FilePath
import qualified Git.Filename import qualified Git.Filename
data TreeItem = TreeItem data TreeItem = TreeItem
{ mode :: FileMode { mode :: FileMode
, typeobj :: String , typeobj :: String
, sha :: String , sha :: String
, file :: FilePath , file :: TopFilePath
} deriving Show } deriving Show
{- Lists the complete contents of a tree, with lazy output. -} {- Lists the complete contents of a tree, with lazy output. -}
@ -48,7 +49,7 @@ parseLsTree l = TreeItem
{ mode = fst $ Prelude.head $ readOct m { mode = fst $ Prelude.head $ readOct m
, typeobj = t , typeobj = t
, sha = s , sha = s
, file = Git.Filename.decode f , file = asTopFilePath $ Git.Filename.decode f
} }
where where
-- l = <mode> SP <type> SP <sha> TAB <file> -- l = <mode> SP <type> SP <sha> TAB <file>