# HG changeset patch # User Jun Wu # Date 1499211408 25200 # Node ID 85391b95961d7d4b4b7f82d6e9420fef008cec70 # Parent dba9f88659a3c6e8aeeb458793c0208a1eaa20f2 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 -r dba9f88659a3 -r 85391b95961d contrib/phabricator.py --- a/contrib/phabricator.py Tue Jul 04 16:36:48 2017 -0700 +++ b/contrib/phabricator.py Tue Jul 04 16:36:48 2017 -0700 @@ -307,8 +307,6 @@ ctx.description().split('\n')[0])) 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. _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'), @@ -377,6 +375,20 @@ result.reverse() 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' @@ -396,13 +408,9 @@ 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 # and extract in mercurial/patch.py for supported headers.