| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |