# HG changeset patch # User Martin von Zweigbergk # Date 1579131025 28800 # Node ID f546d2170b0fedca9eeac331f11b34a7abc6e25b # Parent 48a1a974a92c273444c09e779bfb8d62ceb5a941 merge: introduce a clean_update() for that use-case I find it hard to understand what value to pass for all the arguments to `merge.update()`. I would like to introduce functions that are more specific to each use-case. We already have `graft()`. This patch introduces a `clean_update()` and uses it in some places to show that it works. Differential Revision: https://phab.mercurial-scm.org/D7902 diff -r 48a1a974a92c -r f546d2170b0f hgext/histedit.py --- a/hgext/histedit.py Wed Feb 05 16:16:15 2020 -0500 +++ b/hgext/histedit.py Wed Jan 15 15:30:25 2020 -0800 @@ -945,7 +945,7 @@ class base(histeditaction): def run(self): if self.repo[b'.'].node() != self.node: - mergemod.update(self.repo, self.node, branchmerge=False, force=True) + mergemod.clean_update(self.repo[self.node]) return self.continueclean() def continuedirty(self): diff -r 48a1a974a92c -r f546d2170b0f hgext/rebase.py --- a/hgext/rebase.py Wed Feb 05 16:16:15 2020 -0500 +++ b/hgext/rebase.py Wed Jan 15 15:30:25 2020 -0800 @@ -800,9 +800,7 @@ # Update away from the rebase if necessary if shouldupdate: - mergemod.update( - repo, self.originalwd, branchmerge=False, force=True - ) + mergemod.clean_update(repo[self.originalwd]) # Strip from the first rebased revision if rebased: @@ -1477,7 +1475,7 @@ else: if repo[b'.'].rev() != p1: repo.ui.debug(b" update to %d:%s\n" % (p1, p1ctx)) - mergemod.update(repo, p1, branchmerge=False, force=True) + mergemod.clean_update(p1ctx) else: repo.ui.debug(b" already in destination\n") # This is, alas, necessary to invalidate workingctx's manifest cache, diff -r 48a1a974a92c -r f546d2170b0f mercurial/hg.py --- a/mercurial/hg.py Wed Feb 05 16:16:15 2020 -0500 +++ b/mercurial/hg.py Wed Jan 15 15:30:25 2020 -0800 @@ -1173,7 +1173,7 @@ node = repo[b'.'].hex() repo.ui.status(_(b"aborting the merge, updating back to %s\n") % node[:12]) - stats = mergemod.update(repo, node, branchmerge=False, force=True) + stats = mergemod.clean_update(repo[node]) assert stats.unresolvedcount == 0 _showstats(repo, stats) diff -r 48a1a974a92c -r f546d2170b0f mercurial/merge.py --- a/mercurial/merge.py Wed Feb 05 16:16:15 2020 -0500 +++ b/mercurial/merge.py Wed Jan 15 15:30:25 2020 -0800 @@ -2597,6 +2597,15 @@ return stats +def clean_update(ctx, wc=None): + """Do a clean update to the given commit. + + This involves updating to the commit and discarding any changes in the + working copy. + """ + return update(ctx.repo(), ctx.rev(), branchmerge=False, force=True, wc=wc) + + def graft( repo, ctx, diff -r 48a1a974a92c -r f546d2170b0f mercurial/shelve.py --- a/mercurial/shelve.py Wed Feb 05 16:16:15 2020 -0500 +++ b/mercurial/shelve.py Wed Jan 15 15:30:25 2020 -0800 @@ -745,7 +745,7 @@ try: checkparents(repo, state) - merge.update(repo, state.pendingctx, branchmerge=False, force=True) + merge.clean_update(state.pendingctx) if state.activebookmark and state.activebookmark in repo._bookmarks: bookmarks.activate(repo, state.activebookmark) mergefiles(ui, repo, state.wctx, state.pendingctx)