[PATCH 01 of 10] phabricator: check associated Differential Revision from commit message

Jun Wu quark at fb.com
Wed Jul 5 01:58:26 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1499210197 25200
#      Tue Jul 04 16:16:37 2017 -0700
# Node ID 650ef9794f032c216e85476db39170a52041260f
# Parent  895ecec31c705fcafeb3e16f9b0e2933e3ffdf8f
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 650ef9794f03
phabricator: check associated Differential Revision from commit message

Previously, only tags can "associate" a changeset to a Differential
Revision. But the usual pattern (arc patch or hg phabread) is to put the
Differential Revision URL in commit message.

This patch makes the code read commit message to find associated
Differential Revision if associated tags are not found.

This makes some workflows possible. For example, if the author loses their
repo, or switch to another computer, they can continue download their own
patches from Phabricator and update them without needing to manually create
tags.

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -136,5 +136,7 @@ def getrepophid(repo):
     return repophid
 
-_differentialrevisionre = re.compile('\AD([1-9][0-9]*)\Z')
+_differentialrevisiontagre = re.compile('\AD([1-9][0-9]*)\Z')
+_differentialrevisiondescre = re.compile(
+    '^Differential Revision:.*D([1-9][0-9]*)$', re.M)
 
 def getmapping(ctx):
@@ -144,13 +146,24 @@ def getmapping(ctx):
     considered a match and the node with that tag, and the number after "D"
     (ex. 1234) will be returned.
+
+    If tags are not found, examine commit message. The "Differential Revision:"
+    line could associate this changeset to a Differential Revision.
     """
     unfi = ctx.repo().unfiltered()
     nodemap = unfi.changelog.nodemap
+
+    # Check tags like "D123"
     for n in obsolete.allprecursors(unfi.obsstore, [ctx.node()]):
         if n in nodemap:
             for tag in unfi.nodetags(n):
-                m = _differentialrevisionre.match(tag)
+                m = _differentialrevisiontagre.match(tag)
                 if m:
                     return n, int(m.group(1))
+
+    # Check commit message
+    m = _differentialrevisiondescre.search(ctx.description())
+    if m:
+        return None, int(m.group(1))
+
     return None, None
 


More information about the Mercurial-devel mailing list