Mercurial > hg
changeset 44271:c791ed6a2154
merge: introduce a revert_to() for that use-case
In the same vein as the previous patch.
Differential Revision: https://phab.mercurial-scm.org/D7901
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 15 Jan 2020 14:47:38 -0800 |
parents | f546d2170b0f |
children | 06de4a673f48 |
files | hgext/fix.py mercurial/cmdutil.py mercurial/merge.py |
diffstat | 3 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/fix.py Wed Jan 15 15:30:25 2020 -0800 +++ b/hgext/fix.py Wed Jan 15 14:47:38 2020 -0800 @@ -735,15 +735,7 @@ wctx = context.overlayworkingctx(repo) wctx.setbase(repo[newp1node]) - merge.update( - repo, - ctx.rev(), - branchmerge=False, - force=True, - ancestor=p1rev, - mergeancestor=False, - wc=wctx, - ) + merge.revert_to(ctx, wc=wctx) copies.graftcopies(wctx, ctx, ctx.p1()) for path in filedata.keys():
--- a/mercurial/cmdutil.py Wed Jan 15 15:30:25 2020 -0800 +++ b/mercurial/cmdutil.py Wed Jan 15 14:47:38 2020 -0800 @@ -584,15 +584,8 @@ [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] # 3a. apply filtered patch to clean repo (clean) if backups: - # Equivalent to hg.revert m = scmutil.matchfiles(repo, set(backups.keys()) | alsorestore) - mergemod.update( - repo, - repo.dirstate.p1(), - branchmerge=False, - force=True, - matcher=m, - ) + mergemod.revert_to(repo[b'.'], matcher=m) # 3b. (apply) if dopatch:
--- a/mercurial/merge.py Wed Jan 15 15:30:25 2020 -0800 +++ b/mercurial/merge.py Wed Jan 15 14:47:38 2020 -0800 @@ -2225,6 +2225,7 @@ labels=None, matcher=None, mergeforce=False, + updatedirstate=True, updatecheck=None, wc=None, ): @@ -2523,7 +2524,7 @@ # If we're doing a partial update, we need to skip updating # the dirstate. always = matcher is None or matcher.always() - updatedirstate = always and not wc.isinmemory() + updatedirstate = updatedirstate and always and not wc.isinmemory() if updatedirstate: repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2) # note that we're in the middle of an update @@ -2606,6 +2607,24 @@ return update(ctx.repo(), ctx.rev(), branchmerge=False, force=True, wc=wc) +def revert_to(ctx, matcher=None, wc=None): + """Revert the working copy to the given commit. + + The working copy will keep its current parent(s) but its content will + be the same as in the given commit. + """ + + return update( + ctx.repo(), + ctx.rev(), + branchmerge=False, + force=True, + updatedirstate=False, + matcher=matcher, + wc=wc, + ) + + def graft( repo, ctx,