Mercurial > public > mercurial-scm > hg-stable
comparison hgext/uncommit.py @ 38429:32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
We have had multiple bugs where the phase wasn't correctly carried
forward to a rewritten changeset (for example: phabricator, split,
evolve, fix). Handling the phase update in cleanupnodes() makes it
less likely to happen again, especially once we have made it fix the
phase by default (perhaps in the next release cycle).
This patch also updates all applicable callers so we get some testing
of it.
Note that rebase and histedit can't be fixed yet because they call
cleanupnodes() only at the end and the phase may have been changed by
the user when the rebase/histedit was interrupted (due to merge
conflicts). I think we should make them write one commit at a time (as
it already does), along with associated obsmarkers, bookmark moves,
etc. When that's done, we can switch them over to cleanupnodes().
Differential Revision: https://phab.mercurial-scm.org/D3818
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 19 Jun 2018 11:07:40 -0700 |
parents | 435b8b05affd |
children | 3bd22c4d3711 |
comparison
equal
deleted
inserted
replaced
38428:a6addfd64507 | 38429:32fba6fe893d |
---|---|
89 files=files, | 89 files=files, |
90 filectxfn=filectxfn, | 90 filectxfn=filectxfn, |
91 user=ctx.user(), | 91 user=ctx.user(), |
92 date=ctx.date(), | 92 date=ctx.date(), |
93 extra=ctx.extra()) | 93 extra=ctx.extra()) |
94 # phase handling | 94 return repo.commitctx(new) |
95 commitphase = ctx.phase() | |
96 overrides = {('phases', 'new-commit'): commitphase} | |
97 with repo.ui.configoverride(overrides, 'uncommit'): | |
98 newid = repo.commitctx(new) | |
99 return newid | |
100 | 95 |
101 def _fixdirstate(repo, oldctx, newctx, status): | 96 def _fixdirstate(repo, oldctx, newctx, status): |
102 """ fix the dirstate after switching the working directory from oldctx to | 97 """ fix the dirstate after switching the working directory from oldctx to |
103 newctx which can be result of either unamend or uncommit. | 98 newctx which can be result of either unamend or uncommit. |
104 """ | 99 """ |
181 mapping[old.node()] = (newid,) | 176 mapping[old.node()] = (newid,) |
182 else: | 177 else: |
183 # Fully removed the old commit | 178 # Fully removed the old commit |
184 mapping[old.node()] = () | 179 mapping[old.node()] = () |
185 | 180 |
186 scmutil.cleanupnodes(repo, mapping, 'uncommit') | 181 scmutil.cleanupnodes(repo, mapping, 'uncommit', fixphase=True) |
187 | 182 |
188 with repo.dirstate.parentchange(): | 183 with repo.dirstate.parentchange(): |
189 repo.dirstate.setparents(newid, node.nullid) | 184 repo.dirstate.setparents(newid, node.nullid) |
190 s = repo.status(old.p1(), old, match=match) | 185 s = repo.status(old.p1(), old, match=match) |
191 _fixdirstate(repo, old, repo[newid], s) | 186 _fixdirstate(repo, old, repo[newid], s) |
240 files=predctx.files(), | 235 files=predctx.files(), |
241 filectxfn=filectxfn, | 236 filectxfn=filectxfn, |
242 user=predctx.user(), | 237 user=predctx.user(), |
243 date=predctx.date(), | 238 date=predctx.date(), |
244 extra=extras) | 239 extra=extras) |
245 # phase handling | 240 newprednode = repo.commitctx(newctx) |
246 commitphase = curctx.phase() | |
247 overrides = {('phases', 'new-commit'): commitphase} | |
248 with repo.ui.configoverride(overrides, 'uncommit'): | |
249 newprednode = repo.commitctx(newctx) | |
250 | |
251 newpredctx = repo[newprednode] | 241 newpredctx = repo[newprednode] |
252 dirstate = repo.dirstate | 242 dirstate = repo.dirstate |
253 | 243 |
254 with dirstate.parentchange(): | 244 with dirstate.parentchange(): |
255 dirstate.setparents(newprednode, node.nullid) | 245 dirstate.setparents(newprednode, node.nullid) |
256 s = repo.status(predctx, curctx) | 246 s = repo.status(predctx, curctx) |
257 _fixdirstate(repo, curctx, newpredctx, s) | 247 _fixdirstate(repo, curctx, newpredctx, s) |
258 | 248 |
259 mapping = {curctx.node(): (newprednode,)} | 249 mapping = {curctx.node(): (newprednode,)} |
260 scmutil.cleanupnodes(repo, mapping, 'unamend') | 250 scmutil.cleanupnodes(repo, mapping, 'unamend', fixphase=True) |