[PATCH 06 of 10] phabricator: avoid calling differential.getcommitmessage

Jun Wu quark at fb.com
Tue Jul 4 21:58:31 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1499211408 25200
#      Tue Jul 04 16:36:48 2017 -0700
# Node ID 992fc5ed028d5312eb96acd360b6cc6611cc76bd
# Parent  71433de5157b49dfbb58ebe638a5c5ae780763dc
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 992fc5ed028d
phabricator: avoid calling differential.getcommitmessage

Previously, we call differential.getcommitmessage API to get commit
messages. Now we read that from "Differential Revision" object fetched
via "differential.query" API.

This removes one API call per patch.

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -308,6 +308,4 @@ def phabsend(ui, repo, *revs, **opts):
         lastrevid = newrevid
 
-_summaryre = re.compile('^Summary:\s*', re.M)
-
 # Map from "hg:meta" keys to header understood by "hg import". The order is
 # consistent with "hg export" output.
@@ -378,4 +376,18 @@ def querydrev(repo, params, stack=False)
     return result
 
+def getdescfromdrev(drev):
+    """get description (commit message) from "Differential Revision"
+
+    This is similar to differential.getcommitmessage API. But we only care
+    about limited fields: title, summary, test plan, and URL.
+    """
+    title = drev[r'title']
+    summary = drev[r'summary'].rstrip()
+    testplan = drev[r'testPlan'].rstrip()
+    if testplan:
+        testplan = 'Test Plan:\n%s' % testplan
+    uri = 'Differential Revision: %s' % drev[r'uri']
+    return '\n\n'.join(filter(None, [title, summary, testplan, uri]))
+
 def readpatch(repo, params, write, stack=False):
     """generate plain-text patch readable by 'hg import'
@@ -397,11 +409,7 @@ def readpatch(repo, params, write, stack
         diffid = max(int(v) for v in drev[r'diffs'])
         body = callconduit(repo, 'differential.getrawdiff', {'diffID': diffid})
-        desc = callconduit(repo, 'differential.getcommitmessage',
-                           {'revision_id': drev[r'id']})
+        desc = getdescfromdrev(drev)
         header = '# HG changeset patch\n'
 
-        # Remove potential empty "Summary:"
-        desc = _summaryre.sub('', desc)
-
         # Try to preserve metadata from hg:meta property. Write hg patch
         # headers that can be read by the "import" command. See patchheadermap


More information about the Mercurial-devel mailing list