Patchwork [2,of,2] phabricator: teach {phabreview} to work without --amend

login
register
mail settings
Submitter Matt Harbison
Date Jan. 10, 2019, 4:28 a.m.
Message ID <bb9cd63d1cce015431a2.1547094519@Envy>
Download mbox | patch
Permalink /patch/37604/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 10, 2019, 4:28 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1546735830 18000
#      Sat Jan 05 19:50:30 2019 -0500
# Node ID bb9cd63d1cce015431a274a581021d8807cd9267
# Parent  0b7c3a31e42b075b5fc1d90c85f10239d87f9e33
phabricator: teach {phabreview} to work without --amend

There's some possibility of this being wrong (e.g. if the url config was
changed).  But commit messages can be amended too, so that isn't bulletproof
either.  Having something seems better than just returning None.

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -997,3 +997,17 @@  def template_review(context, mapping):
             b'url': m.group(b'url'),
             b'id': b"D{}".format(m.group(b'id')),
         })
+    else:
+        tags = ctx.repo().nodetags(ctx.node())
+        for t in tags:
+            if _differentialrevisiontagre.match(t):
+                url = ctx.repo().ui.config(b'phabricator', b'url')
+                if not url.endswith(b'/'):
+                    url += b'/'
+                url += t
+
+                return templateutil.hybriddict({
+                    b'url': url,
+                    b'id': t,
+                })
+    return None
diff --git a/tests/test-phabricator.t b/tests/test-phabricator.t
--- a/tests/test-phabricator.t
+++ b/tests/test-phabricator.t
@@ -106,13 +106,13 @@  behind to identify it.
 Template keywords
   $ hg log -T'{rev} {phabreview|json}\n'
   3 {"id": "D5545", "url": "https://phab.mercurial-scm.org/D5545"}
-  2 null
+  2 {"id": "D5544", "url": "https://phab.mercurial-scm.org/D5544"}
   1 {"id": "D4597", "url": "https://phab.mercurial-scm.org/D4597"}
   0 {"id": "D4596", "url": "https://phab.mercurial-scm.org/D4596"}
 
   $ hg log -T'{rev} {if(phabreview, "{phabreview.url} {phabreview.id}")}\n'
   3 https://phab.mercurial-scm.org/D5545 D5545
-  2 
+  2 https://phab.mercurial-scm.org/D5544 D5544
   1 https://phab.mercurial-scm.org/D4597 D4597
   0 https://phab.mercurial-scm.org/D4596 D4596