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

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

Issue 552013008: Replace "git svn" with "git footers" commands to get commit position or svn revision. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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 | « no previous file | tools/bisect-perf-regression.py » ('j') | 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 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
9 8
10 from . import bisect_utils 9 from . import bisect_utils
11 10
12 CROS_VERSION_PATTERN = 'new version number from %s' 11 CROS_VERSION_PATTERN = 'new version number from %s'
13 12
14 13
15 def DetermineAndCreateSourceControl(opts): 14 def DetermineAndCreateSourceControl(opts):
16 """Attempts to determine the underlying source control workflow and returns 15 """Attempts to determine the underlying source control workflow and returns
17 a SourceControl object. 16 a SourceControl object.
18 17
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 198
200 Returns: 199 Returns:
201 True if the current branch on src is 'master' 200 True if the current branch on src is 'master'
202 """ 201 """
203 cmd = ['rev-parse', '--abbrev-ref', 'HEAD'] 202 cmd = ['rev-parse', '--abbrev-ref', 'HEAD']
204 log_output = bisect_utils.CheckRunGit(cmd) 203 log_output = bisect_utils.CheckRunGit(cmd)
205 log_output = log_output.strip() 204 log_output = log_output.strip()
206 205
207 return log_output == "master" 206 return log_output == "master"
208 207
209 def SVNFindRev(self, git_revision, cwd=None): 208 def GetCommitPosition(self, git_revision, cwd=None):
210 """Finds a SVN revision OR git number for the given git hash. 209 """Finds git commit postion for the given git hash.
211 210
212 If "git svn find_rev <hash>" fails, then it runs 211 This function executes "git footer --position-num <git hash>" command to get
213 "git log --format=%b -1 origin/master <hash> and greps for 212 commit position the given revision.
214 Cr-Commit-Position.
215 213
216 Args: 214 Args:
217 git_revision: The git SHA1 to use. 215 git_revision: The git SHA1 to use.
216 cwd: Working directory to run the command from.
218 217
219 Returns: 218 Returns:
220 Git number (aka git commit position) OR an SVN revision as integer, 219 Git commit position as integer or None.
221 otherwise None.
222 """ 220 """
221 cmd = ['footers', '--position-num', git_revision]
222 output = bisect_utils.CheckRunGit(cmd, cwd)
223 commit_position = output.strip()
223 224
224 cmd = ['svn', 'find-rev', git_revision] 225 if bisect_utils.IsStringInt(commit_position):
225 226 return int(commit_position)
226 output = bisect_utils.CheckRunGit(cmd, cwd)
227 svn_revision = output.strip()
228
229 if bisect_utils.IsStringInt(svn_revision):
230 return int(svn_revision)
231
232 # Retrieve commit position number from git log body for the given revision.
233 # TODO(prasadv): Use an appropriate command to find commit position instead
234 # of parsing the log. Resolve this once 407316 is fixed.
235 commit_position_pattern = 'Cr-Commit-Position: .*@\{#(?P<commit>[0-9]+)\}'
236 cmd = ['log', '--format=%b', '-1', git_revision]
237 output = bisect_utils.CheckRunGit(cmd, cwd=cwd)
238 if output:
239 version_re = re.compile(commit_position_pattern)
240 commit_reg = version_re.search(output)
241 if commit_reg and bisect_utils.IsStringInt(commit_reg.group('commit')):
242 return int(commit_reg.group('commit'))
243 227
244 return None 228 return None
245 229
246 def QueryRevisionInfo(self, revision, cwd=None): 230 def QueryRevisionInfo(self, revision, cwd=None):
247 """Gathers information on a particular revision, such as author's name, 231 """Gathers information on a particular revision, such as author's name,
248 email, subject, and date. 232 email, subject, and date.
249 233
250 Args: 234 Args:
251 revision: Revision you want to gather information on. 235 revision: Revision you want to gather information on.
252 236
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 revision_end: End of revision range. 285 revision_end: End of revision range.
302 286
303 Returns: 287 Returns:
304 Returns a list of commits that touched this file. 288 Returns a list of commits that touched this file.
305 """ 289 """
306 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end), 290 cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end),
307 '--', filename] 291 '--', filename]
308 output = bisect_utils.CheckRunGit(cmd) 292 output = bisect_utils.CheckRunGit(cmd)
309 293
310 return [o for o in output.split('\n') if o] 294 return [o for o in output.split('\n') if o]
OLDNEW
« no previous file with comments | « no previous file | tools/bisect-perf-regression.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698