evolve: extract "update" code into its own function
authorSushil khanchi <sushilkhanchi97@gmail.com>
Fri, 18 Jan 2019 23:08:43 +0530
changeset 4347 59745d6d626d
parent 4346 ff483949674e
child 4348 398c33b17d76
evolve: extract "update" code into its own function This patch moves the code to a function which handles the case when wdir parent is obsolete and evolve will just update to its successor. And extraction of this to a function will also help us to fix the issue5881.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Tue Dec 25 16:08:05 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Jan 18 23:08:43 2019 +0530
@@ -1479,35 +1479,8 @@
     elif len(specifiedcategories) == 1:
         targetcat = specifiedcategories[0]
     elif repo['.'].obsolete():
-        oldid = repo['.'].node()
-        displayer = compat.changesetdisplayer(ui, repo,
-                                              {'template': shorttemplate})
-        # no args and parent is obsolete, update to successors
-        try:
-            ctx = repo[utility._singlesuccessor(repo, repo['.'])]
-        except utility.MultipleSuccessorsError as exc:
-            repo.ui.write_err(_('parent is obsolete with multiple'
-                                ' successors:\n'))
-            for ln in exc.successorssets:
-                for n in ln:
-                    displayer.show(repo[n])
-            return 2
-
-        ui.status(_('update:'))
-        if not ui.quiet:
-            displayer.show(ctx)
-
-        if dryrunopt:
-            return 0
-        res = hg.update(repo, ctx.rev())
-        newid = ctx.node()
-
-        if ctx != startnode:
-            with repo.wlock(), repo.lock(), repo.transaction('evolve') as tr:
-                bmupdater = rewriteutil.bookmarksupdater(repo, oldid, tr)
-                bmupdater(newid)
-            ui.status(_('working directory is now at %s\n') % ctx)
-        return res
+        # if no args and parent is obsolete, update to successors
+        return solveobswdp(ui, repo, opts)
 
     ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'evolve')
     troubled = set(repo.revs('troubled()'))
@@ -1616,6 +1589,38 @@
     progresscb()
     _cleanup(ui, repo, startnode, showprogress, shouldupdate)
 
+def solveobswdp(ui, repo, opts):
+    oldid = repo['.'].node()
+    startnode = repo['.']
+    dryrunopt = opts.get('dry_run', False)
+    displayer = compat.changesetdisplayer(ui, repo,
+                                          {'template': shorttemplate})
+    try:
+        ctx = repo[utility._singlesuccessor(repo, repo['.'])]
+    except utility.MultipleSuccessorsError as exc:
+        repo.ui.write_err(_('parent is obsolete with multiple'
+                            ' successors:\n'))
+        for ln in exc.successorssets:
+            for n in ln:
+                displayer.show(repo[n])
+        return 2
+
+    ui.status(_('update:'))
+    if not ui.quiet:
+        displayer.show(ctx)
+
+    if dryrunopt:
+        return 0
+    res = hg.update(repo, ctx.rev())
+    newid = ctx.node()
+
+    if ctx != startnode:
+        with repo.wlock(), repo.lock(), repo.transaction('evolve') as tr:
+            bmupdater = rewriteutil.bookmarksupdater(repo, oldid, tr)
+            bmupdater(newid)
+        ui.status(_('working directory is now at %s\n') % ctx)
+    return res
+
 def stopevolve(ui, repo, evolvestate):
     """logic for handling of `hg evolve --stop`"""
     updated = False