[Differential] [Closed] D34: phabricator: finding old nodes in batch

quark (Jun Wu) phabricator at mercurial-scm.org
Fri Jul 14 17:25:06 UTC 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG3ab0d5767b54: phabricator: finding old nodes in batch (authored by quark).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D34?vs=50&id=140

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

AFFECTED FILES
  contrib/phabricator.py

CHANGE DETAILS

Index: contrib/phabricator.py
===================================================================
--- contrib/phabricator.py
+++ contrib/phabricator.py
@@ -139,33 +139,42 @@
 _differentialrevisiondescre = re.compile(
     '^Differential Revision:.*D([1-9][0-9]*)$', re.M)
 
-def getmapping(ctx):
-    """return (node, associated Differential Revision ID) or (None, None)
+def getoldnodedrevmap(repo, nodelist):
+    """find previous nodes that has been sent to Phabricator
+
+    return {node: (oldnode or None, Differential Revision ID)}
+    for node in nodelist with known previous sent versions, or associated
+    Differential Revision IDs.
 
     Examines all precursors and their tags. Tags with format like "D1234" are
     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()
+    url, token = readurltoken(repo)
+    unfi = 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 = _differentialrevisiontagre.match(tag)
-                if m:
-                    return n, int(m.group(1))
+    result = {} # {node: (oldnode or None, drev)}
+    for node in nodelist:
+        ctx = unfi[node]
+        # Check tags like "D123"
+        for n in obsolete.allprecursors(unfi.obsstore, [node]):
+            if n in nodemap:
+                for tag in unfi.nodetags(n):
+                    m = _differentialrevisiontagre.match(tag)
+                    if m:
+                        result[node] = (n, int(m.group(1)))
+                        continue
 
-    # Check commit message
-    m = _differentialrevisiondescre.search(ctx.description())
-    if m:
-        return None, int(m.group(1))
+        # Check commit message
+        m = _differentialrevisiondescre.search(ctx.description())
+        if m:
+            result[node] = (None, int(m.group(1)))
 
-    return None, None
+    return result
 
 def getdiff(ctx, diffopts):
     """plain-text diff without header (user, commit message, etc)"""
@@ -274,15 +283,17 @@
     if not revs:
         raise error.Abort(_('phabsend requires at least one changeset'))
 
+    oldnodedrev = getoldnodedrevmap(repo, [repo[r].node() for r in revs])
+
     # Send patches one by one so we know their Differential Revision IDs and
     # can provide dependency relationship
     lastrevid = None
     for rev in revs:
         ui.debug('sending rev %d\n' % rev)
         ctx = repo[rev]
 
         # Get Differential Revision ID
-        oldnode, revid = getmapping(ctx)
+        oldnode, revid = oldnodedrev.get(ctx.node(), (None, None))
         if oldnode != ctx.node():
             # Create or update Differential Revision
             revision = createdifferentialrevision(ctx, revid, lastrevid,


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

To: quark, durin42
Cc: mercurial-devel


More information about the Mercurial-devel mailing list