D3414: phabricator: specify some metadata compatibly with arc.

tom.prince (Tom Prince) phabricator at mercurial-scm.org
Thu Apr 19 01:06:29 UTC 2018


tom.prince created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  contrib/phabricator.py
  mercurial/templatefilters.py
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2341,6 +2341,33 @@
         r = None
     return author[author.find('<') + 1:r]
 
+def person(author):
+    """Any text. Returns the name before an email address,
+    interpreting it as per RFC 5322.
+
+    >>> person(b'foo at bar')
+    'foo'
+    >>> person(b'Foo Bar <foo at bar>')
+    'Foo Bar'
+    >>> person(b'"Foo Bar" <foo at bar>')
+    'Foo Bar'
+    >>> person(b'"Foo \"buz\" Bar" <foo at bar>')
+    'Foo "buz" Bar'
+    >>> # The following are invalid, but do exist in real-life
+    ...
+    >>> person(b'Foo "buz" Bar <foo at bar>')
+    'Foo "buz" Bar'
+    >>> person(b'"Foo Bar <foo at bar>')
+    'Foo Bar'
+    """
+    if '@' not in author:
+        return author
+    f = author.find('<')
+    if f != -1:
+        return author[:f].strip(' "').replace('\\"', '"')
+    f = author.find('@')
+    return author[:f].replace('.', ' ')
+
 def ellipsis(text, maxlength=400):
     """Trim string to at most maxlength (default: 400) columns in display."""
     return encoding.trim(text, maxlength, ellipsis='...')
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -297,13 +297,7 @@
     >>> person(b'"Foo Bar <foo at bar>')
     'Foo Bar'
     """
-    if '@' not in author:
-        return author
-    f = author.find('<')
-    if f != -1:
-        return author[:f].strip(' "').replace('\\"', '"')
-    f = author.find('@')
-    return author[:f].replace('.', ' ')
+    return util.person(author)
 
 @templatefilter('revescape')
 def revescape(text):
diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -306,6 +306,19 @@
     }
     callconduit(ctx.repo(), 'differential.setdiffproperty', params)
 
+    params = {
+        'diff_id': diff[r'id'],
+        'name': 'local:commits',
+        'data': json.dumps({
+            ctx.hex(): {
+                'author': util.person(ctx.user()),
+                'authorEmail': util.email(ctx.user()),
+                'time': ctx.date()[0],
+            },
+        }),
+    }
+    callconduit(ctx.repo(), 'differential.setdiffproperty', params)
+
 def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None,
                                olddiff=None, actions=None):
     """create or update a Differential Revision



To: tom.prince, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list