Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: tools/auto_bisect/source_control.py

Issue 792183003: Make changes to support bisect for android-chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/auto_bisect/bisect_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
156 def QueryRevisionInfo(revision, cwd=None): 135 def QueryRevisionInfo(revision, cwd=None):
157 """Gathers information on a particular revision, such as author's name, 136 """Gathers information on a particular revision, such as author's name,
158 email, subject, and date. 137 email, subject, and date.
159 138
160 Args: 139 Args:
161 revision: Revision you want to gather information on; a git commit hash. 140 revision: Revision you want to gather information on; a git commit hash.
162 141
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 'log', 201 'log',
223 '--format=%H', 202 '--format=%H',
224 '%s~1..%s' % (revision_start, revision_end), 203 '%s~1..%s' % (revision_start, revision_end),
225 '--', 204 '--',
226 filename, 205 filename,
227 ] 206 ]
228 output = bisect_utils.CheckRunGit(cmd) 207 output = bisect_utils.CheckRunGit(cmd)
229 lines = output.split('\n') 208 lines = output.split('\n')
230 return [o for o in lines if o] 209 return [o for o in lines if o]
231 210
211 def GetCommitTime(git_revision, cwd=None):
212 """Returns commit time for the given revision."""
qyearsley 2014/12/11 23:51:06 This could go up next to GetCommitPosition, with t
213 cmd = ['log', '--format=%ct', '-1', git_revision]
214 output = bisect_utils.CheckRunGit(cmd, cwd=cwd)
215 return int(output)
216
OLDNEW
« no previous file with comments | « tools/auto_bisect/bisect_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698