| 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 functions for performing source control operations.""" | 5 """This module contains functions for performing source control operations.""" |
| 6 | 6 |
| 7 import bisect_utils | 7 import bisect_utils |
| 8 | 8 |
| 9 | 9 |
| 10 def IsInGitRepository(): | 10 def IsInGitRepository(): |
| 11 output, _ = bisect_utils.RunGit(['rev-parse', '--is-inside-work-tree']) | 11 output, _ = bisect_utils.RunGit(['rev-parse', '--is-inside-work-tree']) |
| 12 return output.strip() == 'true' | 12 return output.strip() == 'true' |
| 13 | 13 |
| 14 | 14 |
| 15 def SyncToRevisionWithGClient(revision): | |
| 16 """Uses gclient to sync to the specified revision. | |
| 17 | |
| 18 This is like running gclient sync --revision <revision>. | |
| 19 | |
| 20 Args: | |
| 21 revision: A git SHA1 hash or SVN revision number (depending on workflow). | |
| 22 | |
| 23 Returns: | |
| 24 The return code of the call. | |
| 25 """ | |
| 26 return bisect_utils.RunGClient( | |
| 27 ['sync', '--verbose', '--reset', '--force', | |
| 28 '--delete_unversioned_trees', '--nohooks', '--revision', revision]) | |
| 29 | |
| 30 | |
| 31 def GetRevisionList(end_revision_hash, start_revision_hash, cwd=None): | 15 def GetRevisionList(end_revision_hash, start_revision_hash, cwd=None): |
| 32 """Retrieves a list of git commit hashes in a range. | 16 """Retrieves a list of git commit hashes in a range. |
| 33 | 17 |
| 34 Args: | 18 Args: |
| 35 end_revision_hash: The SHA1 for the end of the range, inclusive. | 19 end_revision_hash: The SHA1 for the end of the range, inclusive. |
| 36 start_revision_hash: The SHA1 for the beginning of the range, inclusive. | 20 start_revision_hash: The SHA1 for the beginning of the range, inclusive. |
| 37 | 21 |
| 38 Returns: | 22 Returns: |
| 39 A list of the git commit hashes in the range, in reverse time order -- | 23 A list of the git commit hashes in the range, in reverse time order -- |
| 40 that is, starting with |end_revision_hash|. | 24 that is, starting with |end_revision_hash|. |
| 41 """ | 25 """ |
| 42 revision_range = '%s..%s' % (start_revision_hash, end_revision_hash) | 26 revision_range = '%s..%s' % (start_revision_hash, end_revision_hash) |
| 43 cmd = ['log', '--format=%H', '-10000', '--first-parent', revision_range] | 27 cmd = ['log', '--format=%H', '-10000', '--first-parent', revision_range] |
| 44 log_output = bisect_utils.CheckRunGit(cmd, cwd=cwd) | 28 log_output = bisect_utils.CheckRunGit(cmd, cwd=cwd) |
| 45 | 29 |
| 46 revision_hash_list = log_output.split() | 30 revision_hash_list = log_output.split() |
| 47 revision_hash_list.append(start_revision_hash) | 31 revision_hash_list.append(start_revision_hash) |
| 48 | 32 |
| 49 return revision_hash_list | 33 return revision_hash_list |
| 50 | 34 |
| 51 | 35 |
| 52 def SyncToRevision(revision, sync_client=None): | 36 def SyncToRevision(revision, sync_client=None): |
| 53 if not sync_client: | 37 if not sync_client: |
| 54 _, return_code = bisect_utils.RunGit(['checkout', revision]) | 38 _, return_code = bisect_utils.RunGit(['checkout', revision]) |
| 55 elif sync_client == 'gclient': | 39 elif sync_client == 'gclient': |
| 56 return_code = SyncToRevisionWithGClient(revision) | 40 return_code = bisect_utils.RunGClientAndSync(revision) |
| 57 else: | 41 else: |
| 58 raise NotImplementedError('Unsupported sync_client: "%s"' % sync_client) | 42 raise NotImplementedError('Unsupported sync_client: "%s"' % sync_client) |
| 59 | 43 |
| 60 return not return_code | 44 return not return_code |
| 61 | 45 |
| 62 | 46 |
| 63 def ResolveToRevision(revision_to_check, depot, depot_deps_dict, | 47 def ResolveToRevision(revision_to_check, depot, depot_deps_dict, |
| 64 search, cwd=None): | 48 search, cwd=None): |
| 65 """Tries to resolve an SVN revision or commit position to a git SHA1. | 49 """Tries to resolve an SVN revision or commit position to a git SHA1. |
| 66 | 50 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 116 |
| 133 Args: | 117 Args: |
| 134 git_revision: The git SHA1 to use. | 118 git_revision: The git SHA1 to use. |
| 135 cwd: Working directory to run the command from. | 119 cwd: Working directory to run the command from. |
| 136 | 120 |
| 137 Returns: | 121 Returns: |
| 138 Git commit position as integer or None. | 122 Git commit position as integer or None. |
| 139 """ | 123 """ |
| 140 # Some of the respositories are pure git based, unlike other repositories | 124 # Some of the respositories are pure git based, unlike other repositories |
| 141 # they doesn't have commit position. e.g., skia, angle. | 125 # they doesn't have commit position. e.g., skia, angle. |
| 142 no_commit_position_repos = ['angle', 'skia'] | |
| 143 if cwd and any(repo in cwd for repo in no_commit_position_repos): | |
| 144 return None | |
| 145 | |
| 146 cmd = ['footers', '--position-num', git_revision] | 126 cmd = ['footers', '--position-num', git_revision] |
| 147 output = bisect_utils.CheckRunGit(cmd, cwd) | 127 output, return_code = bisect_utils.RunGit(cmd, cwd) |
| 148 commit_position = output.strip() | 128 if not return_code: |
| 149 | 129 commit_position = output.strip() |
| 150 if bisect_utils.IsStringInt(commit_position): | 130 if bisect_utils.IsStringInt(commit_position): |
| 151 return int(commit_position) | 131 return int(commit_position) |
| 152 | |
| 153 return None | 132 return None |
| 154 | 133 |
| 155 | 134 |
| 135 def GetCommitTime(git_revision, cwd=None): |
| 136 """Returns commit time for the given revision in UNIX timestamp.""" |
| 137 cmd = ['log', '--format=%ct', '-1', git_revision] |
| 138 output = bisect_utils.CheckRunGit(cmd, cwd=cwd) |
| 139 return int(output) |
| 140 |
| 141 |
| 156 def QueryRevisionInfo(revision, cwd=None): | 142 def QueryRevisionInfo(revision, cwd=None): |
| 157 """Gathers information on a particular revision, such as author's name, | 143 """Gathers information on a particular revision, such as author's name, |
| 158 email, subject, and date. | 144 email, subject, and date. |
| 159 | 145 |
| 160 Args: | 146 Args: |
| 161 revision: Revision you want to gather information on; a git commit hash. | 147 revision: Revision you want to gather information on; a git commit hash. |
| 162 | 148 |
| 163 Returns: | 149 Returns: |
| 164 A dict in the following format: | 150 A dict in the following format: |
| 165 { | 151 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 'log', | 208 'log', |
| 223 '--format=%H', | 209 '--format=%H', |
| 224 '%s~1..%s' % (revision_start, revision_end), | 210 '%s~1..%s' % (revision_start, revision_end), |
| 225 '--', | 211 '--', |
| 226 filename, | 212 filename, |
| 227 ] | 213 ] |
| 228 output = bisect_utils.CheckRunGit(cmd) | 214 output = bisect_utils.CheckRunGit(cmd) |
| 229 lines = output.split('\n') | 215 lines = output.split('\n') |
| 230 return [o for o in lines if o] | 216 return [o for o in lines if o] |
| 231 | 217 |
| OLD | NEW |