| 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 | 8 |
| 9 from . import bisect_utils | 9 from . import bisect_utils |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 results = bisect_utils.RunGit(['checkout', revision])[1] | 107 results = bisect_utils.RunGit(['checkout', revision])[1] |
| 108 elif sync_client == 'gclient': | 108 elif sync_client == 'gclient': |
| 109 results = self.SyncToRevisionWithGClient(revision) | 109 results = self.SyncToRevisionWithGClient(revision) |
| 110 elif sync_client == 'repo': | 110 elif sync_client == 'repo': |
| 111 results = self.SyncToRevisionWithRepo(revision) | 111 results = self.SyncToRevisionWithRepo(revision) |
| 112 | 112 |
| 113 return not results | 113 return not results |
| 114 | 114 |
| 115 def ResolveToRevision(self, revision_to_check, depot, depot_deps_dict, | 115 def ResolveToRevision(self, revision_to_check, depot, depot_deps_dict, |
| 116 search, cwd=None): | 116 search, cwd=None): |
| 117 """If an SVN revision is supplied, try to resolve it to a git SHA1. | 117 """Tries to resolve an SVN revision or commit position to a git SHA1. |
| 118 | 118 |
| 119 Args: | 119 Args: |
| 120 revision_to_check: The user supplied revision string that may need to be | 120 revision_to_check: The user supplied revision string that may need to be |
| 121 resolved to a git SHA1. | 121 resolved to a git SHA1. |
| 122 depot: The depot the revision_to_check is from. | 122 depot: The depot the revision_to_check is from. |
| 123 depot_deps_dict: A dictionary with information about different depots. | 123 depot_deps_dict: A dictionary with information about different depots. |
| 124 search: The number of changelists to try if the first fails to resolve | 124 search: The number of changelists to try if the first fails to resolve |
| 125 to a git hash. If the value is negative, the function will search | 125 to a git hash. If the value is negative, the function will search |
| 126 backwards chronologically, otherwise it will search forward. | 126 backwards chronologically, otherwise it will search forward. |
| 127 | 127 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 144 svn_revision = int(revision_to_check) | 144 svn_revision = int(revision_to_check) |
| 145 git_revision = None | 145 git_revision = None |
| 146 | 146 |
| 147 if search > 0: | 147 if search > 0: |
| 148 search_range = xrange(svn_revision, svn_revision + search, 1) | 148 search_range = xrange(svn_revision, svn_revision + search, 1) |
| 149 else: | 149 else: |
| 150 search_range = xrange(svn_revision, svn_revision + search, -1) | 150 search_range = xrange(svn_revision, svn_revision + search, -1) |
| 151 | 151 |
| 152 for i in search_range: | 152 for i in search_range: |
| 153 svn_pattern = 'git-svn-id: %s@%d' % (depot_svn, i) | 153 svn_pattern = 'git-svn-id: %s@%d' % (depot_svn, i) |
| 154 commit_position_pattern = 'Cr-Commit-Position: .*@{#%d}' % i |
| 154 cmd = ['log', '--format=%H', '-1', '--grep', svn_pattern, | 155 cmd = ['log', '--format=%H', '-1', '--grep', svn_pattern, |
| 155 'origin/master'] | 156 '--grep', commit_position_pattern, 'origin/master'] |
| 156 | 157 |
| 157 (log_output, return_code) = bisect_utils.RunGit(cmd, cwd=cwd) | 158 (log_output, return_code) = bisect_utils.RunGit(cmd, cwd=cwd) |
| 158 | 159 |
| 159 assert not return_code, 'An error occurred while running'\ | 160 assert not return_code, 'An error occurred while running'\ |
| 160 ' "git %s"' % ' '.join(cmd) | 161 ' "git %s"' % ' '.join(cmd) |
| 161 | 162 |
| 162 if not return_code: | 163 if not return_code: |
| 163 log_output = log_output.strip() | 164 log_output = log_output.strip() |
| 164 | 165 |
| 165 if log_output: | 166 if log_output: |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 revision_end: End of revision range. | 280 revision_end: End of revision range. |
| 280 | 281 |
| 281 Returns: | 282 Returns: |
| 282 Returns a list of commits that touched this file. | 283 Returns a list of commits that touched this file. |
| 283 """ | 284 """ |
| 284 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), | 285 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), |
| 285 filename] | 286 filename] |
| 286 output = bisect_utils.CheckRunGit(cmd) | 287 output = bisect_utils.CheckRunGit(cmd) |
| 287 | 288 |
| 288 return [o for o in output.split('\n') if o] | 289 return [o for o in output.split('\n') if o] |
| OLD | NEW |