##// END OF EJS Templates
scmutil: make cleanupnodes optionally also fix the phase...
Martin von Zweigbergk -
r38442:32fba6fe default
parent child Browse files
Show More
@@ -580,9 +580,7 def phabsend(ui, repo, *revs, **opts):
580 repo, old, parents=parents, text=newdesc,
580 repo, old, parents=parents, text=newdesc,
581 user=old.user(), date=old.date(), extra=old.extra())
581 user=old.user(), date=old.date(), extra=old.extra())
582
582
583 overrides = {(b'phases', b'new-commit'): old.phase()}
583 newnode = new.commit()
584 with ui.configoverride(overrides, b'phabsend'):
585 newnode = new.commit()
586
584
587 mapping[old.node()] = [newnode]
585 mapping[old.node()] = [newnode]
588 # Update diff property
586 # Update diff property
@@ -592,7 +590,7 def phabsend(ui, repo, *revs, **opts):
592 if tagname in repo.tags():
590 if tagname in repo.tags():
593 tags.tag(repo, tagname, nullid, message=None, user=None,
591 tags.tag(repo, tagname, nullid, message=None, user=None,
594 date=None, local=True)
592 date=None, local=True)
595 scmutil.cleanupnodes(repo, mapping, b'phabsend')
593 scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True)
596 if wnode in mapping:
594 if wnode in mapping:
597 unfi.setparents(mapping[wnode][0])
595 unfi.setparents(mapping[wnode][0])
598
596
@@ -158,7 +158,7 def fix(ui, repo, *pats, **opts):
158 del filedata[rev]
158 del filedata[rev]
159
159
160 replacements = {prec: [succ] for prec, succ in replacements.iteritems()}
160 replacements = {prec: [succ] for prec, succ in replacements.iteritems()}
161 scmutil.cleanupnodes(repo, replacements, 'fix')
161 scmutil.cleanupnodes(repo, replacements, 'fix', fixphase=True)
162
162
163 def getworkqueue(ui, repo, pats, opts, revstofix, basectxs):
163 def getworkqueue(ui, repo, pats, opts, revstofix, basectxs):
164 """"Constructs the list of files to be fixed at specific revisions
164 """"Constructs the list of files to be fixed at specific revisions
@@ -484,25 +484,23 def replacerev(ui, repo, ctx, filedata,
484 isexec=fctx.isexec(),
484 isexec=fctx.isexec(),
485 copied=copied)
485 copied=copied)
486
486
487 overrides = {('phases', 'new-commit'): ctx.phase()}
487 memctx = context.memctx(
488 with ui.configoverride(overrides, source='fix'):
488 repo,
489 memctx = context.memctx(
489 parents=(newp1node, newp2node),
490 repo,
490 text=ctx.description(),
491 parents=(newp1node, newp2node),
491 files=set(ctx.files()) | set(filedata.keys()),
492 text=ctx.description(),
492 filectxfn=filectxfn,
493 files=set(ctx.files()) | set(filedata.keys()),
493 user=ctx.user(),
494 filectxfn=filectxfn,
494 date=ctx.date(),
495 user=ctx.user(),
495 extra=ctx.extra(),
496 date=ctx.date(),
496 branch=ctx.branch(),
497 extra=ctx.extra(),
497 editor=None)
498 branch=ctx.branch(),
498 sucnode = memctx.commit()
499 editor=None)
499 prenode = ctx.node()
500 sucnode = memctx.commit()
500 if prenode == sucnode:
501 prenode = ctx.node()
501 ui.debug('node %s already existed\n' % (ctx.hex()))
502 if prenode == sucnode:
502 else:
503 ui.debug('node %s already existed\n' % (ctx.hex()))
503 replacements[ctx.node()] = sucnode
504 else:
505 replacements[ctx.node()] = sucnode
506
504
507 def getfixers(ui):
505 def getfixers(ui):
508 """Returns a map of configured fixer tools indexed by their names
506 """Returns a map of configured fixer tools indexed by their names
@@ -91,12 +91,7 def _commitfiltered(repo, ctx, match, ke
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
@@ -183,7 +178,7 def uncommit(ui, repo, *pats, **opts):
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)
@@ -242,12 +237,7 def unamend(ui, repo, **opts):
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
@@ -257,4 +247,4 def unamend(ui, repo, **opts):
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)
@@ -35,6 +35,7 from . import (
35 obsolete,
35 obsolete,
36 patch,
36 patch,
37 pathutil,
37 pathutil,
38 phases,
38 pycompat,
39 pycompat,
39 revlog,
40 revlog,
40 rewriteutil,
41 rewriteutil,
@@ -784,16 +785,12 def changebranch(ui, repo, revs, label):
784 extra=extra,
785 extra=extra,
785 branch=label)
786 branch=label)
786
787
787 commitphase = ctx.phase()
788 newnode = repo.commitctx(mc)
788 overrides = {('phases', 'new-commit'): commitphase}
789 with repo.ui.configoverride(overrides, 'branch-change'):
790 newnode = repo.commitctx(mc)
791
792 replacements[ctx.node()] = (newnode,)
789 replacements[ctx.node()] = (newnode,)
793 ui.debug('new node id is %s\n' % hex(newnode))
790 ui.debug('new node id is %s\n' % hex(newnode))
794
791
795 # create obsmarkers and move bookmarks
792 # create obsmarkers and move bookmarks
796 scmutil.cleanupnodes(repo, replacements, 'branch-change')
793 scmutil.cleanupnodes(repo, replacements, 'branch-change', fixphase=True)
797
794
798 # move the working copy too
795 # move the working copy too
799 wctx = repo[None]
796 wctx = repo[None]
@@ -2536,13 +2533,10 def amend(ui, repo, old, extra, pats, op
2536 # This not what we expect from amend.
2533 # This not what we expect from amend.
2537 return old.node()
2534 return old.node()
2538
2535
2536 commitphase = None
2539 if opts.get('secret'):
2537 if opts.get('secret'):
2540 commitphase = 'secret'
2538 commitphase = phases.secret
2541 else:
2539 newid = repo.commitctx(new)
2542 commitphase = old.phase()
2543 overrides = {('phases', 'new-commit'): commitphase}
2544 with ui.configoverride(overrides, 'amend'):
2545 newid = repo.commitctx(new)
2546
2540
2547 # Reroute the working copy parent to the new changeset
2541 # Reroute the working copy parent to the new changeset
2548 repo.setparents(newid, nullid)
2542 repo.setparents(newid, nullid)
@@ -2550,7 +2544,8 def amend(ui, repo, old, extra, pats, op
2550 obsmetadata = None
2544 obsmetadata = None
2551 if opts.get('note'):
2545 if opts.get('note'):
2552 obsmetadata = {'note': opts['note']}
2546 obsmetadata = {'note': opts['note']}
2553 scmutil.cleanupnodes(repo, mapping, 'amend', metadata=obsmetadata)
2547 scmutil.cleanupnodes(repo, mapping, 'amend', metadata=obsmetadata,
2548 fixphase=True, targetphase=commitphase)
2554
2549
2555 # Fixing the dirstate because localrepo.commitctx does not update
2550 # Fixing the dirstate because localrepo.commitctx does not update
2556 # it. This is rather convenient because we did not need to update
2551 # it. This is rather convenient because we did not need to update
@@ -779,7 +779,8 class _containsnode(object):
779 def __contains__(self, node):
779 def __contains__(self, node):
780 return self._revcontains(self._torev(node))
780 return self._revcontains(self._torev(node))
781
781
782 def cleanupnodes(repo, replacements, operation, moves=None, metadata=None):
782 def cleanupnodes(repo, replacements, operation, moves=None, metadata=None,
783 fixphase=False, targetphase=None):
783 """do common cleanups when old nodes are replaced by new nodes
784 """do common cleanups when old nodes are replaced by new nodes
784
785
785 That includes writing obsmarkers or stripping nodes, and moving bookmarks.
786 That includes writing obsmarkers or stripping nodes, and moving bookmarks.
@@ -795,6 +796,7 def cleanupnodes(repo, replacements, ope
795 metadata is dictionary containing metadata to be stored in obsmarker if
796 metadata is dictionary containing metadata to be stored in obsmarker if
796 obsolescence is enabled.
797 obsolescence is enabled.
797 """
798 """
799 assert fixphase or targetphase is None
798 if not replacements and not moves:
800 if not replacements and not moves:
799 return
801 return
800
802
@@ -825,11 +827,38 def cleanupnodes(repo, replacements, ope
825 newnode = newnodes[0]
827 newnode = newnodes[0]
826 moves[oldnode] = newnode
828 moves[oldnode] = newnode
827
829
830 allnewnodes = [n for ns in replacements.values() for n in ns]
831 toretract = {}
832 toadvance = {}
833 if fixphase:
834 precursors = {}
835 for oldnode, newnodes in replacements.items():
836 for newnode in newnodes:
837 precursors.setdefault(newnode, []).append(oldnode)
838
839 allnewnodes.sort(key=lambda n: unfi[n].rev())
840 newphases = {}
841 def phase(ctx):
842 return newphases.get(ctx.node(), ctx.phase())
843 for newnode in allnewnodes:
844 ctx = unfi[newnode]
845 if targetphase is None:
846 oldphase = max(unfi[oldnode].phase()
847 for oldnode in precursors[newnode])
848 parentphase = max(phase(p) for p in ctx.parents())
849 newphase = max(oldphase, parentphase)
850 else:
851 newphase = targetphase
852 newphases[newnode] = newphase
853 if newphase > ctx.phase():
854 toretract.setdefault(newphase, []).append(newnode)
855 elif newphase < ctx.phase():
856 toadvance.setdefault(newphase, []).append(newnode)
857
828 with repo.transaction('cleanup') as tr:
858 with repo.transaction('cleanup') as tr:
829 # Move bookmarks
859 # Move bookmarks
830 bmarks = repo._bookmarks
860 bmarks = repo._bookmarks
831 bmarkchanges = []
861 bmarkchanges = []
832 allnewnodes = [n for ns in replacements.values() for n in ns]
833 for oldnode, newnode in moves.items():
862 for oldnode, newnode in moves.items():
834 oldbmarks = repo.nodebookmarks(oldnode)
863 oldbmarks = repo.nodebookmarks(oldnode)
835 if not oldbmarks:
864 if not oldbmarks:
@@ -850,6 +879,11 def cleanupnodes(repo, replacements, ope
850 if bmarkchanges:
879 if bmarkchanges:
851 bmarks.applychanges(repo, tr, bmarkchanges)
880 bmarks.applychanges(repo, tr, bmarkchanges)
852
881
882 for phase, nodes in toretract.items():
883 phases.retractboundary(repo, tr, phase, nodes)
884 for phase, nodes in toadvance.items():
885 phases.advanceboundary(repo, tr, phase, nodes)
886
853 # Obsolete or strip nodes
887 # Obsolete or strip nodes
854 if obsolete.isenabled(repo, obsolete.createmarkersopt):
888 if obsolete.isenabled(repo, obsolete.createmarkersopt):
855 # If a node is already obsoleted, and we want to obsolete it
889 # If a node is already obsoleted, and we want to obsolete it
General Comments 0
You need to be logged in to leave comments. Login now