Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: appengine/findit/common/git_repository.py

Issue 2435863003: [Findit] Add local git parsers. (Closed)
Patch Set: Fix nits. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/findit/common/git_repository.py
diff --git a/appengine/findit/common/git_repository.py b/appengine/findit/common/git_repository.py
index c74aeb908f850172bc685ba771010d2170a20dfc..f95cacee80c791c2e3bb3117a70126af0a892845 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
@@ -86,49 +80,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):
@@ -153,21 +104,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']:
@@ -180,14 +119,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)
@@ -255,7 +195,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

Powered by Google App Engine
This is Rietveld 408576698