contrib/phabricator.py
changeset 33268 85391b95961d
parent 33267 dba9f88659a3
child 33269 ead6749354e1
equal deleted inserted replaced
33267:dba9f88659a3 33268:85391b95961d
   304             action = _('skipped')
   304             action = _('skipped')
   305 
   305 
   306         ui.write(_('D%s: %s - %s: %s\n') % (newrevid, action, ctx,
   306         ui.write(_('D%s: %s - %s: %s\n') % (newrevid, action, ctx,
   307                                             ctx.description().split('\n')[0]))
   307                                             ctx.description().split('\n')[0]))
   308         lastrevid = newrevid
   308         lastrevid = newrevid
   309 
       
   310 _summaryre = re.compile('^Summary:\s*', re.M)
       
   311 
   309 
   312 # Map from "hg:meta" keys to header understood by "hg import". The order is
   310 # Map from "hg:meta" keys to header understood by "hg import". The order is
   313 # consistent with "hg export" output.
   311 # consistent with "hg export" output.
   314 _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'),
   312 _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'),
   315                               (r'node', 'Node ID'), (r'parent', 'Parent ')])
   313                               (r'node', 'Node ID'), (r'parent', 'Parent ')])
   375             for phid in depends:
   373             for phid in depends:
   376                 queue.append({'phids': [phid]})
   374                 queue.append({'phids': [phid]})
   377     result.reverse()
   375     result.reverse()
   378     return result
   376     return result
   379 
   377 
       
   378 def getdescfromdrev(drev):
       
   379     """get description (commit message) from "Differential Revision"
       
   380 
       
   381     This is similar to differential.getcommitmessage API. But we only care
       
   382     about limited fields: title, summary, test plan, and URL.
       
   383     """
       
   384     title = drev[r'title']
       
   385     summary = drev[r'summary'].rstrip()
       
   386     testplan = drev[r'testPlan'].rstrip()
       
   387     if testplan:
       
   388         testplan = 'Test Plan:\n%s' % testplan
       
   389     uri = 'Differential Revision: %s' % drev[r'uri']
       
   390     return '\n\n'.join(filter(None, [title, summary, testplan, uri]))
       
   391 
   380 def readpatch(repo, params, write, stack=False):
   392 def readpatch(repo, params, write, stack=False):
   381     """generate plain-text patch readable by 'hg import'
   393     """generate plain-text patch readable by 'hg import'
   382 
   394 
   383     write is usually ui.write. params is passed to "differential.query". If
   395     write is usually ui.write. params is passed to "differential.query". If
   384     stack is True, also write dependent patches.
   396     stack is True, also write dependent patches.
   394     for drev in drevs:
   406     for drev in drevs:
   395         repo.ui.note(_('reading D%s\n') % drev[r'id'])
   407         repo.ui.note(_('reading D%s\n') % drev[r'id'])
   396 
   408 
   397         diffid = max(int(v) for v in drev[r'diffs'])
   409         diffid = max(int(v) for v in drev[r'diffs'])
   398         body = callconduit(repo, 'differential.getrawdiff', {'diffID': diffid})
   410         body = callconduit(repo, 'differential.getrawdiff', {'diffID': diffid})
   399         desc = callconduit(repo, 'differential.getcommitmessage',
   411         desc = getdescfromdrev(drev)
   400                            {'revision_id': drev[r'id']})
       
   401         header = '# HG changeset patch\n'
   412         header = '# HG changeset patch\n'
   402 
       
   403         # Remove potential empty "Summary:"
       
   404         desc = _summaryre.sub('', desc)
       
   405 
   413 
   406         # Try to preserve metadata from hg:meta property. Write hg patch
   414         # Try to preserve metadata from hg:meta property. Write hg patch
   407         # headers that can be read by the "import" command. See patchheadermap
   415         # headers that can be read by the "import" command. See patchheadermap
   408         # and extract in mercurial/patch.py for supported headers.
   416         # and extract in mercurial/patch.py for supported headers.
   409         props = diffs[str(diffid)][r'properties'] # could be empty list or dict
   417         props = diffs[str(diffid)][r'properties'] # could be empty list or dict