2016-03-11 20:00:14 +00:00
|
|
|
{- adjusted branch
|
2016-02-25 20:11:13 +00:00
|
|
|
-
|
|
|
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2016-02-29 19:04:03 +00:00
|
|
|
module Annex.AdjustedBranch (
|
|
|
|
Adjustment(..),
|
|
|
|
OrigBranch,
|
|
|
|
AdjBranch,
|
2016-03-03 20:19:09 +00:00
|
|
|
originalToAdjusted,
|
2016-02-29 19:04:03 +00:00
|
|
|
adjustedToOriginal,
|
2016-03-03 18:13:54 +00:00
|
|
|
fromAdjustedBranch,
|
2016-03-29 17:26:06 +00:00
|
|
|
getAdjustment,
|
2016-02-29 19:04:03 +00:00
|
|
|
enterAdjustedBranch,
|
2016-03-29 17:52:13 +00:00
|
|
|
adjustToCrippledFileSystem,
|
2016-02-29 19:04:03 +00:00
|
|
|
updateAdjustedBranch,
|
2016-03-03 18:13:54 +00:00
|
|
|
propigateAdjustedCommits,
|
2016-02-29 19:04:03 +00:00
|
|
|
) where
|
2016-02-25 20:11:13 +00:00
|
|
|
|
|
|
|
import Annex.Common
|
|
|
|
import qualified Annex
|
2016-03-03 20:19:09 +00:00
|
|
|
import Git
|
2016-02-25 20:11:13 +00:00
|
|
|
import Git.Types
|
|
|
|
import qualified Git.Branch
|
|
|
|
import qualified Git.Ref
|
|
|
|
import qualified Git.Command
|
2016-03-03 20:19:09 +00:00
|
|
|
import qualified Git.Tree
|
2016-03-11 20:00:14 +00:00
|
|
|
import qualified Git.DiffTree
|
2016-03-03 20:19:09 +00:00
|
|
|
import Git.Tree (TreeItem(..))
|
2016-03-11 20:00:14 +00:00
|
|
|
import Git.Sha
|
2016-02-25 20:11:13 +00:00
|
|
|
import Git.Env
|
2016-03-03 16:55:00 +00:00
|
|
|
import Git.Index
|
2016-03-03 20:19:09 +00:00
|
|
|
import Git.FilePath
|
2016-03-03 16:55:00 +00:00
|
|
|
import qualified Git.LockFile
|
2016-02-25 20:11:13 +00:00
|
|
|
import Annex.CatFile
|
|
|
|
import Annex.Link
|
2016-02-29 21:16:56 +00:00
|
|
|
import Annex.AutoMerge
|
2016-03-11 23:53:18 +00:00
|
|
|
import Annex.Content
|
2016-02-29 21:27:19 +00:00
|
|
|
import qualified Database.Keys
|
2016-02-25 20:11:13 +00:00
|
|
|
|
2016-03-11 20:00:14 +00:00
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2016-03-11 23:41:11 +00:00
|
|
|
data Adjustment
|
2016-03-11 23:53:18 +00:00
|
|
|
= UnlockAdjustment
|
2016-03-11 23:41:11 +00:00
|
|
|
| LockAdjustment
|
2016-03-11 23:53:18 +00:00
|
|
|
| HideMissingAdjustment
|
|
|
|
| ShowMissingAdjustment
|
2016-03-29 17:26:06 +00:00
|
|
|
deriving (Show, Eq)
|
2016-02-25 20:11:13 +00:00
|
|
|
|
2016-03-11 23:41:11 +00:00
|
|
|
reverseAdjustment :: Adjustment -> Adjustment
|
|
|
|
reverseAdjustment UnlockAdjustment = LockAdjustment
|
|
|
|
reverseAdjustment LockAdjustment = UnlockAdjustment
|
2016-03-11 23:53:18 +00:00
|
|
|
reverseAdjustment HideMissingAdjustment = ShowMissingAdjustment
|
|
|
|
reverseAdjustment ShowMissingAdjustment = HideMissingAdjustment
|
2016-03-03 20:19:09 +00:00
|
|
|
|
2016-03-11 20:00:14 +00:00
|
|
|
{- How to perform various adjustments to a TreeItem. -}
|
2016-03-29 15:15:21 +00:00
|
|
|
adjustTreeItem :: Adjustment -> TreeItem -> Annex (Maybe TreeItem)
|
|
|
|
adjustTreeItem UnlockAdjustment ti@(TreeItem f m s)
|
2016-02-25 20:11:13 +00:00
|
|
|
| toBlobType m == Just SymlinkBlob = do
|
|
|
|
mk <- catKey s
|
|
|
|
case mk of
|
2016-02-29 21:27:19 +00:00
|
|
|
Just k -> do
|
|
|
|
Database.Keys.addAssociatedFile k f
|
|
|
|
Just . TreeItem f (fromBlobType FileBlob)
|
2016-03-29 15:15:21 +00:00
|
|
|
<$> hashPointerFile k
|
2016-02-25 20:11:13 +00:00
|
|
|
Nothing -> return (Just ti)
|
|
|
|
| otherwise = return (Just ti)
|
2016-03-29 15:15:21 +00:00
|
|
|
adjustTreeItem LockAdjustment ti@(TreeItem f m s)
|
2016-03-03 20:19:09 +00:00
|
|
|
| toBlobType m /= Just SymlinkBlob = do
|
|
|
|
mk <- catKey s
|
|
|
|
case mk of
|
|
|
|
Just k -> do
|
|
|
|
absf <- inRepo $ \r -> absPath $
|
2016-03-03 20:47:51 +00:00
|
|
|
fromTopFilePath f r
|
2016-03-03 20:19:09 +00:00
|
|
|
linktarget <- calcRepo $ gitAnnexLink absf k
|
|
|
|
Just . TreeItem f (fromBlobType SymlinkBlob)
|
2016-03-29 15:15:21 +00:00
|
|
|
<$> hashSymlink linktarget
|
2016-03-03 20:19:09 +00:00
|
|
|
Nothing -> return (Just ti)
|
|
|
|
| otherwise = return (Just ti)
|
2016-03-29 15:15:21 +00:00
|
|
|
adjustTreeItem HideMissingAdjustment ti@(TreeItem _ _ s) = do
|
2016-03-11 23:53:18 +00:00
|
|
|
mk <- catKey s
|
|
|
|
case mk of
|
|
|
|
Just k -> ifM (inAnnex k)
|
|
|
|
( return (Just ti)
|
|
|
|
, return Nothing
|
|
|
|
)
|
|
|
|
Nothing -> return (Just ti)
|
2016-03-29 15:15:21 +00:00
|
|
|
adjustTreeItem ShowMissingAdjustment ti = return (Just ti)
|
2016-02-25 20:11:13 +00:00
|
|
|
|
|
|
|
type OrigBranch = Branch
|
|
|
|
type AdjBranch = Branch
|
|
|
|
|
|
|
|
adjustedBranchPrefix :: String
|
|
|
|
adjustedBranchPrefix = "refs/heads/adjusted/"
|
|
|
|
|
2016-02-29 19:04:03 +00:00
|
|
|
serialize :: Adjustment -> String
|
2016-03-03 20:38:56 +00:00
|
|
|
serialize UnlockAdjustment = "unlocked"
|
2016-03-11 23:41:11 +00:00
|
|
|
serialize LockAdjustment = "locked"
|
2016-03-11 23:53:18 +00:00
|
|
|
serialize HideMissingAdjustment = "present"
|
|
|
|
serialize ShowMissingAdjustment = "showmissing"
|
2016-02-25 20:11:13 +00:00
|
|
|
|
2016-02-29 19:04:03 +00:00
|
|
|
deserialize :: String -> Maybe Adjustment
|
2016-03-03 20:38:56 +00:00
|
|
|
deserialize "unlocked" = Just UnlockAdjustment
|
2016-03-11 23:41:11 +00:00
|
|
|
deserialize "locked" = Just UnlockAdjustment
|
2016-03-11 23:53:18 +00:00
|
|
|
deserialize "present" = Just HideMissingAdjustment
|
2016-02-29 19:04:03 +00:00
|
|
|
deserialize _ = Nothing
|
|
|
|
|
|
|
|
originalToAdjusted :: OrigBranch -> Adjustment -> AdjBranch
|
2016-03-03 20:38:56 +00:00
|
|
|
originalToAdjusted orig adj = Ref $
|
|
|
|
adjustedBranchPrefix ++ base ++ '(' : serialize adj ++ ")"
|
2016-02-29 19:04:03 +00:00
|
|
|
where
|
2016-03-03 20:38:56 +00:00
|
|
|
base = fromRef (Git.Ref.basename orig)
|
2016-02-29 19:04:03 +00:00
|
|
|
|
|
|
|
adjustedToOriginal :: AdjBranch -> Maybe (Adjustment, OrigBranch)
|
2016-02-25 20:11:13 +00:00
|
|
|
adjustedToOriginal b
|
2016-02-29 19:04:03 +00:00
|
|
|
| adjustedBranchPrefix `isPrefixOf` bs = do
|
2016-03-03 20:38:56 +00:00
|
|
|
let (base, as) = separate (== '(') (drop prefixlen bs)
|
|
|
|
adj <- deserialize (takeWhile (/= ')') as)
|
|
|
|
Just (adj, Git.Ref.under "refs/heads" (Ref base))
|
2016-02-25 20:11:13 +00:00
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
|
|
|
bs = fromRef b
|
|
|
|
prefixlen = length adjustedBranchPrefix
|
|
|
|
|
2016-03-29 17:26:06 +00:00
|
|
|
getAdjustment :: Branch -> Maybe Adjustment
|
|
|
|
getAdjustment = fmap fst . adjustedToOriginal
|
|
|
|
|
2016-03-03 18:13:54 +00:00
|
|
|
fromAdjustedBranch :: Branch -> OrigBranch
|
|
|
|
fromAdjustedBranch b = maybe b snd (adjustedToOriginal b)
|
|
|
|
|
2016-02-25 20:11:13 +00:00
|
|
|
originalBranch :: Annex (Maybe OrigBranch)
|
2016-03-03 18:13:54 +00:00
|
|
|
originalBranch = fmap fromAdjustedBranch <$> inRepo Git.Branch.current
|
2016-02-25 20:11:13 +00:00
|
|
|
|
|
|
|
{- Enter an adjusted version of current branch (or, if already in an
|
|
|
|
- adjusted version of a branch, changes the adjustment of the original
|
|
|
|
- branch).
|
|
|
|
-
|
|
|
|
- Can fail, if no branch is checked out, or perhaps if staged changes
|
|
|
|
- conflict with the adjusted branch.
|
|
|
|
-}
|
|
|
|
enterAdjustedBranch :: Adjustment -> Annex ()
|
|
|
|
enterAdjustedBranch adj = go =<< originalBranch
|
|
|
|
where
|
2016-03-03 18:17:37 +00:00
|
|
|
go (Just origbranch) = do
|
2016-03-11 20:00:14 +00:00
|
|
|
adjbranch <- preventCommits $ const $
|
2016-03-11 23:41:11 +00:00
|
|
|
adjustBranch adj origbranch
|
2016-02-25 20:11:13 +00:00
|
|
|
inRepo $ Git.Command.run
|
|
|
|
[ Param "checkout"
|
|
|
|
, Param $ fromRef $ Git.Ref.base $ adjbranch
|
|
|
|
]
|
|
|
|
go Nothing = error "not on any branch!"
|
|
|
|
|
2016-03-29 17:52:13 +00:00
|
|
|
adjustToCrippledFileSystem :: Annex ()
|
|
|
|
adjustToCrippledFileSystem = do
|
|
|
|
warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files."
|
|
|
|
whenM (isNothing <$> originalBranch) $
|
|
|
|
void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit
|
|
|
|
[ Param "--quiet"
|
|
|
|
, Param "--allow-empty"
|
|
|
|
, Param "-m"
|
|
|
|
, Param "commit before entering adjusted unlocked branch"
|
|
|
|
]
|
|
|
|
enterAdjustedBranch UnlockAdjustment
|
|
|
|
|
2016-03-11 23:41:11 +00:00
|
|
|
adjustBranch :: Adjustment -> OrigBranch -> Annex AdjBranch
|
|
|
|
adjustBranch adj origbranch = do
|
|
|
|
sha <- adjust adj origbranch
|
2016-03-31 16:27:48 +00:00
|
|
|
inRepo $ Git.Branch.update "entering adjusted branch" adjbranch sha
|
2016-02-25 20:11:13 +00:00
|
|
|
return adjbranch
|
|
|
|
where
|
2016-02-29 19:04:03 +00:00
|
|
|
adjbranch = originalToAdjusted origbranch adj
|
2016-02-25 20:11:13 +00:00
|
|
|
|
2016-03-11 23:41:11 +00:00
|
|
|
adjust :: Adjustment -> Ref -> Annex Sha
|
|
|
|
adjust adj orig = do
|
|
|
|
treesha <- adjustTree adj orig
|
2016-03-03 20:19:09 +00:00
|
|
|
commitAdjustedTree treesha orig
|
|
|
|
|
2016-03-11 23:41:11 +00:00
|
|
|
adjustTree :: Adjustment -> Ref -> Annex Sha
|
|
|
|
adjustTree adj orig = do
|
2016-03-29 15:15:21 +00:00
|
|
|
let toadj = adjustTreeItem adj
|
2016-03-11 20:30:06 +00:00
|
|
|
treesha <- Git.Tree.adjustTree toadj [] [] orig =<< Annex.gitRepo
|
2016-03-03 20:19:09 +00:00
|
|
|
return treesha
|
2016-02-29 21:16:56 +00:00
|
|
|
|
2016-03-11 20:00:14 +00:00
|
|
|
type CommitsPrevented = Git.LockFile.LockHandle
|
|
|
|
|
2016-03-03 16:55:00 +00:00
|
|
|
{- Locks git's index file, preventing git from making a commit, merge,
|
|
|
|
- or otherwise changing the HEAD ref while the action is run.
|
|
|
|
-
|
|
|
|
- Throws an IO exception if the index file is already locked.
|
|
|
|
-}
|
2016-03-11 20:00:14 +00:00
|
|
|
preventCommits :: (CommitsPrevented -> Annex a) -> Annex a
|
|
|
|
preventCommits = bracket setup cleanup
|
2016-03-03 16:55:00 +00:00
|
|
|
where
|
|
|
|
setup = do
|
|
|
|
lck <- fromRepo indexFileLock
|
|
|
|
liftIO $ Git.LockFile.openLock lck
|
2016-03-11 20:00:14 +00:00
|
|
|
cleanup = liftIO . Git.LockFile.closeLock
|
2016-03-03 16:55:00 +00:00
|
|
|
|
2016-02-25 20:11:13 +00:00
|
|
|
{- Commits a given adjusted tree, with the provided parent ref.
|
|
|
|
-
|
|
|
|
- This should always yield the same value, even if performed in different
|
|
|
|
- clones of a repo, at different times. The commit message and other
|
|
|
|
- metadata is based on the parent.
|
|
|
|
-}
|
|
|
|
commitAdjustedTree :: Sha -> Ref -> Annex Sha
|
|
|
|
commitAdjustedTree treesha parent = go =<< catCommit parent
|
|
|
|
where
|
|
|
|
go Nothing = inRepo mkcommit
|
|
|
|
go (Just parentcommit) = inRepo $ commitWithMetaData
|
|
|
|
(commitAuthorMetaData parentcommit)
|
|
|
|
(commitCommitterMetaData parentcommit)
|
|
|
|
mkcommit
|
2016-03-03 20:19:09 +00:00
|
|
|
mkcommit = Git.Branch.commitTree Git.Branch.AutomaticCommit
|
|
|
|
adjustedBranchCommitMessage [parent] treesha
|
|
|
|
|
|
|
|
adjustedBranchCommitMessage :: String
|
|
|
|
adjustedBranchCommitMessage = "git-annex adjusted branch"
|
2016-02-29 19:04:03 +00:00
|
|
|
|
|
|
|
{- Update the currently checked out adjusted branch, merging the provided
|
|
|
|
- branch into it. -}
|
2016-02-29 19:57:47 +00:00
|
|
|
updateAdjustedBranch :: Branch -> (OrigBranch, Adjustment) -> Git.Branch.CommitMode -> Annex Bool
|
2016-03-31 16:04:05 +00:00
|
|
|
updateAdjustedBranch tomerge (origbranch, adj) commitmode = catchBoolIO $
|
|
|
|
join $ preventCommits $ \commitsprevented -> go commitsprevented =<< (,)
|
2016-02-29 21:16:56 +00:00
|
|
|
<$> inRepo (Git.Ref.sha tomerge)
|
|
|
|
<*> inRepo Git.Branch.current
|
|
|
|
where
|
2016-03-11 20:00:14 +00:00
|
|
|
go commitsprevented (Just mergesha, Just currbranch) =
|
|
|
|
ifM (inRepo $ Git.Branch.changed currbranch mergesha)
|
|
|
|
( do
|
|
|
|
propigateAdjustedCommits' origbranch (adj, currbranch) commitsprevented
|
2016-03-11 23:41:11 +00:00
|
|
|
adjustedtomerge <- adjust adj mergesha
|
2016-03-11 20:00:14 +00:00
|
|
|
ifM (inRepo $ Git.Branch.changed currbranch adjustedtomerge)
|
2016-03-31 16:04:05 +00:00
|
|
|
( return $ do
|
|
|
|
-- Run after commit lock is dropped.
|
2016-03-11 20:00:14 +00:00
|
|
|
ifM (autoMergeFrom adjustedtomerge (Just currbranch) commitmode)
|
|
|
|
( preventCommits $ \commitsprevented' ->
|
|
|
|
recommit commitsprevented' currbranch mergesha =<< catCommit currbranch
|
|
|
|
, return False
|
|
|
|
)
|
2016-03-31 16:04:05 +00:00
|
|
|
, nochangestomerge
|
2016-02-29 21:16:56 +00:00
|
|
|
)
|
2016-03-31 16:04:05 +00:00
|
|
|
, nochangestomerge
|
2016-03-11 20:00:14 +00:00
|
|
|
)
|
2016-03-31 16:04:05 +00:00
|
|
|
go _ _ = return $ return False
|
|
|
|
nochangestomerge = return $ return True
|
2016-02-29 21:16:56 +00:00
|
|
|
{- 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.
|
|
|
|
-}
|
2016-03-11 20:00:14 +00:00
|
|
|
recommit commitsprevented currbranch parent (Just commit) = do
|
2016-02-29 21:16:56 +00:00
|
|
|
commitsha <- commitAdjustedTree (commitTree commit) parent
|
2016-03-31 16:27:48 +00:00
|
|
|
inRepo $ Git.Branch.update "merging into adjusted branch" currbranch commitsha
|
2016-03-11 20:00:14 +00:00
|
|
|
propigateAdjustedCommits' origbranch (adj, currbranch) commitsprevented
|
2016-02-29 21:16:56 +00:00
|
|
|
return True
|
2016-03-11 20:00:14 +00:00
|
|
|
recommit _ _ _ Nothing = return False
|
2016-02-29 21:16:56 +00:00
|
|
|
|
|
|
|
{- Check for any commits present on the adjusted branch that have not yet
|
2016-03-03 20:19:09 +00:00
|
|
|
- been propigated to the orig branch, and propigate them.
|
|
|
|
-
|
|
|
|
- After propigating the commits back to the orig banch,
|
|
|
|
- rebase the adjusted branch on top of the updated orig branch.
|
|
|
|
-}
|
|
|
|
propigateAdjustedCommits :: OrigBranch -> (Adjustment, AdjBranch) -> Annex ()
|
2016-03-11 20:00:14 +00:00
|
|
|
propigateAdjustedCommits origbranch (adj, currbranch) =
|
|
|
|
preventCommits $ propigateAdjustedCommits' origbranch (adj, currbranch)
|
|
|
|
|
|
|
|
propigateAdjustedCommits' :: OrigBranch -> (Adjustment, AdjBranch) -> CommitsPrevented -> Annex ()
|
|
|
|
propigateAdjustedCommits' origbranch (adj, currbranch) _commitsprevented = do
|
2016-03-03 21:00:48 +00:00
|
|
|
ov <- inRepo $ Git.Ref.sha (Git.Ref.under "refs/heads" origbranch)
|
|
|
|
case ov of
|
2016-03-11 20:00:14 +00:00
|
|
|
Just origsha -> do
|
2016-03-03 21:00:48 +00:00
|
|
|
cv <- catCommit currbranch
|
|
|
|
case cv of
|
2016-03-11 20:00:14 +00:00
|
|
|
Just currcommit -> do
|
2016-03-29 15:15:21 +00:00
|
|
|
v <- newcommits >>= go origsha False
|
2016-03-11 20:00:14 +00:00
|
|
|
case v of
|
|
|
|
Left e -> do
|
|
|
|
warning e
|
|
|
|
return ()
|
|
|
|
Right newparent ->
|
|
|
|
rebase currcommit newparent
|
2016-03-03 21:00:48 +00:00
|
|
|
Nothing -> return ()
|
2016-03-03 20:19:09 +00:00
|
|
|
Nothing -> return ()
|
|
|
|
where
|
|
|
|
newcommits = inRepo $ Git.Branch.changedCommits origbranch currbranch
|
|
|
|
-- Get commits oldest first, so they can be processed
|
|
|
|
-- in order made.
|
|
|
|
[Param "--reverse"]
|
2016-03-29 15:15:21 +00:00
|
|
|
go parent _ [] = do
|
2016-03-31 16:27:48 +00:00
|
|
|
inRepo $ Git.Branch.update "updating adjusted branch" origbranch parent
|
2016-03-11 20:00:14 +00:00
|
|
|
return (Right parent)
|
2016-03-29 15:15:21 +00:00
|
|
|
go parent pastadjcommit (sha:l) = do
|
2016-03-03 20:19:09 +00:00
|
|
|
mc <- catCommit sha
|
|
|
|
case mc of
|
|
|
|
Just c
|
|
|
|
| commitMessage c == adjustedBranchCommitMessage ->
|
2016-03-29 15:15:21 +00:00
|
|
|
go parent True l
|
2016-03-03 20:19:09 +00:00
|
|
|
| pastadjcommit -> do
|
2016-03-29 15:15:21 +00:00
|
|
|
v <- reverseAdjustedCommit parent adj (sha, c) origbranch
|
2016-03-11 20:00:14 +00:00
|
|
|
case v of
|
|
|
|
Left e -> return (Left e)
|
2016-03-29 15:15:21 +00:00
|
|
|
Right commit -> go commit pastadjcommit l
|
|
|
|
_ -> go parent pastadjcommit l
|
2016-03-03 21:00:48 +00:00
|
|
|
rebase currcommit newparent = do
|
|
|
|
-- Reuse the current adjusted tree,
|
|
|
|
-- and reparent it on top of the new
|
|
|
|
-- version of the origbranch.
|
|
|
|
commitAdjustedTree (commitTree currcommit) newparent
|
2016-03-31 16:27:48 +00:00
|
|
|
>>= inRepo . Git.Branch.update "rebasing adjusted branch on top of updated original branch" currbranch
|
2016-03-03 20:19:09 +00:00
|
|
|
|
2016-03-11 20:00:14 +00:00
|
|
|
{- Reverses an adjusted commit, and commit on top of the provided newparent,
|
|
|
|
- yielding a commit sha.
|
|
|
|
-
|
|
|
|
- Adjust the tree of the newparent, changing only the files that the
|
|
|
|
- commit changed, and reverse adjusting those changes.
|
2016-03-03 20:19:09 +00:00
|
|
|
-
|
|
|
|
- Note that the commit message, and the author and committer metadata are
|
|
|
|
- copied over. However, any gpg signature will be lost, and any other
|
|
|
|
- headers are not copied either. -}
|
2016-03-29 15:15:21 +00:00
|
|
|
reverseAdjustedCommit :: Sha -> Adjustment -> (Sha, Commit) -> OrigBranch -> Annex (Either String Sha)
|
|
|
|
reverseAdjustedCommit newparent adj (csha, c) origbranch
|
2016-03-11 20:00:14 +00:00
|
|
|
-- commitDiff does not support merge commits
|
|
|
|
| length (commitParent c) > 1 = return $
|
|
|
|
Left $ "unable to propigate merge commit " ++ show csha ++ " back to " ++ show origbranch
|
|
|
|
| otherwise = do
|
|
|
|
(diff, cleanup) <- inRepo (Git.DiffTree.commitDiff csha)
|
2016-03-11 20:30:06 +00:00
|
|
|
let (adds, others) = partition (\dti -> Git.DiffTree.srcsha dti == nullSha) diff
|
|
|
|
let (removes, changes) = partition (\dti -> Git.DiffTree.dstsha dti == nullSha) others
|
2016-03-11 20:00:14 +00:00
|
|
|
adds' <- catMaybes <$>
|
2016-03-29 15:15:21 +00:00
|
|
|
mapM (adjustTreeItem reverseadj) (map diffTreeToTreeItem adds)
|
2016-03-11 20:30:06 +00:00
|
|
|
treesha <- Git.Tree.adjustTree
|
|
|
|
(propchanges changes)
|
|
|
|
adds'
|
|
|
|
(map Git.DiffTree.file removes)
|
|
|
|
newparent
|
2016-03-11 20:00:14 +00:00
|
|
|
=<< Annex.gitRepo
|
|
|
|
void $ liftIO cleanup
|
|
|
|
revadjcommit <- inRepo $ commitWithMetaData
|
|
|
|
(commitAuthorMetaData c)
|
|
|
|
(commitCommitterMetaData c) $
|
|
|
|
Git.Branch.commitTree Git.Branch.AutomaticCommit
|
|
|
|
(commitMessage c) [newparent] treesha
|
|
|
|
return (Right revadjcommit)
|
|
|
|
where
|
2016-03-11 23:41:11 +00:00
|
|
|
reverseadj = reverseAdjustment adj
|
2016-03-11 20:00:14 +00:00
|
|
|
propchanges changes ti@(TreeItem f _ _) =
|
|
|
|
case M.lookup f m of
|
|
|
|
Nothing -> return (Just ti) -- not changed
|
2016-03-29 15:15:21 +00:00
|
|
|
Just change -> adjustTreeItem reverseadj change
|
2016-03-11 20:00:14 +00:00
|
|
|
where
|
|
|
|
m = M.fromList $ map (\i@(TreeItem f' _ _) -> (f', i)) $
|
|
|
|
map diffTreeToTreeItem changes
|
|
|
|
|
|
|
|
diffTreeToTreeItem :: Git.DiffTree.DiffTreeItem -> TreeItem
|
|
|
|
diffTreeToTreeItem dti = TreeItem
|
|
|
|
(Git.DiffTree.file dti)
|
|
|
|
(Git.DiffTree.dstmode dti)
|
|
|
|
(Git.DiffTree.dstsha dti)
|