| Index: appengine/findit/common/git_repository.py
|
| diff --git a/appengine/findit/common/git_repository.py b/appengine/findit/common/git_repository.py
|
| index b4f5845455a0574c36f11207e39ceb575a4d9ca6..5078dbf9068b8de55fcbdacf113625ad7ef2eaee 100644
|
| --- a/appengine/findit/common/git_repository.py
|
| +++ b/appengine/findit/common/git_repository.py
|
| @@ -10,6 +10,7 @@ import re
|
|
|
| from common import diff
|
| from common import http_client_appengine
|
| +from common import repo_util
|
| from common.blame import Blame
|
| from common.blame import Region
|
| from common.cache_decorator import Cached
|
| @@ -18,13 +19,6 @@ from common.change_log import ChangeLog
|
| from common.change_log import FileChangeInfo
|
| from common.repository import Repository
|
|
|
| -
|
| -COMMIT_POSITION_PATTERN = re.compile(
|
| - '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE)
|
| -CODE_REVIEW_URL_PATTERN = re.compile(
|
| - '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE)
|
| -REVERTED_REVISION_PATTERN = re.compile(
|
| - '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE)
|
| TIMEZONE_PATTERN = re.compile('[-+]\d{4}$')
|
| CACHE_EXPIRE_TIME_SECONDS = 24 * 60 * 60
|
|
|
| @@ -69,49 +63,6 @@ class GitRepository(Repository):
|
| return None
|
| return base64.b64decode(content)
|
|
|
| - def ExtractCommitPositionAndCodeReviewUrl(self, message):
|
| - """Returns the commit position and code review url in the commit message.
|
| -
|
| - A "commit position" is something similar to SVN version ids; i.e.,
|
| - numeric identifiers which are issued in sequential order. The reason
|
| - we care about them is that they're easier for humans to read than
|
| - the hashes that Git uses internally for identifying commits. We
|
| - should never actually use them for *identifying* commits; they're
|
| - only for pretty printing to humans.
|
| -
|
| - Returns:
|
| - (commit_position, code_review_url)
|
| - """
|
| - if not message:
|
| - return (None, None)
|
| -
|
| - commit_position = None
|
| - code_review_url = None
|
| -
|
| - # Commit position and code review url are in the last 5 lines.
|
| - lines = message.strip().split('\n')[-5:]
|
| - lines.reverse()
|
| -
|
| - for line in lines:
|
| - if commit_position is None:
|
| - match = COMMIT_POSITION_PATTERN.match(line)
|
| - if match:
|
| - commit_position = int(match.group(1))
|
| -
|
| - if code_review_url is None:
|
| - match = CODE_REVIEW_URL_PATTERN.match(line)
|
| - if match:
|
| - code_review_url = match.group(1)
|
| - return (commit_position, code_review_url)
|
| -
|
| - def _NormalizeEmail(self, email):
|
| - """Normalizes the email from git repo.
|
| -
|
| - Some email is like: test@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538.
|
| - """
|
| - parts = email.split('@')
|
| - return '@'.join(parts[0:2])
|
| -
|
| def _GetDateTimeFromString(self, datetime_string,
|
| date_format='%a %b %d %H:%M:%S %Y'):
|
| if TIMEZONE_PATTERN.findall(datetime_string):
|
| @@ -136,21 +87,9 @@ class GitRepository(Repository):
|
| url = '%s/+/%s' % (self.repo_url, revision)
|
| return url, self._SendRequestForJsonResponse(url)
|
|
|
| - def GetRevertedRevision(self, message):
|
| - """Parse message to get the reverted revision if there is one."""
|
| - lines = message.strip().splitlines()
|
| - if not lines[0].lower().startswith('revert'):
|
| - return None
|
| -
|
| - for line in reversed(lines): # pragma: no cover
|
| - # TODO: Handle cases where no reverted_revision in reverting message.
|
| - reverted_revision_match = REVERTED_REVISION_PATTERN.match(line)
|
| - if reverted_revision_match:
|
| - return reverted_revision_match.group(1)
|
| -
|
| def _ParseChangeLogFromLogData(self, data):
|
| commit_position, code_review_url = (
|
| - self.ExtractCommitPositionAndCodeReviewUrl(data['message']))
|
| + repo_util.ExtractCommitPositionAndCodeReviewUrl(data['message']))
|
|
|
| touched_files = []
|
| for file_diff in data['tree_diff']:
|
| @@ -163,14 +102,15 @@ class GitRepository(Repository):
|
|
|
| author_time = self._GetDateTimeFromString(data['author']['time'])
|
| committer_time = self._GetDateTimeFromString(data['committer']['time'])
|
| - reverted_revision = self.GetRevertedRevision(data['message'])
|
| + reverted_revision = repo_util.GetRevertedRevision(data['message'])
|
| url = '%s/+/%s' % (self.repo_url, data['commit'])
|
|
|
| return ChangeLog(
|
| - data['author']['name'], self._NormalizeEmail(data['author']['email']),
|
| + data['author']['name'],
|
| + repo_util.NormalizeEmail(data['author']['email']),
|
| author_time,
|
| data['committer']['name'],
|
| - self._NormalizeEmail(data['committer']['email']),
|
| + repo_util.NormalizeEmail(data['committer']['email']),
|
| committer_time, data['commit'], commit_position,
|
| data['message'], touched_files, url, code_review_url,
|
| reverted_revision)
|
| @@ -238,7 +178,8 @@ class GitRepository(Repository):
|
| blame.AddRegion(
|
| Region(region['start'], region['count'], region['commit'],
|
| region['author']['name'],
|
| - self._NormalizeEmail(region['author']['email']), author_time))
|
| + repo_util.NormalizeEmail(region['author']['email']),
|
| + author_time))
|
|
|
| return blame
|
|
|
|
|