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