summaryrefslogtreecommitdiff
path: root/Git/LsTree.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-06-26 12:15:27 -0400
committerJoey Hess <joeyh@joeyh.name>2017-06-26 12:15:55 -0400
commit63f9aba33b45e5bab688ffaa5e4182801c152828 (patch)
tree1f4e16640503b27bbd0f33241cbe1cb2c4a4eb89 /Git/LsTree.hs
parentc799b05deae723690bfac5e867f7985e8f800d0d (diff)
downloadgit-repair-63f9aba33b45e5bab688ffaa5e4182801c152828.tar.gz
merge from git-annex
Removes dependency on MissingH, adding a dependency on split instead. This commit was sponsored by Brock Spratlen on Patreon.
Diffstat (limited to 'Git/LsTree.hs')
-rw-r--r--Git/LsTree.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/Git/LsTree.hs b/Git/LsTree.hs
index 2060fa7..225f2ce 100644
--- a/Git/LsTree.hs
+++ b/Git/LsTree.hs
@@ -24,6 +24,7 @@ import Git.FilePath
import qualified Git.Filename
import Numeric
+import Data.Char
import System.Posix.Types
data TreeItem = TreeItem
@@ -66,7 +67,9 @@ lsTreeFiles t fs repo = map parseLsTree <$> pipeNullSplitStrict ps repo
, File $ fromRef t
] ++ map File fs
-{- Parses a line of ls-tree output.
+{- Parses a line of ls-tree output, in format:
+ - mode SP type SP sha TAB file
+ -
- (The --long format is not currently supported.) -}
parseLsTree :: String -> TreeItem
parseLsTree l = TreeItem
@@ -76,12 +79,9 @@ parseLsTree l = TreeItem
, file = sfile
}
where
- -- l = <mode> SP <type> SP <sha> TAB <file>
- -- All fields are fixed, so we can pull them out of
- -- specific positions in the line.
- (m, past_m) = splitAt 7 l
- (!t, past_t) = splitAt 4 past_m
- (!s, past_s) = splitAt shaSize $ Prelude.tail past_t
- !f = Prelude.tail past_s
+ (m, past_m) = splitAt 7 l -- mode is 6 bytes
+ (!t, past_t) = separate isSpace past_m
+ (!s, past_s) = splitAt shaSize past_t
+ !f = drop 1 past_s
!smode = fst $ Prelude.head $ readOct m
!sfile = asTopFilePath $ Git.Filename.decode f