summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-02-23 21:56:03 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-02-23 21:56:08 -0400
commit33e442ce1f5ce4df677674dbcd272125a8405803 (patch)
tree9704c13a11e6e1bd404ff36ef50b2a003223e6d6
parent6229edf7d420c6a9c0f2a3f7d32eba03caad1afc (diff)
refactor
-rw-r--r--Git/Tree.hs40
1 files changed, 26 insertions, 14 deletions
diff --git a/Git/Tree.hs b/Git/Tree.hs
index 5e05ad9a0..fd059fd7c 100644
--- a/Git/Tree.hs
+++ b/Git/Tree.hs
@@ -118,53 +118,65 @@ adjustTree :: MonadIO m => (TreeItem -> m (Maybe TreeItem)) -> Ref -> Repo -> m
adjustTree adjust r repo = do
(l, cleanup) <- liftIO $ lsTreeWithObjects r repo
h <- liftIO $ startRecordTree repo
- (l', _, _) <- go h False [] "" l
- sha <- liftIO $ recordTree (Tree l') repo
+ (l', _, _) <- go h False [] topTree l
+ liftIO $ print l'
+ sha <- liftIO $ mkTree h l'
+ liftIO $ CoProcess.stop h
void $ liftIO cleanup
return sha
where
go _ wasmodified c _ [] = return (c, wasmodified, [])
- go h wasmodified c prefix (i:is)
- | prefix `isPrefixOf` getTopFilePath (LsTree.file i) =
+ go h wasmodified c intree (i:is)
+ | intree i =
case readObjectType (LsTree.typeobj i) of
Just BlobObject -> do
let ti = TreeItem (LsTree.file i) (LsTree.mode i) (LsTree.sha i)
v <- adjust ti
case v of
- Nothing -> go h True c prefix is
+ Nothing -> go h True c intree is
Just ti'@(TreeItem f m s) ->
let modified = ti' /= ti
blob = TreeBlob f m s
- in go h (wasmodified || modified) (blob:c) prefix is
+ in go h (wasmodified || modified) (blob:c) intree is
Just TreeObject -> do
- (sl, modified, is') <- go h False [] (getTopFilePath (LsTree.file i) ++ "/") is
+ (sl, modified, is') <- go h False [] (subTree i) is
subtree <- if modified
then liftIO $ recordSubTree h $ NewSubTree (LsTree.file i) sl
else return $ RecordedSubTree (LsTree.file i) (LsTree.sha i) []
- go h (modified || wasmodified) (subtree : c) prefix is'
+ go h (modified || wasmodified) (subtree : c) intree is'
_ -> error ("unexpected object type \"" ++ LsTree.typeobj i ++ "\"")
| otherwise = return (c, wasmodified, i:is)
{- Assumes the list is ordered, with tree objects coming right before their
- contents. -}
extractTree :: [LsTree.TreeItem] -> Either String Tree
-extractTree l = case go [] "" l of
+extractTree l = case go [] topTree l of
Right (t, []) -> Right (Tree t)
Right _ -> parseerr "unexpected tree form"
Left e -> parseerr e
where
go t _ [] = Right (t, [])
- go t prefix (i:is)
- | prefix `isPrefixOf` getTopFilePath (LsTree.file i) =
+ go t intree (i:is)
+ | intree i =
case readObjectType (LsTree.typeobj i) of
Just BlobObject ->
let b = TreeBlob (LsTree.file i) (LsTree.mode i) (LsTree.sha i)
- in go (b:t) prefix is
- Just TreeObject -> case go [] (getTopFilePath (LsTree.file i) ++ "/") is of
+ in go (b:t) intree is
+ Just TreeObject -> case go [] (subTree i) is of
Right (subtree, is') ->
let st = RecordedSubTree (LsTree.file i) (LsTree.sha i) subtree
- in go (st:t) prefix is'
+ in go (st:t) intree is'
Left e -> Left e
_ -> parseerr ("unexpected object type \"" ++ LsTree.typeobj i ++ "\"")
| otherwise = Right (t, i:is)
parseerr = Left
+
+type InTree = LsTree.TreeItem -> Bool
+
+topTree :: InTree
+topTree = notElem '/' . getTopFilePath . LsTree.file
+
+subTree :: LsTree.TreeItem -> InTree
+subTree i =
+ let prefix = getTopFilePath (LsTree.file i) ++ "/"
+ in (\i -> prefix `isPrefixOf` getTopFilePath (LsTree.file i))