comparison contrib/phabricator.py @ 33831:75fdaf851e83

phabricator: change "readpatch" to be more flexible Previously, `readpatch` and `querydrev` take a same `params` and `stack` parameters. This patch changes `readpatch` so it takes the output of `querydrev`, not the input of `querydrev`. This makes the code more flexible and cleaner. Differential Revision: https://phab.mercurial-scm.org/D124
author Jun Wu <quark@fb.com>
date Mon, 17 Jul 2017 23:14:06 -0700
parents fa3aa6c98bb7
children 539541779010
comparison
equal deleted inserted replaced
33830:aa6c290a77fa 33831:75fdaf851e83
633 } 633 }
634 if len(commit.get(r'parents', ())) >= 1: 634 if len(commit.get(r'parents', ())) >= 1:
635 meta[r'parent'] = commit[r'parents'][0] 635 meta[r'parent'] = commit[r'parents'][0]
636 return meta or {} 636 return meta or {}
637 637
638 def readpatch(repo, params, write, stack=False): 638 def readpatch(repo, drevs, write):
639 """generate plain-text patch readable by 'hg import' 639 """generate plain-text patch readable by 'hg import'
640 640
641 write is usually ui.write. params is passed to "differential.query". If 641 write is usually ui.write. drevs is what "querydrev" returns, results of
642 stack is True, also write dependent patches. 642 "differential.query".
643 """ 643 """
644 # Differential Revisions
645 drevs = querydrev(repo, params, stack)
646
647 # Prefetch hg:meta property for all diffs 644 # Prefetch hg:meta property for all diffs
648 diffids = sorted(set(max(int(v) for v in drev[r'diffs']) for drev in drevs)) 645 diffids = sorted(set(max(int(v) for v in drev[r'diffs']) for drev in drevs))
649 diffs = callconduit(repo, 'differential.querydiffs', {'ids': diffids}) 646 diffs = callconduit(repo, 'differential.querydiffs', {'ids': diffids})
650 647
651 # Generate patch for each drev 648 # Generate patch for each drev
681 """ 678 """
682 try: 679 try:
683 revid = int(revid.split('/')[-1].replace('D', '')) 680 revid = int(revid.split('/')[-1].replace('D', ''))
684 except ValueError: 681 except ValueError:
685 raise error.Abort(_('invalid Revision ID: %s') % revid) 682 raise error.Abort(_('invalid Revision ID: %s') % revid)
686 readpatch(repo, {'ids': [revid]}, ui.write, opts.get('stack')) 683 drevs = querydrev(repo, {'ids': [revid]}, opts.get('stack'))
684 readpatch(repo, drevs, ui.write)