Remove some unused private things in git_cl

There are many functions in git_cl that appear unused, although
it's possible that some of them are used in other places, where
git_cl may be imported as a library.

This CL just removes some of the private ones, which at least
were not supposed to be used from other places.

Things removed here:

 - _get_commiter_timestamp
 - _git_amend_head
 - GitCookiesChecker._get_usernames_of_domain
 - constants MERGE_BRANCH, CHERRY_PICK_BRANCH;
   the comment says that these are supposed to
   be used in CMDland, but apparently they aren't.
   contextlib which is only used by this, is also
   removed
 - CodereviewSettingsFileMock in git_cl_test;
   it is not used anywhere in the test, and I
   assume that nobody's importing and using
   git_cl_test...

git_cl_test still passes, git cl seems to still work

Change-Id: Ib8eee0dfb181c8cda04c0894d2daea52b3ad42ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1818621
Reviewed-by: Andrii Shyshkalov <tandrii@google.com>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
changes/21/1818621/5
Quinten Yearsley 6 years ago committed by Commit Bot
parent 314adcb844
commit 90a67e2fc1

@ -13,7 +13,6 @@ from distutils.version import LooseVersion
from multiprocessing.pool import ThreadPool
import base64
import collections
import contextlib
import datetime
import httplib
import itertools
@ -313,26 +312,6 @@ def _git_set_branch_config_value(key, value, branch=None, **kwargs):
RunGit(args, **kwargs)
def _get_committer_timestamp(commit):
"""Returns Unix timestamp as integer of a committer in a commit.
Commit can be whatever git show would recognize, such as HEAD, sha1 or ref.
"""
# Git also stores timezone offset, but it only affects visual display;
# actual point in time is defined by this timestamp only.
return int(RunGit(['show', '-s', '--format=%ct', commit]).strip())
def _git_amend_head(message, committer_timestamp):
"""Amends commit with new message and desired committer_timestamp.
Sets committer timezone to UTC.
"""
env = os.environ.copy()
env['GIT_COMMITTER_DATE'] = '%d+0000' % committer_timestamp
return RunGit(['commit', '--amend', '-m', message], env=env)
def _get_properties_from_options(options):
properties = dict(x.split('=', 1) for x in options.properties)
for key, val in properties.iteritems():
@ -935,36 +914,6 @@ class Settings(object):
return RunGit(['config', param], **kwargs).strip()
@contextlib.contextmanager
def _get_gerrit_project_config_file(remote_url):
"""Context manager to fetch and store Gerrit's project.config from
refs/meta/config branch and store it in temp file.
Provides a temporary filename or None if there was error.
"""
error, _ = RunGitWithCode([
'fetch', remote_url,
'+refs/meta/config:refs/git_cl/meta/config'])
if error:
# Ref doesn't exist or isn't accessible to current user.
print('WARNING: Failed to fetch project config for %s: %s' %
(remote_url, error))
yield None
return
error, project_config_data = RunGitWithCode(
['show', 'refs/git_cl/meta/config:project.config'])
if error:
print('WARNING: project.config file not found')
yield None
return
with gclient_utils.temporary_directory() as tempdir:
project_config_file = os.path.join(tempdir, 'project.config')
gclient_utils.FileWrite(project_config_file, project_config_data)
yield project_config_file
def ShortBranchName(branch):
"""Convert a name like 'refs/heads/foo' to just 'foo'."""
return branch.replace('refs/heads/', '', 1)
@ -1094,7 +1043,6 @@ class Changelist(object):
self._remote = None
self._cached_remote_url = (False, None) # (is_cached, value)
self._change_id = None
# Lazily cached values.
self._gerrit_host = None # e.g. chromium-review.googlesource.com
self._gerrit_server = None # e.g. https://chromium-review.googlesource.com
@ -3354,14 +3302,6 @@ class _GitCookiesChecker(object):
username = username[len('git-'):]
return username, domain
def _get_usernames_of_domain(self, domain):
"""Returns list of usernames referenced by .gitcookies in a given domain."""
identities_by_domain = {}
for _, identity, _ in self.get_hosts_with_creds():
username, domain = self._parse_identity(identity)
identities_by_domain.setdefault(domain, []).append(username)
return identities_by_domain.get(domain)
def _canonical_git_googlesource_host(self, host):
"""Normalizes Gerrit hosts (with '-review') to Git host."""
assert host.endswith(self._GOOGLESOURCE)
@ -4541,11 +4481,6 @@ def CMDdcommit(parser, args):
return 1
# Two special branches used by git cl land.
MERGE_BRANCH = 'git-cl-commit'
CHERRY_PICK_BRANCH = 'git-cl-cherry-pick'
@subcommand.usage('[upstream branch to apply against]')
@metrics.collector.collect_metrics('git cl land')
def CMDland(parser, args):

@ -91,15 +91,6 @@ class WatchlistsMock(object):
return ['joe@example.com']
class CodereviewSettingsFileMock(object):
def __init__(self):
pass
# pylint: disable=no-self-use
def read(self):
return ('CODE_REVIEW_SERVER: gerrit.chromium.org\n' +
'GERRIT_HOST: True\n')
class AuthenticatorMock(object):
def __init__(self, *_args):
pass

Loading…
Cancel
Save