changeset 44587:90adda73676a

phabricator: add a helper function to convert DREVSPECs to a DREV dict list Prep work for allowing multiple DREVSPECs to various commands, and properly validating the input. Differential Revision: https://phab.mercurial-scm.org/D8232
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 05 Mar 2020 11:00:00 -0500
parents f8427841c8fc
children a7f8c657a3f0
files hgext/phabricator.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Fri Mar 20 17:18:14 2020 +0900
+++ b/hgext/phabricator.py	Thu Mar 05 11:00:00 2020 -0500
@@ -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'