Patchwork D120: phabricator: add --status option to phabread

login
register
mail settings
Submitter phabricator
Date July 18, 2017, 4:20 a.m.
Message ID <differential-rev-PHID-DREV-vxtxmgk6d4twif5owhbb-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22468/
State Superseded, archived
Headers show

Comments

phabricator - July 18, 2017, 4:20 a.m.
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The --status option filters Differential Revisions by their status, like
  "Opened", "Accetped" etc. It could be useful to skip certain revisions.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D120

AFFECTED FILES
  contrib/phabricator.py

CHANGE DETAILS




EMAIL PREFERENCES
  https://phab.mercurial-scm.org/settings/panel/emailpreferences/

To: quark, #hg-reviewers
Cc: mercurial-devel
phabricator - July 18, 2017, 6:29 a.m.
quark abandoned this revision.
quark added a comment.


  Have a better idea about how to do this.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D120

EMAIL PREFERENCES
  https://phab.mercurial-scm.org/settings/panel/emailpreferences/

To: quark, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -526,12 +526,19 @@ 
             meta[r'parent'] = commit[r'parents'][0]
     return meta or {}
 
-def readpatch(repo, params, write, stack=False):
+def _normalizestatus(name):
+    """normalize status name: remove spaces and convert to lower case"""
+    return name.replace(' ', '').lower()
+
+def readpatch(repo, params, write, stack=False, status=None):
     """generate plain-text patch readable by 'hg import'
 
     write is usually ui.write. params is passed to "differential.query". If
-    stack is True, also write dependent patches.
+    stack is True, also write dependent patches. If status is not None, it's a
+    list of strings and Differential Revision outside them will be skipped.
     """
+    statusset = set(_normalizestatus(s) for s in status or ())
+
     # Differential Revisions
     drevs = querydrev(repo, params, stack)
 
@@ -541,6 +548,9 @@ 
 
     # Generate patch for each drev
     for drev in drevs:
+        if statusset and _normalizestatus(drev[r'statusName']) not in statusset:
+            continue
+
         repo.ui.note(_('reading D%s\n') % drev[r'id'])
 
         diffid = max(int(v) for v in drev[r'diffs'])
@@ -559,18 +569,24 @@ 
         write(('%s%s\n%s') % (header, desc, body))
 
 @command('phabread',
-         [('', 'stack', False, _('read dependencies'))],
+         [('', 'stack', False, _('read dependencies')),
+          ('', 'status', [], _('filter patches by status'))],
          _('REVID [OPTIONS]'))
 def phabread(ui, repo, revid, **opts):
     """print patches from Phabricator suitable for importing
 
     REVID could be a Differential Revision identity, like ``D123``, or just the
     number ``123``, or a full URL like ``https://phab.example.com/D123``.
 
     If --stack is given, follow dependencies information and read all patches.
+
+    If --status is given, only print Differential Revisions matching one of the
+    given statuses. Statuses could be ``Accepted``, ``NeedsReview``,
+    ``NeedsRevision``, ``Closed``, ``Abandoned``.
     """
     try:
         revid = int(revid.split('/')[-1].replace('D', ''))
     except ValueError:
         raise error.Abort(_('invalid Revision ID: %s') % revid)
-    readpatch(repo, {'ids': [revid]}, ui.write, opts.get('stack'))
+    readpatch(repo, {'ids': [revid]}, ui.write, opts.get('stack'),
+              opts.get('status'))