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

Side by Side Diff: scm.py

Issue 10826035: Fix error syncing to LKGR due to misparsing of Cygwin git-svn output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Adding test for git-svn SHA1 output parsing Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/scm_unittest.py » ('j') | tests/scm_unittest.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """SCM-specific utility classes.""" 5 """SCM-specific utility classes."""
6 6
7 import cStringIO 7 import cStringIO
8 import glob 8 import glob
9 import logging 9 import logging
10 import os 10 import os
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 def GetGitSvnHeadRev(cwd): 384 def GetGitSvnHeadRev(cwd):
385 """Gets the most recently pulled git-svn revision.""" 385 """Gets the most recently pulled git-svn revision."""
386 try: 386 try:
387 output = GIT.Capture(['svn', 'info'], cwd=cwd) 387 output = GIT.Capture(['svn', 'info'], cwd=cwd)
388 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE) 388 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE)
389 return int(match.group(1)) if match else None 389 return int(match.group(1)) if match else None
390 except (subprocess2.CalledProcessError, ValueError): 390 except (subprocess2.CalledProcessError, ValueError):
391 return None 391 return None
392 392
393 @staticmethod 393 @staticmethod
394 def ParseGitSvnSha1(output):
395 """Parses git-svn output for the first sha1."""
396 match = re.search(r'[0-9a-fA-F]{40}', output)
397 return match.group(0) if match else None
398
399 @staticmethod
394 def GetSha1ForSvnRev(cwd, rev): 400 def GetSha1ForSvnRev(cwd, rev):
395 """Returns a corresponding git sha1 for a SVN revision.""" 401 """Returns a corresponding git sha1 for a SVN revision."""
396 if not GIT.IsGitSvn(cwd=cwd): 402 if not GIT.IsGitSvn(cwd=cwd):
397 return None 403 return None
398 try: 404 try:
399 lines = GIT.Capture( 405 output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
400 ['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).splitlines() 406 return GIT.ParseGitSvnSha1(output)
401 return lines[-1].strip() if lines else None
402 except subprocess2.CalledProcessError: 407 except subprocess2.CalledProcessError:
403 return None 408 return None
404 409
405 @staticmethod 410 @staticmethod
406 def IsValidRevision(cwd, rev): 411 def IsValidRevision(cwd, rev):
407 """Verifies the revision is a proper git revision.""" 412 """Verifies the revision is a proper git revision."""
408 # 'git rev-parse foo' where foo is *any* 40 character hex string will return 413 # 'git rev-parse foo' where foo is *any* 40 character hex string will return
409 # the string and return code 0. So strip one character to force 'git 414 # the string and return code 0. So strip one character to force 'git
410 # rev-parse' to do a hash table look-up and returns 128 if the hash is not 415 # rev-parse' to do a hash table look-up and returns 128 if the hash is not
411 # present. 416 # present.
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 # revert, like for properties. 1068 # revert, like for properties.
1064 if not os.path.isdir(cwd): 1069 if not os.path.isdir(cwd):
1065 # '.' was deleted. It's not worth continuing. 1070 # '.' was deleted. It's not worth continuing.
1066 return 1071 return
1067 try: 1072 try:
1068 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1073 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1069 except subprocess2.CalledProcessError: 1074 except subprocess2.CalledProcessError:
1070 if not os.path.exists(file_path): 1075 if not os.path.exists(file_path):
1071 continue 1076 continue
1072 raise 1077 raise
OLDNEW
« no previous file with comments | « no previous file | tests/scm_unittest.py » ('j') | tests/scm_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698