diff hgext/phabricator.py @ 44715:38f7b2f02f6d

phabricator: add debug logging to show previous node values in `phabsend` This isn't real useful here, but was very useful showing how `phabsend --fold` handles commits created by `hg fold` and `hg split`. It introduces a new debug function and flag instead of using `ui.debug()`, because `--debug` prints out all of the API chatter. Differential Revision: https://phab.mercurial-scm.org/D8389
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Apr 2020 21:19:21 -0400
parents 949a87145336
children 3dc6a70779f2
line wrap: on
line diff
--- a/hgext/phabricator.py	Thu Apr 16 17:31:29 2020 +0200
+++ b/hgext/phabricator.py	Sun Apr 05 21:19:21 2020 -0400
@@ -54,7 +54,7 @@
 import operator
 import re
 
-from mercurial.node import bin, nullid
+from mercurial.node import bin, nullid, short
 from mercurial.i18n import _
 from mercurial.pycompat import getattr
 from mercurial.thirdparty import attr
@@ -115,6 +115,10 @@
 eh.configitem(
     b'phabricator', b'curlcmd', default=None,
 )
+# developer config: phabricator.debug
+eh.configitem(
+    b'phabricator', b'debug', default=False,
+)
 # developer config: phabricator.repophid
 eh.configitem(
     b'phabricator', b'repophid', default=None,
@@ -279,6 +283,21 @@
     return decorate
 
 
+def _debug(ui, *msg, **opts):
+    """write debug output for Phabricator if ``phabricator.debug`` is set
+
+    Specifically, this avoids dumping Conduit and HTTP auth chatter that is
+    printed with the --debug argument.
+    """
+    if ui.configbool(b"phabricator", b"debug"):
+        flag = ui.debugflag
+        try:
+            ui.debugflag = True
+            ui.write(*msg, **opts)
+        finally:
+            ui.debugflag = flag
+
+
 def urlencodenested(params):
     """like urlencode, but works with nested parameters.
 
@@ -455,7 +474,8 @@
     has_node = unfi.changelog.index.has_node
 
     result = {}  # {node: (oldnode?, lastdiff?, drev)}
-    toconfirm = {}  # {node: (force, {precnode}, drev)}
+    # ordered for test stability when printing new -> old mapping below
+    toconfirm = util.sortdict()  # {node: (force, {precnode}, drev)}
     for node in nodelist:
         ctx = unfi[node]
         # For tags like "D123", put them into "toconfirm" to verify later
@@ -526,6 +546,15 @@
                 lastdiff = max(diffs, key=lambda d: int(d[b'id']))
                 oldnodes = getnodes(lastdiff, precset)
 
+                _debug(
+                    unfi.ui,
+                    b"%s mapped to old nodes %s\n"
+                    % (
+                        short(newnode),
+                        stringutil.pprint([short(n) for n in sorted(oldnodes)]),
+                    ),
+                )
+
                 # If this commit was the result of `hg fold` after submission,
                 # and now resubmitted with --fold, the easiest thing to do is
                 # to leave the node clear.  This only results in creating a new
@@ -1194,6 +1223,11 @@
     This is a utility function for the amend phase of ``phabsend``, which
     converts failures to warning messages.
     """
+    _debug(
+        unfi.ui,
+        b"new commits: %s\n" % stringutil.pprint([short(n) for n in newnodes]),
+    )
+
     try:
         writediffproperties([unfi[newnode] for newnode in newnodes], diff)
     except util.urlerr.urlerror: