Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 """Parses git-svn output for the first sha1.""" | 395 """Parses git-svn output for the first sha1.""" |
| 396 match = re.search(r'[0-9a-fA-F]{40}', output) | 396 match = re.search(r'[0-9a-fA-F]{40}', output) |
| 397 return match.group(0) if match else None | 397 return match.group(0) if match else None |
| 398 | 398 |
| 399 @staticmethod | 399 @staticmethod |
| 400 def GetSha1ForSvnRev(cwd, rev): | 400 def GetSha1ForSvnRev(cwd, rev): |
| 401 """Returns a corresponding git sha1 for a SVN revision.""" | 401 """Returns a corresponding git sha1 for a SVN revision.""" |
| 402 if not GIT.IsGitSvn(cwd=cwd): | 402 if not GIT.IsGitSvn(cwd=cwd): |
| 403 return None | 403 return None |
| 404 try: | 404 try: |
| 405 git_svn_rev = GIT.Capture( | 405 output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd) |
| 406 ['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).rstrip() | 406 return GIT.ParseGitSvnSha1(output) |
| 407 if not git_svn_rev: | 407 except subprocess2.CalledProcessError: |
| 408 return None | 408 return None |
| 409 | |
| 410 @staticmethod | |
| 411 def GetBlessedSha1ForSvnRev(cwd, rev): | |
| 412 """Returns a git commit hash from the master branch history that has | |
| 413 accurate .DEPS.git and git submodules. To understand why this is more | |
| 414 complicated than a simple call to `git svn find-rev`, refer to: | |
| 415 | |
| 416 http://www.chromium.org/developers/how-tos/git-repo | |
| 417 """ | |
| 418 git_svn_rev = GIT.GetSha1ForSvnRev(cwd, rev) | |
| 419 if not git_svn_rev: | |
| 420 return None | |
| 421 try: | |
| 409 output = GIT.Capture( | 422 output = GIT.Capture( |
| 410 ['rev-list', '--ancestry-path', '--reverse', | 423 ['rev-list', '--ancestry-path', '--reverse', |
| 411 '--grep', 'SVN changes up to revision [0-9]*', | 424 '--grep', 'SVN changes up to revision [0-9]*', |
| 412 '%s..refs/remotes/origin/master' % git_svn_rev], cwd=cwd) | 425 '%s..refs/remotes/origin/master' % git_svn_rev], cwd=cwd) |
| 413 if not output: | 426 if not output: |
| 414 return None | 427 return None |
| 415 sha1 = output.splitlines()[0] | 428 sha1 = output.splitlines()[0] |
| 416 if not sha1: | 429 if not sha1: |
| 417 return None | 430 return None |
| 418 output = GIT.Capture(['rev-list', '-n', '1', '%s^1' % sha1], cwd=cwd) | 431 output = GIT.Capture(['rev-list', '-n', '1', '%s^1' % sha1], cwd=cwd) |
| 419 if git_svn_rev != output.rstrip(): | 432 if git_svn_rev != output.rstrip(): |
| 420 raise gclient_utils.Error(sha1) | 433 raise gclient_utils.Error(sha1) |
| 421 return sha1 | 434 return sha1 |
| 422 except subprocess2.CalledProcessError: | 435 except subprocess2.CalledProcessError: |
| 423 return None | 436 return None |
| 424 | 437 |
| 438 | |
|
M-A Ruel
2012/10/15 18:34:05
Just one vertical line for non-file level symbol
szager1
2012/10/15 18:37:58
Done.
| |
| 425 @staticmethod | 439 @staticmethod |
| 426 def IsValidRevision(cwd, rev): | 440 def IsValidRevision(cwd, rev): |
| 427 """Verifies the revision is a proper git revision.""" | 441 """Verifies the revision is a proper git revision.""" |
| 428 # 'git rev-parse foo' where foo is *any* 40 character hex string will return | 442 # 'git rev-parse foo' where foo is *any* 40 character hex string will return |
| 429 # the string and return code 0. So strip one character to force 'git | 443 # the string and return code 0. So strip one character to force 'git |
| 430 # rev-parse' to do a hash table look-up and returns 128 if the hash is not | 444 # rev-parse' to do a hash table look-up and returns 128 if the hash is not |
| 431 # present. | 445 # present. |
| 432 if re.match(r'^[0-9a-fA-F]{40}$', rev): | 446 if re.match(r'^[0-9a-fA-F]{40}$', rev): |
| 433 rev = rev[:-1] | 447 rev = rev[:-1] |
| 434 try: | 448 try: |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 # revert, like for properties. | 1097 # revert, like for properties. |
| 1084 if not os.path.isdir(cwd): | 1098 if not os.path.isdir(cwd): |
| 1085 # '.' was deleted. It's not worth continuing. | 1099 # '.' was deleted. It's not worth continuing. |
| 1086 return | 1100 return |
| 1087 try: | 1101 try: |
| 1088 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1102 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
| 1089 except subprocess2.CalledProcessError: | 1103 except subprocess2.CalledProcessError: |
| 1090 if not os.path.exists(file_path): | 1104 if not os.path.exists(file_path): |
| 1091 continue | 1105 continue |
| 1092 raise | 1106 raise |
| OLD | NEW |