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 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 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/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@bar') + 'foo' + >>> person(b'Foo Bar ') + 'Foo Bar' + >>> person(b'"Foo Bar" ') + 'Foo Bar' + >>> person(b'"Foo \"buz\" Bar" ') + 'Foo "buz" Bar' + >>> # The following are invalid, but do exist in real-life + ... + >>> person(b'Foo "buz" Bar ') + 'Foo "buz" Bar' + >>> person(b'"Foo 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='...')