| 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 """Finds a SVN revision OR git number for the given git hash. |
| 208 |
| 209 If "git svn find_rev <hash>" fails, then it runs |
| 210 "git log --format=%b -1 origin/master <hash> and greps for |
| 211 Cr-Commit-Position. |
| 207 | 212 |
| 208 Args: | 213 Args: |
| 209 revision: The git SHA1 to use. | 214 git_revision: The git SHA1 to use. |
| 210 | 215 |
| 211 Returns: | 216 Returns: |
| 212 An integer changelist #, otherwise None. | 217 Git number (aka git commit position) OR an SVN revision as integer, |
| 218 otherwise None. |
| 213 """ | 219 """ |
| 214 | 220 |
| 215 cmd = ['svn', 'find-rev', revision] | 221 cmd = ['svn', 'find-rev', git_revision] |
| 216 | 222 |
| 217 output = bisect_utils.CheckRunGit(cmd, cwd) | 223 output = bisect_utils.CheckRunGit(cmd, cwd) |
| 218 svn_revision = output.strip() | 224 svn_revision = output.strip() |
| 219 | 225 |
| 220 if bisect_utils.IsStringInt(svn_revision): | 226 if bisect_utils.IsStringInt(svn_revision): |
| 221 return int(svn_revision) | 227 return int(svn_revision) |
| 222 | 228 |
| 229 # Retrieve commit position number from git log body for the given revision. |
| 230 # TODO(prasadv): Use an appropriate command to find commit position instead |
| 231 # of parsing the log. Resolve this once 407316 is fixed. |
| 232 commit_position_pattern = 'Cr-Commit-Position: .*@\{#(?P<commit>[0-9]+)\}' |
| 233 cmd = ['log', '--format=%b', '-1', 'origin/master', git_revision] |
| 234 output = bisect_utils.CheckRunGit(cmd, cwd=cwd) |
| 235 if output: |
| 236 version_re = re.compile(commit_position_pattern) |
| 237 commit_reg = version_re.search(output) |
| 238 if commit_reg and bisect_utils.IsStringInt(commit_reg.group('commit')): |
| 239 return int(commit_reg.group('commit')) |
| 240 |
| 223 return None | 241 return None |
| 224 | 242 |
| 225 def QueryRevisionInfo(self, revision, cwd=None): | 243 def QueryRevisionInfo(self, revision, cwd=None): |
| 226 """Gathers information on a particular revision, such as author's name, | 244 """Gathers information on a particular revision, such as author's name, |
| 227 email, subject, and date. | 245 email, subject, and date. |
| 228 | 246 |
| 229 Args: | 247 Args: |
| 230 revision: Revision you want to gather information on. | 248 revision: Revision you want to gather information on. |
| 231 | 249 |
| 232 Returns: | 250 Returns: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 revision_end: End of revision range. | 298 revision_end: End of revision range. |
| 281 | 299 |
| 282 Returns: | 300 Returns: |
| 283 Returns a list of commits that touched this file. | 301 Returns a list of commits that touched this file. |
| 284 """ | 302 """ |
| 285 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), | 303 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), |
| 286 '--', filename] | 304 '--', filename] |
| 287 output = bisect_utils.CheckRunGit(cmd) | 305 output = bisect_utils.CheckRunGit(cmd) |
| 288 | 306 |
| 289 return [o for o in output.split('\n') if o] | 307 return [o for o in output.split('\n') if o] |
| OLD | NEW |