2013-11-16 02:55:42 +04:00
|
|
|
# phrevset.py - support for Phabricator revsets
|
|
|
|
#
|
|
|
|
# Copyright 2013 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
"""provides support for Phabricator revsets
|
|
|
|
|
|
|
|
Allows for queries such as `hg log -r D1234567` to find the commit which
|
|
|
|
corresponds to a specific Differential revision.
|
|
|
|
Automatically handles commits already in subversion, or whose hash has
|
|
|
|
changed since submitting to Differential (due to amends or rebasing).
|
|
|
|
|
|
|
|
Requires arcanist to be installed and properly configured.
|
|
|
|
Repositories should include a callsign in their hgrc.
|
|
|
|
|
|
|
|
Example for www:
|
|
|
|
|
|
|
|
[phrevset]
|
|
|
|
callsign = E
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2017-10-24 06:02:57 +03:00
|
|
|
from mercurial import (
|
|
|
|
error,
|
|
|
|
extensions,
|
|
|
|
hg,
|
|
|
|
registrar,
|
|
|
|
revset,
|
|
|
|
smartset,
|
|
|
|
)
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
from mercurial.i18n import _
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2016-07-20 22:09:29 +03:00
|
|
|
try:
|
|
|
|
from hgsubversion import util as svnutil
|
|
|
|
except ImportError:
|
|
|
|
svnutil = None
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2013-12-13 02:49:04 +04:00
|
|
|
import os
|
|
|
|
import signal
|
2013-11-16 02:55:42 +04:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
|
2017-10-24 06:02:57 +03:00
|
|
|
configtable = {}
|
|
|
|
configitem = registrar.configitem(configtable)
|
|
|
|
|
|
|
|
configitem('phrevset', 'callsign', default=None)
|
|
|
|
|
2013-11-16 02:55:42 +04:00
|
|
|
DIFFERENTIAL_REGEX = re.compile(
|
|
|
|
'Differential Revision: http.+?/' # Line start, URL
|
|
|
|
'D(?P<id>[0-9]+)', # Differential ID, just numeric part
|
|
|
|
flags = re.LOCALE
|
|
|
|
)
|
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
DESCRIPTION_REGEX = re.compile(
|
2013-11-16 02:55:42 +04:00
|
|
|
'Commit r' # Prefix
|
2014-07-25 07:27:05 +04:00
|
|
|
'(?P<callsign>[A-Z]{1,})' # Callsign
|
|
|
|
'(?P<id>[a-f0-9]+)', # rev
|
2013-11-16 02:55:42 +04:00
|
|
|
flags = re.LOCALE
|
|
|
|
)
|
|
|
|
|
2014-07-25 06:36:09 +04:00
|
|
|
def getdiff(repo, diffid):
|
2013-11-16 02:55:42 +04:00
|
|
|
"""Perform a Conduit API call by shelling out to `arc`
|
|
|
|
|
|
|
|
Returns a subprocess.Popen instance"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
proc = subprocess.Popen(['arc', 'call-conduit', 'differential.getdiff'],
|
2016-01-08 05:30:24 +03:00
|
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
|
|
preexec_fn=os.setsid)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
input = json.dumps({'revision_id': diffid})
|
2016-01-08 05:30:24 +03:00
|
|
|
repo.ui.debug("[diffrev] echo '%s' | "
|
|
|
|
"arc call-conduit differential.getdiff\n" % input)
|
2013-11-16 02:55:42 +04:00
|
|
|
proc.stdin.write(input)
|
|
|
|
proc.stdin.close()
|
|
|
|
|
|
|
|
return proc
|
2016-01-08 05:30:24 +03:00
|
|
|
except Exception as e:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('Could not not call "arc call-conduit": %s' % e)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
def finddiff(repo, diffid, proc=None):
|
|
|
|
"""Scans the changelog for commit lines mentioning the Differential ID
|
|
|
|
|
2016-04-04 22:48:01 +03:00
|
|
|
If the optional proc parameter is provided, it must be a subprocess.Popen
|
2013-11-16 02:55:42 +04:00
|
|
|
instance. It will be polled during the iteration and if it indicates that
|
|
|
|
the process has returned, the function will raise StopIteration"""
|
|
|
|
|
|
|
|
repo.ui.debug('[diffrev] Traversing log for %s\n' % diffid)
|
|
|
|
|
|
|
|
# traverse the changelog backwards
|
|
|
|
for rev in repo.changelog.revs(start=len(repo.changelog), stop=0):
|
|
|
|
if rev % 100 == 0 and proc and proc.poll() is not None:
|
|
|
|
raise StopIteration("Parallel proc call completed")
|
|
|
|
|
|
|
|
changectx = repo[rev]
|
|
|
|
desc = changectx.description()
|
|
|
|
match = DIFFERENTIAL_REGEX.search(desc)
|
|
|
|
|
|
|
|
if match and match.group('id') == diffid:
|
2014-07-25 06:36:09 +04:00
|
|
|
return changectx.rev()
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def forksearch(repo, diffid):
|
|
|
|
"""Perform a log traversal and Conduit call in parallel
|
|
|
|
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
Returns a (revisions, arc_response) tuple, where one of the items will be
|
2013-11-16 02:55:42 +04:00
|
|
|
None, depending on which process terminated first"""
|
|
|
|
|
|
|
|
repo.ui.debug('[diffrev] Starting Conduit call\n')
|
|
|
|
|
2014-07-25 06:36:09 +04:00
|
|
|
proc = getdiff(repo, diffid)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
repo.ui.debug('[diffrev] Starting log walk\n')
|
|
|
|
rev = finddiff(repo, diffid, proc)
|
|
|
|
|
|
|
|
repo.ui.debug('[diffrev] Parallel log walk completed with %s\n' % rev)
|
2013-12-13 02:49:04 +04:00
|
|
|
os.killpg(proc.pid, signal.SIGTERM)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
if rev is None:
|
|
|
|
# walked the entire repo and couldn't find the diff
|
2016-10-11 21:13:58 +03:00
|
|
|
raise error.Abort('Could not find diff D%s in changelog' % diffid)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
return ([rev], None)
|
|
|
|
|
|
|
|
except StopIteration:
|
|
|
|
# search terminated because arc returned
|
|
|
|
# if returncode == 0, return arc's output
|
|
|
|
|
|
|
|
repo.ui.debug('[diffrev] Conduit call returned %i\n' % proc.returncode)
|
|
|
|
|
|
|
|
if proc.returncode != 0:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('arc call returned status %i' % proc.returncode)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
resp = proc.stdout.read()
|
|
|
|
return (None, resp)
|
|
|
|
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
def parsedesc(repo, resp, ignoreparsefailure):
|
2014-07-25 07:27:05 +04:00
|
|
|
desc = resp['description']
|
2016-02-27 02:09:16 +03:00
|
|
|
if desc is None:
|
|
|
|
if ignoreparsefailure:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
raise error.Abort("No Conduit description")
|
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
match = DESCRIPTION_REGEX.match(desc)
|
|
|
|
|
|
|
|
if not match:
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
if ignoreparsefailure:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
raise error.Abort("Cannot parse Conduit description '%s'"
|
|
|
|
% desc)
|
2014-07-25 07:27:05 +04:00
|
|
|
|
|
|
|
callsign = match.group('callsign')
|
|
|
|
repo_callsign = repo.ui.config('phrevset', 'callsign')
|
|
|
|
|
|
|
|
if callsign != repo_callsign:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort("Diff callsign '%s' is different from repo"
|
2014-07-25 07:27:05 +04:00
|
|
|
" callsign '%s'" % (callsign, repo_callsign))
|
|
|
|
|
|
|
|
return match.group('id')
|
|
|
|
|
2013-11-16 02:55:42 +04:00
|
|
|
def revsetdiff(repo, subset, diffid):
|
|
|
|
"""Return a set of revisions corresponding to a given Differential ID """
|
|
|
|
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
repo_callsign = repo.ui.config('phrevset', 'callsign')
|
|
|
|
if repo_callsign is None:
|
|
|
|
msg = _('phrevset.callsign is not set - doing a linear search\n')
|
|
|
|
hint = _('This will be slow if the diff was not committed recently\n')
|
|
|
|
repo.ui.warn(msg)
|
|
|
|
repo.ui.warn(hint)
|
|
|
|
rev = finddiff(repo, diffid)
|
|
|
|
if rev is None:
|
|
|
|
raise error.Abort('Could not find diff D%s in changelog' % diffid)
|
|
|
|
else:
|
|
|
|
return [rev]
|
2013-11-16 02:55:42 +04:00
|
|
|
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
revs, resp = forksearch(repo, diffid)
|
|
|
|
|
|
|
|
if revs is not None:
|
2013-11-16 02:55:42 +04:00
|
|
|
# The log walk found the diff, nothing more to do
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
return revs
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
jsresp = json.loads(resp)
|
|
|
|
if not jsresp:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('Could not decode Conduit response')
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
resp = jsresp.get('response')
|
|
|
|
if not resp:
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
e = jsresp.get('errorMessage', 'unknown error')
|
2016-04-04 22:48:01 +03:00
|
|
|
raise error.Abort('Conduit error: %s' % e)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
vcs = resp.get('sourceControlSystem')
|
|
|
|
|
|
|
|
repo.ui.debug('[diffrev] VCS is %s\n' % vcs)
|
|
|
|
|
2016-07-20 22:09:29 +03:00
|
|
|
if vcs == 'svn' and svnutil:
|
2013-11-16 02:55:42 +04:00
|
|
|
# commit has landed in svn, parse the description to get the SVN
|
|
|
|
# revision and delegate to hgsubversion for the rest
|
|
|
|
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
svnrev = parsedesc(repo, resp, ignoreparsefailure=False)
|
2014-07-25 07:27:05 +04:00
|
|
|
repo.ui.debug("[diffrev] SVN rev is r%s\n" % svnrev)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
args = ('string', svnrev)
|
|
|
|
return svnutil.revset_svnrev(repo, subset, args)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
elif vcs == 'git':
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
gitrev = parsedesc(repo, resp, ignoreparsefailure=False)
|
2014-07-25 07:27:05 +04:00
|
|
|
repo.ui.debug("[diffrev] GIT rev is %s\n" % gitrev)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
peerpath = repo.ui.expandpath('default')
|
|
|
|
remoterepo = hg.peer(repo, {}, peerpath)
|
|
|
|
remoterev = remoterepo.lookup('_gitlookup_git_%s' % gitrev)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
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')
|
2017-04-24 19:47:52 +03:00
|
|
|
linear_search_result = finddiff(repo, diffid)
|
|
|
|
if linear_search_result is None:
|
|
|
|
# walked the entire repo and couldn't find the diff
|
|
|
|
raise error.Abort(
|
|
|
|
'Could not find diff D%s in changelog' % diffid)
|
|
|
|
|
|
|
|
return [linear_search_result]
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2014-07-25 07:27:05 +04:00
|
|
|
return [repo[remoterev].rev()]
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
elif vcs == 'hg':
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
rev = parsedesc(repo, resp, ignoreparsefailure=True)
|
|
|
|
if rev:
|
2016-10-11 21:13:58 +03:00
|
|
|
# The response from phabricator contains a changeset ID.
|
|
|
|
# Convert it back to a rev number.
|
|
|
|
try:
|
|
|
|
node = repo[rev.encode('utf-8')]
|
|
|
|
except error.RepoLookupError:
|
|
|
|
raise error.Abort('Landed commit for diff D%s not available '
|
|
|
|
'in current repository: run "hg pull" '
|
|
|
|
'to retrieve it' % diffid)
|
|
|
|
return [node.rev()]
|
Don't crash in phrevset if Conduit replies before linear search completes
Summary:
When converting a Diff number to a revset, phrevset would do a linear scan of the repo history for the most recent appearance of that Diff number (slow if it's an older commit or not present in this repo) and in parallel, query Phabricator Conduit to try and shortcut the process.
Unfortunately, if Conduit was quicker than the linear scan, we would crash because we can't handle a Conduit response for hg commits made when a Diff lands, or for any repo that doesn't have a callsign in hgrc.
Fix the crashes; don't bother calling Conduit if we can't handle any reasonable answer, and teach the hg branch to handle all reasonable answers.
Test Plan:
Check that the new extension does linear search unconditionally when it lacks a callsign:
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
phrevset.callsign is not set - doing a linear search
changeset: 3c0e6756bed4d7330391719bcde52e7490499e53 D2750128
user: Yuhan Guo <yhguo@fb.com>
date: Thu, 07 Jan 2016 00:19:23 -0800
```
Check that it doesn't do a linear search in a repo with a callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ echo -e '[phrevset]\ncallsign=E' >> .hg/hgrc
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
changeset: 4b24ee6737b7e36523eb24c6406d689cc54aadf9 D2704940
user: xifanyan@2c7ba8d8-a2f7-0310-a573-de162e16dcc7
date: Mon, 30 Nov 2015 23:38:18 -0800
```
Check that it aborts cleanly if you give it a Diff from a different repo in a repo with a known callsign:
```
: /data/users/simonfar/www-hg (hg) [webacademy-graphql]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2750128
abort: Diff callsign 'FBS' is different from repo callsign 'E'
```
Check that linear scan eventually aborts cleanly if you give it a Diff from a different repo (note: this step is slow - over a minute on my devvm):
```
: /data/users/simonfar/fbsource (hg) [90234606e65a2a04d042caba7cf5ee85a7a5466e]
: simonfar@devvm631 $ hg --config extensions.phrevset=/data/users/simonfar/fb-hgext/phrevset.py log -r D2704940
phrevset.callsign is not set - doing a linear search
abort: Could not find diff D2704940 in changelog
```
Reviewers: #sourcecontrol, rmcelroy, ttung, lcharignon
Reviewed By: lcharignon
Subscribers: lcharignon, kanishkparihar
Differential Revision: https://phabricator.fb.com/D2844832
Tasks: 9723813, 9714886
Signature: t1:2844832:1453321767:f445447d8187b4be22db3065ba316e6aa461f757
2016-01-21 19:11:13 +03:00
|
|
|
|
|
|
|
# commit is still local, get its hash
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
props = resp['properties']
|
|
|
|
commits = props['local:commits']
|
|
|
|
|
|
|
|
# the JSON parser returns Unicode strings, convert to `str` in UTF-8
|
|
|
|
revs = [c['commit'].encode('utf-8') for c in commits.values()]
|
|
|
|
|
|
|
|
# verify all revisions exist in the current repo; if not, try to
|
|
|
|
# find their counterpart by parsing the log
|
2017-10-16 22:55:16 +03:00
|
|
|
results = set()
|
|
|
|
for rev in revs:
|
|
|
|
# TODO: This really should be searching in repo.unfiltered(),
|
|
|
|
# and then resolving successors if the commit was hidden.
|
|
|
|
try:
|
|
|
|
node = repo[rev.encode('utf-8')]
|
|
|
|
results.add(node.rev())
|
|
|
|
except error.RepoLookupError:
|
2016-02-27 02:09:16 +03:00
|
|
|
repo.ui.warn(_('Commit not found - doing a linear search\n'))
|
2013-11-16 02:55:42 +04:00
|
|
|
parsed_rev = finddiff(repo, diffid)
|
|
|
|
|
|
|
|
if not parsed_rev:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('Could not find diff '
|
2013-11-16 02:55:42 +04:00
|
|
|
'D%s in changelog' % diffid)
|
|
|
|
|
2017-10-16 22:55:16 +03:00
|
|
|
results.add(parsed_rev)
|
|
|
|
|
|
|
|
if not results:
|
|
|
|
raise error.Abort('Could not find local commit for D%s' % diffid)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2017-10-16 22:55:16 +03:00
|
|
|
return set(results)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
else:
|
|
|
|
if not vcs:
|
|
|
|
msg = "D%s does not have an associated version control system\n" \
|
|
|
|
"You can view the diff at http://phabricator.fb.com/D%s\n\n"
|
|
|
|
repo.ui.warn(msg % (diffid, diffid))
|
|
|
|
|
|
|
|
return []
|
|
|
|
else:
|
2016-01-08 05:30:24 +03:00
|
|
|
raise error.Abort('Conduit returned unknown '
|
2013-11-16 02:55:42 +04:00
|
|
|
'sourceControlSystem "%s"' % vcs)
|
|
|
|
|
2017-08-30 23:17:20 +03:00
|
|
|
def revsetstringset(orig, repo, subset, revstr, *args, **kwargs):
|
2013-11-16 02:55:42 +04:00
|
|
|
"""Wrapper that recognizes revisions starting with 'D'"""
|
|
|
|
|
|
|
|
if revstr.startswith('D') and revstr[1:].isdigit():
|
2017-04-24 19:47:52 +03:00
|
|
|
return smartset.baseset(revsetdiff(repo, subset, revstr[1:]))
|
2013-11-16 02:55:42 +04:00
|
|
|
|
2017-08-30 23:17:20 +03:00
|
|
|
return orig(repo, subset, revstr, *args, **kwargs)
|
2013-11-16 02:55:42 +04:00
|
|
|
|
|
|
|
def extsetup(ui):
|
|
|
|
extensions.wrapfunction(revset, 'stringset', revsetstringset)
|
2015-05-12 21:14:44 +03:00
|
|
|
revset.methods['string'] = revset.stringset
|
|
|
|
revset.methods['symbol'] = revset.stringset
|
|
|
|
|