[phrevset] Add ability to parse git revisions from Phabricator

Summary:
We couldn't handle the git case (fbandroid-hg) at all. This fixes that.

I changed my .hg/hgrc to have
```[phrevset]
callsign = FA```
but I've no idea how to do that globally.

Test Plan:
```
[diffrev] Starting Conduit call
[diffrev] echo '{"revision_id": "1153911"}' | arc call-conduit differential.getdiff
[diffrev] Starting log walk
[diffrev] Traversing log for 1153911
[diffrev] Conduit call returned 0
[diffrev] VCS is git
[diffrev] GIT rev is 34838a7f1d68531f385e471bf76f89c6620ea563
Path: ssh://hg.vip.facebook.com//data/scm/fbandroid opts: {}
running ssh hg.vip.facebook.com 'hg -R /data/scm/fbandroid serve --stdio'
sending hello command
sending between command
remote: 199
remote: capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream-preferred streamreqs=lz4revlog,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024 remotefilelog
remote: 1
sending lookup command
[diffrev] HG rev is e67eac10eef35a21a3b61f8aa8caa330884d48d4
...
```

Reviewers: sid0, davidsp

Reviewed By: davidsp

Differential Revision: https://phabricator.fb.com/D1458491
This commit is contained in:
Delyan Kratunov 2014-07-24 20:27:05 -07:00
parent c0418e22e8
commit eea8a70884

View File

@ -22,6 +22,7 @@ callsign = E
"""
from mercurial import hg
from mercurial import extensions
from mercurial import revset
from mercurial import util as hgutil
@ -40,10 +41,10 @@ DIFFERENTIAL_REGEX = re.compile(
flags = re.LOCALE
)
SVN_DESCRIPTION_REGEX = re.compile(
DESCRIPTION_REGEX = re.compile(
'Commit r' # Prefix
'(?P<callsign>[^0-9]{1,})' # Callsign
'(?P<id>[0-9]+)', # SVN rev
'(?P<callsign>[A-Z]{1,})' # Callsign
'(?P<id>[a-f0-9]+)', # rev
flags = re.LOCALE
)
@ -124,6 +125,23 @@ def forksearch(repo, diffid):
resp = proc.stdout.read()
return (None, resp)
def parsedesc(repo, resp):
desc = resp['description']
match = DESCRIPTION_REGEX.match(desc)
if not match:
raise hgutil.Abort("Cannot parse Conduit description '%s'"
% desc)
callsign = match.group('callsign')
repo_callsign = repo.ui.config('phrevset', 'callsign')
if callsign != repo_callsign:
raise hgutil.Abort("Diff callsign '%s' is different from repo"
" callsign '%s'" % (callsign, repo_callsign))
return match.group('id')
def revsetdiff(repo, subset, diffid):
"""Return a set of revisions corresponding to a given Differential ID """
@ -150,26 +168,27 @@ def revsetdiff(repo, subset, diffid):
# commit has landed in svn, parse the description to get the SVN
# revision and delegate to hgsubversion for the rest
desc = resp['description']
match = SVN_DESCRIPTION_REGEX.match(desc)
if not match:
raise hgutil.Abort("Cannot parse Conduit SVN description '%s'"
% desc)
callsign = match.group('callsign')
repo_callsign = repo.ui.config('phrevset', 'callsign')
if callsign != repo_callsign:
raise hgutil.Abort("Diff callsign '%s' is different from repo"
" callsign '%s'" % (callsign, repo_callsign))
svnrev = match.group('id')
svnrev = parsedesc(repo, resp)
repo.ui.debug("[diffrev] SVN rev is r%s\n" % svnrev)
args = ('string', svnrev)
return svnutil.revset_svnrev(repo, subset, args)
elif vcs == 'git':
gitrev = parsedesc(repo, resp)
repo.ui.debug("[diffrev] GIT rev is %s\n" % gitrev)
peerpath = repo.ui.expandpath('default')
remoterepo = hg.peer(repo, {}, peerpath)
remoterev = remoterepo.lookup('_gitlookup_git_%s' % gitrev)
repo.ui.debug("[diffrev] HG rev is %s\n" % remoterev.encode('hex'))
if not remoterev:
repo.ui.debug('[diffrev] Falling back to linear search\n')
return finddiff(repo, diffid)
return [repo[remoterev].rev()]
elif vcs == 'hg':
# commit is still in hg, get its hash