OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 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 """This module contains the SourceControl class and related functions.""" | 5 """This module contains the SourceControl class and related functions.""" |
6 | 6 |
7 import os | 7 import os |
8 import re | |
8 | 9 |
9 from . import bisect_utils | 10 from . import bisect_utils |
10 | 11 |
11 CROS_VERSION_PATTERN = 'new version number from %s' | 12 CROS_VERSION_PATTERN = 'new version number from %s' |
12 | 13 |
13 | 14 |
14 def DetermineAndCreateSourceControl(opts): | 15 def DetermineAndCreateSourceControl(opts): |
15 """Attempts to determine the underlying source control workflow and returns | 16 """Attempts to determine the underlying source control workflow and returns |
16 a SourceControl object. | 17 a SourceControl object. |
17 | 18 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 | 196 |
196 Returns: | 197 Returns: |
197 True if the current branch on src is 'master' | 198 True if the current branch on src is 'master' |
198 """ | 199 """ |
199 cmd = ['rev-parse', '--abbrev-ref', 'HEAD'] | 200 cmd = ['rev-parse', '--abbrev-ref', 'HEAD'] |
200 log_output = bisect_utils.CheckRunGit(cmd) | 201 log_output = bisect_utils.CheckRunGit(cmd) |
201 log_output = log_output.strip() | 202 log_output = log_output.strip() |
202 | 203 |
203 return log_output == "master" | 204 return log_output == "master" |
204 | 205 |
205 def SVNFindRev(self, revision, cwd=None): | 206 def SVNFindRev(self, git_revision, cwd=None): |
206 """Maps directly to the 'git svn find-rev' command. | 207 """Maps directly to the 'git svn find-rev' command. |
qyearsley
2014/08/26 22:42:34
The name and description probably should be update
prasadv
2014/08/26 23:07:30
Done.
| |
207 | 208 |
208 Args: | 209 Args: |
209 revision: The git SHA1 to use. | 210 revision: The git SHA1 to use. |
qyearsley
2014/08/26 22:42:34
Update docstring
prasadv
2014/08/26 23:07:30
Done.
| |
210 | 211 |
211 Returns: | 212 Returns: |
212 An integer changelist #, otherwise None. | 213 An integer changelist #, otherwise None. |
qyearsley
2014/08/26 22:42:34
This is now going to be git number (aka git commit
prasadv
2014/08/26 23:07:30
Done.
| |
213 """ | 214 """ |
214 | 215 |
215 cmd = ['svn', 'find-rev', revision] | 216 cmd = ['svn', 'find-rev', git_revision] |
216 | 217 |
217 output = bisect_utils.CheckRunGit(cmd, cwd) | 218 output = bisect_utils.CheckRunGit(cmd, cwd) |
218 svn_revision = output.strip() | 219 svn_revision = output.strip() |
219 | 220 |
220 if bisect_utils.IsStringInt(svn_revision): | 221 if bisect_utils.IsStringInt(svn_revision): |
221 return int(svn_revision) | 222 return int(svn_revision) |
222 | 223 |
224 # Retrieve commit position number from git log body for the given revision. | |
225 # TODO(prasadv): Use an appropriate command to find commit position instead | |
226 # of parsing the log. Resolve this once 407316 is fixed. | |
227 commit_position_pattern = 'Cr-Commit-Position: .*@\{#(?P<commit>[0-9]+)\}' | |
228 cmd = ['log', '--format=%b', '-1', 'origin/master', git_revision] | |
229 output = bisect_utils.CheckRunGit(cmd, cwd=cwd) | |
230 if output: | |
231 version_re = re.compile(commit_position_pattern) | |
232 commit_reg = version_re.search(output) | |
233 if commit_reg and bisect_utils.IsStringInt(commit_reg.group('commit')): | |
234 return int(commit_reg.group('commit')) | |
qyearsley
2014/08/26 22:42:34
This block is only executed when "git svn find-rev
prasadv
2014/08/26 23:07:30
Yes, basically everything in this method should be
| |
235 | |
223 return None | 236 return None |
224 | 237 |
225 def QueryRevisionInfo(self, revision, cwd=None): | 238 def QueryRevisionInfo(self, revision, cwd=None): |
226 """Gathers information on a particular revision, such as author's name, | 239 """Gathers information on a particular revision, such as author's name, |
227 email, subject, and date. | 240 email, subject, and date. |
228 | 241 |
229 Args: | 242 Args: |
230 revision: Revision you want to gather information on. | 243 revision: Revision you want to gather information on. |
231 | 244 |
232 Returns: | 245 Returns: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 revision_end: End of revision range. | 293 revision_end: End of revision range. |
281 | 294 |
282 Returns: | 295 Returns: |
283 Returns a list of commits that touched this file. | 296 Returns a list of commits that touched this file. |
284 """ | 297 """ |
285 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), | 298 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), |
286 '--', filename] | 299 '--', filename] |
287 output = bisect_utils.CheckRunGit(cmd) | 300 output = bisect_utils.CheckRunGit(cmd) |
288 | 301 |
289 return [o for o in output.split('\n') if o] | 302 return [o for o in output.split('\n') if o] |
OLD | NEW |