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

Unified Diff: appengine/findit/lib/gitiles/gitiles_repository.py

Issue 2435863003: [Findit] Add local git parsers. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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/lib/gitiles/gitiles_repository.py
diff --git a/appengine/findit/lib/gitiles/gitiles_repository.py b/appengine/findit/lib/gitiles/gitiles_repository.py
index 59aa97bf89f0d90abb804961066302b71897231d..e9725d69a823aca42e3e46354d17c0d7a61f555b 100644
--- a/appengine/findit/lib/gitiles/gitiles_repository.py
+++ b/appengine/findit/lib/gitiles/gitiles_repository.py
@@ -12,6 +12,7 @@ import re
from lib.cache_decorator import Cached
from lib.cache_decorator import CompressedMemCacher
from lib.gitiles import diff
+from lib.gitiles import repo_util
from lib.gitiles.blame import Blame
from lib.gitiles.blame import Region
from lib.gitiles.change_log import ChangeLog
@@ -31,6 +32,7 @@ CACHE_EXPIRE_TIME_SECONDS = 24 * 60 * 60
class GitilesRepository(GitRepository):
"""Use Gitiles to access a repository on https://chromium.googlesource.com."""
+ # TODO(crbug.com/659449): Refactor the http_client to be required argument.
def __init__(self, repo_url=None, http_client=None):
super(GitilesRepository, self).__init__()
if repo_url and repo_url.endswith('/'):
@@ -81,49 +83,6 @@ class GitilesRepository(GitRepository):
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):
@@ -148,21 +107,9 @@ class GitilesRepository(GitRepository):
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']:
@@ -175,14 +122,15 @@ class GitilesRepository(GitRepository):
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)
@@ -250,7 +198,8 @@ class GitilesRepository(GitRepository):
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