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 output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd) | 405 git_svn_rev = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], |
|
M-A Ruel
2012/10/11 21:06:14
git_svn_rev = GIT.Capture(
['svn', 'find-rev',
| |
| 406 return GIT.ParseGitSvnSha1(output) | 406 cwd=cwd).rstrip() |
| 407 if not git_svn_rev: | |
| 408 return None | |
| 409 output = GIT.Capture(['rev-list', '--ancestry-path', '--reverse', | |
|
M-A Ruel
2012/10/11 21:06:14
same
| |
| 410 '--grep', 'SVN changes up to revision [0-9]*', | |
| 411 '%s..refs/remotes/origin/master' % git_svn_rev], cwd=cwd) | |
| 412 if not output: | |
| 413 return None | |
| 414 sha1 = output.splitlines()[0] | |
| 415 if not sha1: | |
| 416 return None | |
| 417 output = GIT.Capture(['rev-list', '-n', '1', '%s^1' % sha1], cwd=cwd) | |
| 418 if git_svn_rev != output.rstrip(): | |
| 419 raise gclient_utils.Error(sha1) | |
| 420 return sha1 | |
| 407 except subprocess2.CalledProcessError: | 421 except subprocess2.CalledProcessError: |
| 408 return None | 422 return None |
| 409 | 423 |
| 410 @staticmethod | 424 @staticmethod |
| 411 def IsValidRevision(cwd, rev): | 425 def IsValidRevision(cwd, rev): |
| 412 """Verifies the revision is a proper git revision.""" | 426 """Verifies the revision is a proper git revision.""" |
| 413 # 'git rev-parse foo' where foo is *any* 40 character hex string will return | 427 # 'git rev-parse foo' where foo is *any* 40 character hex string will return |
| 414 # the string and return code 0. So strip one character to force 'git | 428 # the string and return code 0. So strip one character to force 'git |
| 415 # rev-parse' to do a hash table look-up and returns 128 if the hash is not | 429 # rev-parse' to do a hash table look-up and returns 128 if the hash is not |
| 416 # present. | 430 # present. |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1068 # revert, like for properties. | 1082 # revert, like for properties. |
| 1069 if not os.path.isdir(cwd): | 1083 if not os.path.isdir(cwd): |
| 1070 # '.' was deleted. It's not worth continuing. | 1084 # '.' was deleted. It's not worth continuing. |
| 1071 return | 1085 return |
| 1072 try: | 1086 try: |
| 1073 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1087 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
| 1074 except subprocess2.CalledProcessError: | 1088 except subprocess2.CalledProcessError: |
| 1075 if not os.path.exists(file_path): | 1089 if not os.path.exists(file_path): |
| 1076 continue | 1090 continue |
| 1077 raise | 1091 raise |
| OLD | NEW |