changeset 51554:a151fd01e98c

postincoming: move to cmdutil This looks like a good place for it to live.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 27 Mar 2024 17:29:48 +0000
parents f28d5d68b71a
children 15e680a44502
files hgext/rebase.py mercurial/cmdutil.py mercurial/commands.py
diffstat 3 files changed, 48 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Wed Mar 27 17:21:46 2024 +0000
+++ b/hgext/rebase.py	Wed Mar 27 17:29:48 2024 +0000
@@ -2133,16 +2133,16 @@
             )
 
             revsprepull = len(repo)
-            origpostincoming = commands.postincoming
+            origpostincoming = cmdutil.postincoming
 
             def _dummy(*args, **kwargs):
                 pass
 
-            commands.postincoming = _dummy
+            cmdutil.postincoming = _dummy
             try:
                 ret = orig(ui, repo, *args, **opts)
             finally:
-                commands.postincoming = origpostincoming
+                cmdutil.postincoming = origpostincoming
             revspostpull = len(repo)
             if revspostpull > revsprepull:
                 # --rev option from pull conflict with rebase own --rev
--- a/mercurial/cmdutil.py	Wed Mar 27 17:21:46 2024 +0000
+++ b/mercurial/cmdutil.py	Wed Mar 27 17:29:48 2024 +0000
@@ -4135,3 +4135,46 @@
     with repo.wlock():
         graftstate = statemod.cmdstate(repo, b'graftstate')
         return abortgraft(ui, repo, graftstate)
+
+
+def postincoming(ui, repo, modheads, optupdate, checkout, brev):
+    """Run after a changegroup has been added via pull/unbundle
+
+    This takes arguments below:
+
+    :modheads: change of heads by pull/unbundle
+    :optupdate: updating working directory is needed or not
+    :checkout: update destination revision (or None to default destination)
+    :brev: a name, which might be a bookmark to be activated after updating
+
+    return True if update raise any conflict, False otherwise.
+    """
+    if modheads == 0:
+        return False
+    if optupdate:
+        # avoid circular import
+        from . import hg
+
+        try:
+            return hg.updatetotally(ui, repo, checkout, brev)
+        except error.UpdateAbort as inst:
+            msg = _(b"not updating: %s") % stringutil.forcebytestr(inst)
+            hint = inst.hint
+            raise error.UpdateAbort(msg, hint=hint)
+    if ui.quiet:
+        pass  # we won't report anything so the other clause are useless.
+    elif modheads is not None and modheads > 1:
+        currentbranchheads = len(repo.branchheads())
+        if currentbranchheads == modheads:
+            ui.status(
+                _(b"(run 'hg heads' to see heads, 'hg merge' to merge)\n")
+            )
+        elif currentbranchheads > 1:
+            ui.status(
+                _(b"(run 'hg heads .' to see heads, 'hg merge' to merge)\n")
+            )
+        else:
+            ui.status(_(b"(run 'hg heads' to see heads)\n"))
+    elif not ui.configbool(b'commands', b'update.requiredest'):
+        ui.status(_(b"(run 'hg update' to get a working copy)\n"))
+    return False
--- a/mercurial/commands.py	Wed Mar 27 17:21:46 2024 +0000
+++ b/mercurial/commands.py	Wed Mar 27 17:29:48 2024 +0000
@@ -5375,46 +5375,6 @@
     return ret
 
 
-def postincoming(ui, repo, modheads, optupdate, checkout, brev):
-    """Run after a changegroup has been added via pull/unbundle
-
-    This takes arguments below:
-
-    :modheads: change of heads by pull/unbundle
-    :optupdate: updating working directory is needed or not
-    :checkout: update destination revision (or None to default destination)
-    :brev: a name, which might be a bookmark to be activated after updating
-
-    return True if update raise any conflict, False otherwise.
-    """
-    if modheads == 0:
-        return False
-    if optupdate:
-        try:
-            return hg.updatetotally(ui, repo, checkout, brev)
-        except error.UpdateAbort as inst:
-            msg = _(b"not updating: %s") % stringutil.forcebytestr(inst)
-            hint = inst.hint
-            raise error.UpdateAbort(msg, hint=hint)
-    if ui.quiet:
-        pass  # we won't report anything so the other clause are useless.
-    elif modheads is not None and modheads > 1:
-        currentbranchheads = len(repo.branchheads())
-        if currentbranchheads == modheads:
-            ui.status(
-                _(b"(run 'hg heads' to see heads, 'hg merge' to merge)\n")
-            )
-        elif currentbranchheads > 1:
-            ui.status(
-                _(b"(run 'hg heads .' to see heads, 'hg merge' to merge)\n")
-            )
-        else:
-            ui.status(_(b"(run 'hg heads' to see heads)\n"))
-    elif not ui.configbool(b'commands', b'update.requiredest'):
-        ui.status(_(b"(run 'hg update' to get a working copy)\n"))
-    return False
-
-
 @command(
     b'pull',
     [
@@ -5610,7 +5570,7 @@
                 # for pushes.
                 repo._subtoppath = path.loc
                 try:
-                    update_conflict = postincoming(
+                    update_conflict = cmdutil.postincoming(
                         ui, repo, modheads, opts.get('update'), checkout, brev
                     )
                 except error.FilteredRepoLookupError as exc:
@@ -7777,7 +7737,7 @@
                 )
             modheads = bundle2.combinechangegroupresults(op)
 
-    if postincoming(ui, repo, modheads, opts.get('update'), None, None):
+    if cmdutil.postincoming(ui, repo, modheads, opts.get('update'), None, None):
         return 1
     else:
         return 0