comparison 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
comparison
equal deleted inserted replaced
44714:8dbcd5138102 44715:38f7b2f02f6d
52 import json 52 import json
53 import mimetypes 53 import mimetypes
54 import operator 54 import operator
55 import re 55 import re
56 56
57 from mercurial.node import bin, nullid 57 from mercurial.node import bin, nullid, short
58 from mercurial.i18n import _ 58 from mercurial.i18n import _
59 from mercurial.pycompat import getattr 59 from mercurial.pycompat import getattr
60 from mercurial.thirdparty import attr 60 from mercurial.thirdparty import attr
61 from mercurial import ( 61 from mercurial import (
62 cmdutil, 62 cmdutil,
113 b'phabricator', b'callsign', default=None, 113 b'phabricator', b'callsign', default=None,
114 ) 114 )
115 eh.configitem( 115 eh.configitem(
116 b'phabricator', b'curlcmd', default=None, 116 b'phabricator', b'curlcmd', default=None,
117 ) 117 )
118 # developer config: phabricator.debug
119 eh.configitem(
120 b'phabricator', b'debug', default=False,
121 )
118 # developer config: phabricator.repophid 122 # developer config: phabricator.repophid
119 eh.configitem( 123 eh.configitem(
120 b'phabricator', b'repophid', default=None, 124 b'phabricator', b'repophid', default=None,
121 ) 125 )
122 eh.configitem( 126 eh.configitem(
275 helpcategory=helpcategory, 279 helpcategory=helpcategory,
276 optionalrepo=optionalrepo, 280 optionalrepo=optionalrepo,
277 )(cmd) 281 )(cmd)
278 282
279 return decorate 283 return decorate
284
285
286 def _debug(ui, *msg, **opts):
287 """write debug output for Phabricator if ``phabricator.debug`` is set
288
289 Specifically, this avoids dumping Conduit and HTTP auth chatter that is
290 printed with the --debug argument.
291 """
292 if ui.configbool(b"phabricator", b"debug"):
293 flag = ui.debugflag
294 try:
295 ui.debugflag = True
296 ui.write(*msg, **opts)
297 finally:
298 ui.debugflag = flag
280 299
281 300
282 def urlencodenested(params): 301 def urlencodenested(params):
283 """like urlencode, but works with nested parameters. 302 """like urlencode, but works with nested parameters.
284 303
453 """ 472 """
454 unfi = repo.unfiltered() 473 unfi = repo.unfiltered()
455 has_node = unfi.changelog.index.has_node 474 has_node = unfi.changelog.index.has_node
456 475
457 result = {} # {node: (oldnode?, lastdiff?, drev)} 476 result = {} # {node: (oldnode?, lastdiff?, drev)}
458 toconfirm = {} # {node: (force, {precnode}, drev)} 477 # ordered for test stability when printing new -> old mapping below
478 toconfirm = util.sortdict() # {node: (force, {precnode}, drev)}
459 for node in nodelist: 479 for node in nodelist:
460 ctx = unfi[node] 480 ctx = unfi[node]
461 # For tags like "D123", put them into "toconfirm" to verify later 481 # For tags like "D123", put them into "toconfirm" to verify later
462 precnodes = list(obsutil.allpredecessors(unfi.obsstore, [node])) 482 precnodes = list(obsutil.allpredecessors(unfi.obsstore, [node]))
463 for n in precnodes: 483 for n in precnodes:
523 # exists in the repo 543 # exists in the repo
524 oldnode = lastdiff = None 544 oldnode = lastdiff = None
525 if diffs: 545 if diffs:
526 lastdiff = max(diffs, key=lambda d: int(d[b'id'])) 546 lastdiff = max(diffs, key=lambda d: int(d[b'id']))
527 oldnodes = getnodes(lastdiff, precset) 547 oldnodes = getnodes(lastdiff, precset)
548
549 _debug(
550 unfi.ui,
551 b"%s mapped to old nodes %s\n"
552 % (
553 short(newnode),
554 stringutil.pprint([short(n) for n in sorted(oldnodes)]),
555 ),
556 )
528 557
529 # If this commit was the result of `hg fold` after submission, 558 # If this commit was the result of `hg fold` after submission,
530 # and now resubmitted with --fold, the easiest thing to do is 559 # and now resubmitted with --fold, the easiest thing to do is
531 # to leave the node clear. This only results in creating a new 560 # to leave the node clear. This only results in creating a new
532 # diff for the _same_ Differential Revision if this commit is 561 # diff for the _same_ Differential Revision if this commit is
1192 """update the local commit list for the ``diff`` associated with ``drevid`` 1221 """update the local commit list for the ``diff`` associated with ``drevid``
1193 1222
1194 This is a utility function for the amend phase of ``phabsend``, which 1223 This is a utility function for the amend phase of ``phabsend``, which
1195 converts failures to warning messages. 1224 converts failures to warning messages.
1196 """ 1225 """
1226 _debug(
1227 unfi.ui,
1228 b"new commits: %s\n" % stringutil.pprint([short(n) for n in newnodes]),
1229 )
1230
1197 try: 1231 try:
1198 writediffproperties([unfi[newnode] for newnode in newnodes], diff) 1232 writediffproperties([unfi[newnode] for newnode in newnodes], diff)
1199 except util.urlerr.urlerror: 1233 except util.urlerr.urlerror:
1200 # If it fails just warn and keep going, otherwise the DREV 1234 # If it fails just warn and keep going, otherwise the DREV
1201 # associations will be lost 1235 # associations will be lost