Skip to content

Commit

Permalink
Remove unused methods from Git
Browse files Browse the repository at this point in the history
Specifically, this removes:
  _commit_position_regex_for_timestamp
  timestamp_of_revision
  blame
  _branch_tracking_remote_master
  ensure_cleanly_tracking_remote_master

Most of these are unused since removing "webkit-patch auto-rebaseline".

Change-Id: I7422f7f32370b4348753439fdce47a35287866a5
Reviewed-on: https://chromium-review.googlesource.com/587341
Reviewed-by: Jeff Carpenter <jeffcarp@chromium.org>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490035}
  • Loading branch information
Quinten Yearsley authored and Commit Bot committed Jul 27, 2017
1 parent 1c34cc3 commit c124e9f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 64 deletions.
35 changes: 0 additions & 35 deletions third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,6 @@ def commit_position(self, path):
git_log = self.most_recent_log_matching('Cr-Commit-Position:', path)
return self._commit_position_from_git_log(git_log)

def _commit_position_regex_for_timestamp(self):
return 'Cr-Commit-Position:.*@{#%s}'

def timestamp_of_revision(self, path, revision):
git_log = self.most_recent_log_matching(self._commit_position_regex_for_timestamp() % revision, path)
match = re.search(r"^Date:\s*(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) ([+-])(\d{2})(\d{2})$", git_log, re.MULTILINE)
if not match:
return ''

# Manually modify the timezone since Git doesn't have an option to show it in UTC.
# Git also truncates milliseconds but we're going to ignore that for now.
time_with_timezone = datetime.datetime(int(match.group(1)), int(match.group(2)), int(match.group(3)),
int(match.group(4)), int(match.group(5)), int(match.group(6)), 0)

sign = 1 if match.group(7) == '+' else -1
time_without_timezone = time_with_timezone - \
datetime.timedelta(hours=sign * int(match.group(8)), minutes=int(match.group(9)))
return time_without_timezone.strftime('%Y-%m-%dT%H:%M:%SZ')

def create_patch(self, git_commit=None, changed_files=None):
"""Returns a byte array (str()) representing the patch file.
Expand Down Expand Up @@ -339,9 +320,6 @@ def checkout_branch(self, name):
def create_clean_branch(self, name):
self.run(['checkout', '-q', '-b', name, self._remote_branch_ref()])

def blame(self, path):
return self.run(['blame', '--show-email', path])

# Git-specific methods:
def _branch_ref_exists(self, branch_ref):
return self.run(['show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0
Expand Down Expand Up @@ -379,16 +357,3 @@ def git_commit_detail(self, commit, format=None): # pylint: disable=redefined-b
def affected_files(self, commit):
output = self.run(['log', '-1', '--format=', '--name-only', commit])
return output.strip().split('\n')

def _branch_tracking_remote_master(self):
origin_info = self.run(['remote', 'show', 'origin', '-n'])
match = re.search(r"^\s*(?P<branch_name>\S+)\s+merges with remote master$", origin_info, re.MULTILINE)
if not match:
raise ScriptError(message='Unable to find local branch tracking origin/master.')
branch = str(match.group('branch_name'))
return self._branch_from_ref(self.run(['rev-parse', '--symbolic-full-name', branch]).strip())

def ensure_cleanly_tracking_remote_master(self):
self._discard_working_directory_changes()
self.run(['checkout', '-q', self._branch_tracking_remote_master()])
self._discard_local_commits()
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def add_list(self, destination_paths, return_exit_code=False):
def has_working_directory_changes(self, pathspec=None):
return False

def ensure_cleanly_tracking_remote_master(self):
pass

def current_branch(self):
return 'mock-branch-name'

Expand Down Expand Up @@ -68,9 +65,6 @@ def commit_position_from_git_commit(self, git_commit):
return 10000
return None

def timestamp_of_revision(self, path, revision):
return '2013-02-01 08:48:05 +0000'

def commit_locally_with_message(self, message):
self._local_commits.append([message])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,36 +181,13 @@ def test_commit_position_from_git_log(self):
git = self.tracking_git
self.assertEqual(git._commit_position_from_git_log(git_log), 1234567)

def test_timestamp_of_revision(self):
# This tests a protected method. pylint: disable=protected-access
self._chdir(self.tracking_git_checkout_path)
git = self.tracking_git
position_regex = git._commit_position_regex_for_timestamp()
git.most_recent_log_matching(position_regex, git.checkout_root)


class GitTestWithMock(unittest.TestCase):

def make_git(self):
git = Git(cwd='.', executive=MockExecutive(), filesystem=MockFileSystem())
git.read_git_config = lambda *args, **kw: 'MOCKKEY:MOCKVALUE'
return git

def _assert_timestamp_of_revision(self, canned_git_output, expected):
git = self.make_git()
git.find_checkout_root = lambda path: ''
git.run = lambda args: canned_git_output
self.assertEqual(git.timestamp_of_revision('some-path', '12345'), expected)

def test_timestamp_of_revision_utc(self):
self._assert_timestamp_of_revision('Date: 2013-02-08 08:05:49 +0000', '2013-02-08T08:05:49Z')

def test_timestamp_of_revision_positive_timezone(self):
self._assert_timestamp_of_revision('Date: 2013-02-08 01:02:03 +0130', '2013-02-07T23:32:03Z')

def test_timestamp_of_revision_pacific_timezone(self):
self._assert_timestamp_of_revision('Date: 2013-02-08 01:55:21 -0800', '2013-02-08T09:55:21Z')

def test_unstaged_files(self):
git = self.make_git()
status_lines = [
Expand Down

0 comments on commit c124e9f

Please sign in to comment.