OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import base64 | 5 import base64 |
6 import json | 6 import json |
7 import re | 7 import re |
8 | 8 |
9 from common.blame import Blame | 9 from common.blame import Blame |
10 from common.blame import Region | 10 from common.blame import Region |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 return (commit_position, code_review_url) | 53 return (commit_position, code_review_url) |
54 | 54 |
55 | 55 |
56 def NormalizeEmail(email): | 56 def NormalizeEmail(email): |
57 """Normalize the email from git repo. | 57 """Normalize the email from git repo. |
58 | 58 |
59 Some email is like: person@@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538. | 59 Some email is like: person@@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538. |
60 """ | 60 """ |
61 parts = email.split('@') | 61 parts = email.split('@') |
62 return '@'.join(parts[:-1]) | 62 if len(parts) > 2: |
| 63 return '@'.join(parts[0:2]) |
| 64 else: |
| 65 return email |
63 | 66 |
64 | 67 |
65 class GitRepository(Repository): | 68 class GitRepository(Repository): |
66 """Represent a git repository on https://chromium.googlesource.com.""" | 69 """Represent a git repository on https://chromium.googlesource.com.""" |
67 | 70 |
68 def __init__(self, repo_url, http_client): | 71 def __init__(self, repo_url, http_client): |
69 super(GitRepository, self).__init__() | 72 super(GitRepository, self).__init__() |
70 self.repo_url = repo_url | 73 self.repo_url = repo_url |
71 if self.repo_url.endswith('/'): | 74 if self.repo_url.endswith('/'): |
72 self.repo_url = self.repo_url[:-1] | 75 self.repo_url = self.repo_url[:-1] |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return blame | 141 return blame |
139 | 142 |
140 def GetSource(self, path, revision): | 143 def GetSource(self, path, revision): |
141 """Return the source code of the file at |path| of the given revision.""" | 144 """Return the source code of the file at |path| of the given revision.""" |
142 url = '%s/+/%s/%s' % (self.repo_url, revision, path) | 145 url = '%s/+/%s/%s' % (self.repo_url, revision, path) |
143 | 146 |
144 status_code, content = self.http_client.Get(url, {'format': 'text'}) | 147 status_code, content = self.http_client.Get(url, {'format': 'text'}) |
145 if status_code != 200: | 148 if status_code != 200: |
146 return None | 149 return None |
147 return base64.b64decode(content) | 150 return base64.b64decode(content) |
OLD | NEW |