Patchwork D8232: phabricator: add a helper function to convert DREVSPECs to a DREV dict list

login
register
mail settings
Submitter phabricator
Date March 5, 2020, 4:43 p.m.
Message ID <differential-rev-PHID-DREV-3inzw4qodl25lfm3akvm-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45509/
State Superseded
Headers show

Comments

phabricator - March 5, 2020, 4:43 p.m.
mharbison72 created this revision.
Herald added subscribers: mercurial-devel, Kwan.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Prep work for allowing multiple DREVSPECs to various commands, and properly
  validating the input.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: Kwan, mercurial-devel
phabricator - March 13, 2020, 4:26 p.m.
Alphare added a comment.


  This seems like something that can easily have a few simple unit tests

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8232/new/

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

To: mharbison72, #hg-reviewers
Cc: Alphare, Kwan, mercurial-devel
phabricator - March 13, 2020, 5:49 p.m.
mharbison72 added a comment.


  In D8232#123673 <https://phab.mercurial-scm.org/D8232#123673>, @Alphare wrote:
  
  > This seems like something that can easily have a few simple unit tests
  
  The next patch attempts to provide coverage.  I'm not sure how else to test this, because it wants to communicate with the server to resolve these values, so then it needs to be run as a command to hook up with the VCR infrastructure.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8232/new/

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

To: mharbison72, #hg-reviewers
Cc: Alphare, Kwan, mercurial-devel
phabricator - March 17, 2020, 8:10 a.m.
Alphare added a comment.
Alphare accepted this revision.


  In D8232#123683 <https://phab.mercurial-scm.org/D8232#123683>, @mharbison72 wrote:
  
  > The next patch attempts to provide coverage.  I'm not sure how else to test this, because it wants to communicate with the server to resolve these values, so then it needs to be run as a command to hook up with the VCR infrastructure.
  
  I guess that's fine. I just wish we had more unit tests for things like utils that are self-contained (in theory) and not really subject to change.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8232/new/

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

To: mharbison72, #hg-reviewers, Alphare
Cc: Alphare, Kwan, mercurial-devel
phabricator - March 20, 2020, 2:50 p.m.
mharbison72 added a comment.


  In D8232#124097 <https://phab.mercurial-scm.org/D8232#124097>, @yuja wrote:
  
  >>> +def _getdrevs(ui, stack, *specs):
  >>> +    """convert user supplied DREVSPECs into "Differential Revision" dicts
  >>> +
  >>> +    See ``hg help phabread`` for how to specify each DREVSPEC.
  >>> +    """
  >>> +    if len(*specs) > 0:
  >>
  >>   ^^^^^^
  >>
  >> Fixed bad argument expansion since I had to rebase this. Please let me
  >> know if that's wrong.
  >
  > Never mind. Maybe `specs` is a list containing a single list, in which case,
  > the code is valid.
  
  It looks like a tuple of strings:
  
    >>> print('specs type is %s' % type(specs))
    specs type is <type 'tuple'>
    >>> print('specs is %r' % (specs,))
    specs is ('D1', 'D2', 'D3')
  
  I copied this pattern from somewhere in Mercurial (file patterns look like they're handled in a similar way), but don't remember exactly where at this point.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8232/new/

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

To: mharbison72, #hg-reviewers, Alphare, pulkit
Cc: yuja, Alphare, Kwan, mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -1632,6 +1632,27 @@ 
     return meta
 
 
+def _getdrevs(ui, stack, *specs):
+    """convert user supplied DREVSPECs into "Differential Revision" dicts
+
+    See ``hg help phabread`` for how to specify each DREVSPEC.
+    """
+    if len(*specs) > 0:
+
+        def _formatspec(s):
+            if stack:
+                s = b':(%s)' % s
+            return b'(%s)' % s
+
+        spec = b'+'.join(pycompat.maplist(_formatspec, *specs))
+
+        drevs = querydrev(ui, spec)
+        if drevs:
+            return drevs
+
+    raise error.Abort(_(b"empty DREVSPEC set"))
+
+
 def readpatch(ui, drevs, write):
     """generate plain-text patch readable by 'hg import'