Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 44211:fc7175df6359
graft: let caller pass in overlayworkingctx to merge.graft()
Passing in a different `wctx` than `repo[None]` is useful because it
allows the caller to decide to not touch the working directory.
Differential Revision: https://phab.mercurial-scm.org/D8026
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 10 Jan 2020 13:12:24 -0800 |
parents | fa9ad1da2e77 |
children | cb8b67016110 |
comparison
equal
deleted
inserted
replaced
44210:d0c3eead515a | 44211:fc7175df6359 |
---|---|
2588 ) | 2588 ) |
2589 return stats | 2589 return stats |
2590 | 2590 |
2591 | 2591 |
2592 def graft( | 2592 def graft( |
2593 repo, ctx, base, labels=None, keepparent=False, keepconflictparent=False | 2593 repo, |
2594 ctx, | |
2595 base, | |
2596 labels=None, | |
2597 keepparent=False, | |
2598 keepconflictparent=False, | |
2599 wctx=None, | |
2594 ): | 2600 ): |
2595 """Do a graft-like merge. | 2601 """Do a graft-like merge. |
2596 | 2602 |
2597 This is a merge where the merge ancestor is chosen such that one | 2603 This is a merge where the merge ancestor is chosen such that one |
2598 or more changesets are grafted onto the current changeset. In | 2604 or more changesets are grafted onto the current changeset. In |
2611 # mergeancestor=True to update. This does two things: 1) allows the merge if | 2617 # mergeancestor=True to update. This does two things: 1) allows the merge if |
2612 # the destination is the same as the parent of the ctx (so we can use graft | 2618 # the destination is the same as the parent of the ctx (so we can use graft |
2613 # to copy commits), and 2) informs update that the incoming changes are | 2619 # to copy commits), and 2) informs update that the incoming changes are |
2614 # newer than the destination so it doesn't prompt about "remote changed foo | 2620 # newer than the destination so it doesn't prompt about "remote changed foo |
2615 # which local deleted". | 2621 # which local deleted". |
2616 wctx = repo[None] | 2622 wctx = wctx or repo[None] |
2617 pctx = wctx.p1() | 2623 pctx = wctx.p1() |
2618 mergeancestor = repo.changelog.isancestor(pctx.node(), ctx.node()) | 2624 mergeancestor = repo.changelog.isancestor(pctx.node(), ctx.node()) |
2619 | 2625 |
2620 stats = update( | 2626 stats = update( |
2621 repo, | 2627 repo, |
2623 True, | 2629 True, |
2624 True, | 2630 True, |
2625 base.node(), | 2631 base.node(), |
2626 mergeancestor=mergeancestor, | 2632 mergeancestor=mergeancestor, |
2627 labels=labels, | 2633 labels=labels, |
2634 wc=wctx, | |
2628 ) | 2635 ) |
2629 | 2636 |
2630 if keepconflictparent and stats.unresolvedcount: | 2637 if keepconflictparent and stats.unresolvedcount: |
2631 pother = ctx.node() | 2638 pother = ctx.node() |
2632 else: | 2639 else: |
2637 pother = parents[0].node() | 2644 pother = parents[0].node() |
2638 # Never set both parents equal to each other | 2645 # Never set both parents equal to each other |
2639 if pother == pctx.node(): | 2646 if pother == pctx.node(): |
2640 pother = nullid | 2647 pother = nullid |
2641 | 2648 |
2642 with repo.dirstate.parentchange(): | 2649 if wctx.isinmemory(): |
2643 repo.setparents(pctx.node(), pother) | 2650 wctx.setparents(pctx.node(), pother) |
2644 repo.dirstate.write(repo.currenttransaction()) | |
2645 # fix up dirstate for copies and renames | 2651 # fix up dirstate for copies and renames |
2646 copies.graftcopies(wctx, ctx, base) | 2652 copies.graftcopies(wctx, ctx, base) |
2653 else: | |
2654 with repo.dirstate.parentchange(): | |
2655 repo.setparents(pctx.node(), pother) | |
2656 repo.dirstate.write(repo.currenttransaction()) | |
2657 # fix up dirstate for copies and renames | |
2658 copies.graftcopies(wctx, ctx, base) | |
2647 return stats | 2659 return stats |
2648 | 2660 |
2649 | 2661 |
2650 def purge( | 2662 def purge( |
2651 repo, | 2663 repo, |