summaryrefslogtreecommitdiff
path: root/Annex/AdjustedBranch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-02-29 17:16:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-02-29 17:16:56 -0400
commit186e00e2d677fa756b6f4ec042c1dfc8f005c364 (patch)
treea0a2f354ff85feb225efd1c82aee23877efcac4a /Annex/AdjustedBranch.hs
parentdfbc04a49807ab525f27f8cfe5b16ee9e4423c83 (diff)
implement updateAdjustedBranch
Diffstat (limited to 'Annex/AdjustedBranch.hs')
-rw-r--r--Annex/AdjustedBranch.hs53
1 files changed, 47 insertions, 6 deletions
diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs
index 8acaa0514..3ff8e9265 100644
--- a/Annex/AdjustedBranch.hs
+++ b/Annex/AdjustedBranch.hs
@@ -25,6 +25,7 @@ import Git.Env
import Annex.CatFile
import Annex.Link
import Git.HashObject
+import Annex.AutoMerge
data Adjustment = UnlockAdjustment
deriving (Show)
@@ -92,15 +93,19 @@ enterAdjustedBranch adj = go =<< originalBranch
adjustBranch :: Adjustment -> OrigBranch -> Annex AdjBranch
adjustBranch adj origbranch = do
- h <- inRepo hashObjectStart
- treesha <- adjustTree (adjustTreeItem adj h) origbranch =<< Annex.gitRepo
- liftIO $ hashObjectStop h
- commitsha <- commitAdjustedTree treesha origbranch
- inRepo $ Git.Branch.update adjbranch commitsha
+ sha <- adjust adj origbranch
+ inRepo $ Git.Branch.update adjbranch sha
return adjbranch
where
adjbranch = originalToAdjusted origbranch adj
+adjust :: Adjustment -> Ref -> Annex Sha
+adjust adj orig = do
+ h <- inRepo hashObjectStart
+ treesha <- adjustTree (adjustTreeItem adj h) orig =<< Annex.gitRepo
+ liftIO $ hashObjectStop h
+ commitAdjustedTree treesha orig
+
{- Commits a given adjusted tree, with the provided parent ref.
-
- This should always yield the same value, even if performed in different
@@ -122,4 +127,40 @@ commitAdjustedTree treesha parent = go =<< catCommit parent
- branch into it. -}
updateAdjustedBranch :: Branch -> (OrigBranch, Adjustment) -> Git.Branch.CommitMode -> Annex Bool
updateAdjustedBranch tomerge (origbranch, adj) commitmode = do
- error "updateAdjustedBranch"
+ liftIO $ print ("updateAdjustedBranch", tomerge)
+ go =<< (,)
+ <$> inRepo (Git.Ref.sha tomerge)
+ <*> inRepo Git.Branch.current
+ where
+ go (Just mergesha, Just currbranch) = ifM (inRepo $ Git.Branch.changed currbranch mergesha)
+ ( do
+ propigateAdjustedCommits origbranch adj
+ adjustedtomerge <- adjust adj mergesha
+ liftIO $ print ("mergesha", mergesha, "adjustedtomerge", adjustedtomerge)
+ ifM (inRepo $ Git.Branch.changed currbranch adjustedtomerge)
+ ( ifM (autoMergeFrom adjustedtomerge (Just currbranch) commitmode)
+ ( recommit currbranch mergesha =<< catCommit currbranch
+ , return False
+ )
+ , return True -- no changes to merge
+ )
+ , return True -- no changes to merge
+ )
+ go _ = return False
+ {- Once a merge commit has been made, re-do it, removing
+ - the old version of the adjusted branch as a parent, and
+ - making the only parent be the branch that was merged in.
+ -
+ - Doing this ensures that the same commit Sha is
+ - always arrived at for a given commit from the merged in branch.
+ -}
+ recommit currbranch parent (Just commit) = do
+ commitsha <- commitAdjustedTree (commitTree commit) parent
+ inRepo $ Git.Branch.update currbranch commitsha
+ return True
+ recommit _ _ Nothing = return False
+
+{- Check for any commits present on the adjusted branch that have not yet
+ - been propigated to the master branch, and propigate them. -}
+propigateAdjustedCommits :: OrigBranch -> Adjustment -> Annex ()
+propigateAdjustedCommits originbranch adj = return () -- TODO