Commit 8e643693 authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

git cl: delete old support code for Git Numberer with Rietveld.

R=ehmaldonado

Change-Id: Ie5522283e84bdec9d98e236577eaad568816519b
Reviewed-on: https://chromium-review.googlesource.com/1242211Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent d4c86735
......@@ -916,57 +916,6 @@ def _get_gerrit_project_config_file(remote_url):
yield project_config_file
def _is_git_numberer_enabled(remote_url, remote_ref):
"""Returns True if Git Numberer is enabled on this ref."""
# TODO(tandrii): this should be deleted once repos below are 100% on Gerrit.
KNOWN_PROJECTS_WHITELIST = [
'chromium/src',
'external/webrtc',
'v8/v8',
'infra/experimental',
# For webrtc.googlesource.com/src.
'src',
]
assert remote_ref and remote_ref.startswith('refs/'), remote_ref
url_parts = urlparse.urlparse(remote_url)
project_name = url_parts.path.lstrip('/').rstrip('git./')
for known in KNOWN_PROJECTS_WHITELIST:
if project_name.endswith(known):
break
else:
# Early exit to avoid extra fetches for repos that aren't using Git
# Numberer.
return False
with _get_gerrit_project_config_file(remote_url) as project_config_file:
if project_config_file is None:
# Failed to fetch project.config, which shouldn't happen on open source
# repos KNOWN_PROJECTS_WHITELIST.
return False
def get_opts(x):
code, out = RunGitWithCode(
['config', '-f', project_config_file, '--get-all',
'plugin.git-numberer.validate-%s-refglob' % x])
if code == 0:
return out.strip().splitlines()
return []
enabled, disabled = map(get_opts, ['enabled', 'disabled'])
logging.info('validator config enabled %s disabled %s refglobs for '
'(this ref: %s)', enabled, disabled, remote_ref)
def match_refglobs(refglobs):
for refglob in refglobs:
if remote_ref == refglob or fnmatch.fnmatch(remote_ref, refglob):
return True
return False
if match_refglobs(disabled):
return False
return match_refglobs(enabled)
def ShortBranchName(branch):
"""Convert a name like 'refs/heads/foo' to just 'foo'."""
return branch.replace('refs/heads/', '', 1)
......
......@@ -1038,72 +1038,6 @@ class TestGitCl(TestCase):
'desc\n\nBUG=500658\nBUG=proj:1234',
[])
def test_git_numberer_not_whitelisted_repo(self):
self.calls = []
res = git_cl._is_git_numberer_enabled(
remote_url='https://chromium.googlesource.com/chromium/tools/build',
remote_ref='refs/whatever')
self.assertEqual(res, False)
def test_git_numberer_fail_fetch(self):
self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
self.calls = [
((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src',
'+refs/meta/config:refs/git_cl/meta/config'],), CERR1),
]
res = git_cl._is_git_numberer_enabled(
remote_url='https://chromium.googlesource.com/chromium/src',
remote_ref='refs/whatever')
self.assertEqual(res, False)
def test_git_numberer_valid_configs(self):
with git_cl.gclient_utils.temporary_directory() as tempdir:
@contextlib.contextmanager
def fake_temporary_directory(**kwargs):
yield tempdir
self.mock(git_cl.gclient_utils, 'temporary_directory',
fake_temporary_directory)
self._test_GitNumbererState_valid_configs_inner(tempdir)
def _test_GitNumbererState_valid_configs_inner(self, tempdir):
self.calls = [
((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src',
'+refs/meta/config:refs/git_cl/meta/config'],), ''),
((['git', 'show', 'refs/git_cl/meta/config:project.config'],),
'''
[plugin "git-numberer"]
validate-enabled-refglob = refs/else/*
validate-enabled-refglob = refs/heads/*
validate-disabled-refglob = refs/heads/disabled
validate-disabled-refglob = refs/branch-heads/*
'''),
((['git', 'config', '-f', os.path.join(tempdir, 'project.config') ,
'--get-all', 'plugin.git-numberer.validate-enabled-refglob'],),
'refs/else/*\n'
'refs/heads/*\n'),
((['git', 'config', '-f', os.path.join(tempdir, 'project.config') ,
'--get-all', 'plugin.git-numberer.validate-disabled-refglob'],),
'refs/heads/disabled\n'
'refs/branch-heads/*\n'),
] * 3 # 3 tests below have exactly the same IO.
res = git_cl._is_git_numberer_enabled(
remote_url='https://chromium.googlesource.com/chromium/src',
remote_ref='refs/heads/test')
self.assertEqual(res, True)
res = git_cl._is_git_numberer_enabled(
remote_url='https://chromium.googlesource.com/chromium/src',
remote_ref='refs/heads/disabled')
self.assertEqual(res, False)
# Validator is disabled by default, even if it's not explicitly in disabled
# refglobs.
res = git_cl._is_git_numberer_enabled(
remote_url='https://chromium.googlesource.com/chromium/src',
remote_ref='refs/arbitrary/ref')
self.assertEqual(res, False)
@classmethod
def _gerrit_ensure_auth_calls(cls, issue=None, skip_auth_check=False):
cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment