rebase: make collapsing use explicit logic to decide on the rev to reuse
authorKostia Balytskyi <ikostia@fb.com>
Fri, 01 Jul 2016 14:09:53 +0200
changeset 29474 56641501adde
parent 29473 e25da98052a4
child 29475 fb7fc877ed17
rebase: make collapsing use explicit logic to decide on the rev to reuse This code: for rev in sortedstate: ... ... newnode = concludenode(repo, rev, p1, rbsrt.external, commitmsg=commitmsg, extrafn=extrafn, editor=editor, keepbranches=rbsrt.keepbranchesf, date=rbsrt.date) uses 'rev' variable in 'concludenode' function invocation. It is not explicitly assigned before, but its value comes as last value or 'rev' in a for loop, e.g. last element in a 'sortedstate'. IMO this a bad style and it also makes it hard to refactor the function, so it is better to explicitly define the value passed to 'concludenode'.
hgext/rebase.py
--- a/hgext/rebase.py	Fri Jul 01 14:09:53 2016 +0200
+++ b/hgext/rebase.py	Fri Jul 01 14:09:53 2016 +0200
@@ -499,10 +499,10 @@
 
         extrafn = _makeextrafn(rbsrt.extrafns)
 
-        sortedstate = sorted(rbsrt.state)
-        total = len(sortedstate)
+        rbsrt.sortedstate = sorted(rbsrt.state)
+        total = len(rbsrt.sortedstate)
         pos = 0
-        for rev in sortedstate:
+        for rev in rbsrt.sortedstate:
             ctx = repo[rev]
             desc = '%d:%s "%s"' % (ctx.rev(), ctx,
                                    ctx.description().split('\n', 1)[0])
@@ -599,7 +599,8 @@
                         commitmsg += '\n* %s' % repo[rebased].description()
                 editopt = True
             editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
-            newnode = concludenode(repo, rev, p1, rbsrt.external,
+            revtoreuse = rbsrt.sortedstate[-1]
+            newnode = concludenode(repo, revtoreuse, p1, rbsrt.external,
                                    commitmsg=commitmsg,
                                    extrafn=extrafn, editor=editor,
                                    keepbranches=rbsrt.keepbranchesf,