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(): |
(...skipping 16 matching lines...) Expand all Loading... |
27 cmd = ['log', '--format=%H', '-10000', '--first-parent', revision_range] | 27 cmd = ['log', '--format=%H', '-10000', '--first-parent', revision_range] |
28 log_output = bisect_utils.CheckRunGit(cmd, cwd=cwd) | 28 log_output = bisect_utils.CheckRunGit(cmd, cwd=cwd) |
29 | 29 |
30 revision_hash_list = log_output.split() | 30 revision_hash_list = log_output.split() |
31 revision_hash_list.append(start_revision_hash) | 31 revision_hash_list.append(start_revision_hash) |
32 | 32 |
33 return revision_hash_list | 33 return revision_hash_list |
34 | 34 |
35 | 35 |
36 def SyncToRevision(revision, sync_client=None): | 36 def SyncToRevision(revision, sync_client=None): |
| 37 """Syncs or checks out a revision based on sync_client argument. |
| 38 |
| 39 Args: |
| 40 revision: Git hash for the solutions with the format <repo>@rev. |
| 41 E.g., "src@2ae43f...", "src/third_party/webkit@asr1234" etc. |
| 42 sync_client: Syncs to revision when this is True otherwise checks out |
| 43 the revision. |
| 44 |
| 45 Returns: |
| 46 True if sync or checkout is successful, False otherwise. |
| 47 """ |
37 if not sync_client: | 48 if not sync_client: |
38 _, return_code = bisect_utils.RunGit(['checkout', revision]) | 49 _, return_code = bisect_utils.RunGit(['checkout', revision]) |
39 elif sync_client == 'gclient': | 50 elif sync_client == 'gclient': |
40 return_code = bisect_utils.RunGClientAndSync(revision) | 51 return_code = bisect_utils.RunGClientAndSync([revision]) |
41 else: | 52 else: |
42 raise NotImplementedError('Unsupported sync_client: "%s"' % sync_client) | 53 raise NotImplementedError('Unsupported sync_client: "%s"' % sync_client) |
43 | 54 |
44 return not return_code | 55 return not return_code |
45 | 56 |
46 | 57 |
| 58 def GetCurrentRevision(cwd=None): |
| 59 """Gets current revision of the given repository.""" |
| 60 return bisect_utils.CheckRunGit(['rev-parse', 'HEAD'], cwd=cwd).strip() |
| 61 |
| 62 |
47 def ResolveToRevision(revision_to_check, depot, depot_deps_dict, | 63 def ResolveToRevision(revision_to_check, depot, depot_deps_dict, |
48 search, cwd=None): | 64 search, cwd=None): |
49 """Tries to resolve an SVN revision or commit position to a git SHA1. | 65 """Tries to resolve an SVN revision or commit position to a git SHA1. |
50 | 66 |
51 Args: | 67 Args: |
52 revision_to_check: The user supplied revision string that may need to be | 68 revision_to_check: The user supplied revision string that may need to be |
53 resolved to a git commit hash. This may be an SVN revision, git commit | 69 resolved to a git commit hash. This may be an SVN revision, git commit |
54 position, or a git commit hash. | 70 position, or a git commit hash. |
55 depot: The depot (dependency repository) that |revision_to_check| is from. | 71 depot: The depot (dependency repository) that |revision_to_check| is from. |
56 depot_deps_dict: A dictionary with information about different depots. | 72 depot_deps_dict: A dictionary with information about different depots. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 'log', | 224 'log', |
209 '--format=%H', | 225 '--format=%H', |
210 '%s~1..%s' % (revision_start, revision_end), | 226 '%s~1..%s' % (revision_start, revision_end), |
211 '--', | 227 '--', |
212 filename, | 228 filename, |
213 ] | 229 ] |
214 output = bisect_utils.CheckRunGit(cmd) | 230 output = bisect_utils.CheckRunGit(cmd) |
215 lines = output.split('\n') | 231 lines = output.split('\n') |
216 return [o for o in lines if o] | 232 return [o for o in lines if o] |
217 | 233 |
OLD | NEW |