From e0aff931023a6c3f7a06caaa5dfa1aad2da3889d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 23 Apr 2014 14:04:09 -0400 Subject: merge from git-annex --- Git/CatFile.hs | 7 ++++++- Git/Command.hs | 3 --- Git/Types.hs | 5 +++-- Git/UpdateIndex.hs | 8 ++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) (limited to 'Git') diff --git a/Git/CatFile.hs b/Git/CatFile.hs index c8cb76d..8e64fc5 100644 --- a/Git/CatFile.hs +++ b/Git/CatFile.hs @@ -11,6 +11,7 @@ module Git.CatFile ( catFileStart', catFileStop, catFile, + catFileDetails, catTree, catObject, catObjectDetails, @@ -52,6 +53,10 @@ catFile :: CatFileHandle -> Branch -> FilePath -> IO L.ByteString catFile h branch file = catObject h $ Ref $ fromRef branch ++ ":" ++ toInternalGitPath file +catFileDetails :: CatFileHandle -> Branch -> FilePath -> IO (Maybe (L.ByteString, Sha, ObjectType)) +catFileDetails h branch file = catObjectDetails h $ Ref $ + fromRef branch ++ ":" ++ toInternalGitPath file + {- Uses a running git cat-file read the content of an object. - Objects that do not exist will have "" returned. -} catObject :: CatFileHandle -> Ref -> IO L.ByteString @@ -103,6 +108,6 @@ catTree h treeref = go <$> catObjectDetails h treeref dropsha = L.drop 21 parsemodefile b = - let (modestr, file) = separate (== ' ') (encodeW8 $ L.unpack b) + let (modestr, file) = separate (== ' ') (decodeBS b) in (file, readmode modestr) readmode = fst . fromMaybe (0, undefined) . headMaybe . readOct diff --git a/Git/Command.hs b/Git/Command.hs index 0fa3d1b..a0c7c4b 100644 --- a/Git/Command.hs +++ b/Git/Command.hs @@ -15,9 +15,6 @@ import Common import Git import Git.Types import qualified Utility.CoProcess as CoProcess -#ifdef mingw32_HOST_OS -import Git.FilePath -#endif import Utility.Batch {- Constructs a git command line operating on the specified repo. -} diff --git a/Git/Types.hs b/Git/Types.hs index 8029225..838c9e0 100644 --- a/Git/Types.hs +++ b/Git/Types.hs @@ -11,6 +11,7 @@ import Network.URI import qualified Data.Map as M import System.Posix.Types import Utility.SafeCommand +import Utility.URI () {- Support repositories on local disk, and repositories accessed via an URL. - @@ -27,7 +28,7 @@ data RepoLocation | LocalUnknown FilePath | Url URI | Unknown - deriving (Show, Eq) + deriving (Show, Eq, Ord) data Repo = Repo { location :: RepoLocation @@ -41,7 +42,7 @@ data Repo = Repo , gitEnv :: Maybe [(String, String)] -- global options to pass to git when running git commands , gitGlobalOpts :: [CommandParam] - } deriving (Show, Eq) + } deriving (Show, Eq, Ord) type RemoteName = String diff --git a/Git/UpdateIndex.hs b/Git/UpdateIndex.hs index 6d1ff25..4ecd773 100644 --- a/Git/UpdateIndex.hs +++ b/Git/UpdateIndex.hs @@ -15,6 +15,7 @@ module Git.UpdateIndex ( startUpdateIndex, stopUpdateIndex, lsTree, + lsSubTree, updateIndexLine, stageFile, unstageFile, @@ -74,6 +75,13 @@ lsTree (Ref x) repo streamer = do void $ cleanup where params = map Param ["ls-tree", "-z", "-r", "--full-tree", x] +lsSubTree :: Ref -> FilePath -> Repo -> Streamer +lsSubTree (Ref x) p repo streamer = do + (s, cleanup) <- pipeNullSplit params repo + mapM_ streamer s + void $ cleanup + where + params = map Param ["ls-tree", "-z", "-r", "--full-tree", x, p] {- Generates a line suitable to be fed into update-index, to add - a given file with a given sha. -} -- cgit v1.2.3