2016-04-27 19:50:13 +03:00
|
|
|
import re
|
2016-05-12 23:11:08 +03:00
|
|
|
from operator import itemgetter
|
2016-04-27 19:50:13 +03:00
|
|
|
|
2017-03-29 06:53:07 +03:00
|
|
|
diffrevisionregex = re.compile('^Differential Revision:.*/D(\d+)', re.M)
|
2017-01-09 12:37:48 +03:00
|
|
|
|
2016-04-27 19:50:13 +03:00
|
|
|
def parserevfromcommitmsg(description):
|
|
|
|
"""Parses the D123 revision number from a commit message.
|
|
|
|
Returns just the revision number without the D prefix.
|
|
|
|
Matches any URL as a candidate, not just our internal phabricator
|
|
|
|
host, so this can also work with our public phabricator instance,
|
|
|
|
or for others.
|
|
|
|
"""
|
2017-01-09 12:37:48 +03:00
|
|
|
match = diffrevisionregex.search(description)
|
2016-04-27 19:50:13 +03:00
|
|
|
return match.group(1) if match else None
|
|
|
|
|
2016-05-12 23:11:08 +03:00
|
|
|
def getcurrentdiffidforrev(client, phabrev):
|
|
|
|
"""Given a revision number (the 123 from D123), returns the current
|
|
|
|
diff id associated with that revision. """
|
|
|
|
|
|
|
|
res = client.call('differential.query', {'ids': [phabrev]})
|
|
|
|
if not res:
|
|
|
|
return None
|
|
|
|
|
|
|
|
info = res[0]
|
|
|
|
if not info:
|
|
|
|
return None
|
|
|
|
|
|
|
|
diffs = info.get('diffs', [])
|
|
|
|
if not diffs:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return max(diffs)
|
|
|
|
|
|
|
|
def getlocalcommitfordiffid(client, diffid):
|
|
|
|
"""Returns the most recent local:commits entry for a phabricator diff_id"""
|
|
|
|
|
|
|
|
res = client.call('differential.getdiffproperties', {
|
|
|
|
'diff_id': diffid,
|
|
|
|
'names': ['local:commits']})
|
|
|
|
if not res:
|
|
|
|
return None
|
|
|
|
|
|
|
|
localcommits = res.get('local:commits', {})
|
|
|
|
if not localcommits:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Order with most recent commit time first. A more completely correct
|
|
|
|
# implementation would toposort based on the parents properties, however,
|
|
|
|
# wez thinks that we should only contain a single entry most of the time,
|
|
|
|
# and our best prior art used to just take the first item that showed up
|
|
|
|
# in the dictionary. Sorting gives us some determinism, so we will at
|
|
|
|
# least be consistently wrong if we're wrong.
|
|
|
|
localcommits = sorted(localcommits.values(),
|
|
|
|
key=itemgetter('time'), reverse=True)
|
|
|
|
|
|
|
|
return localcommits[0]
|
|
|
|
|