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) |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 # revert, like for properties. | 1096 # revert, like for properties. |
1084 if not os.path.isdir(cwd): | 1097 if not os.path.isdir(cwd): |
1085 # '.' was deleted. It's not worth continuing. | 1098 # '.' was deleted. It's not worth continuing. |
1086 return | 1099 return |
1087 try: | 1100 try: |
1088 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1101 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1089 except subprocess2.CalledProcessError: | 1102 except subprocess2.CalledProcessError: |
1090 if not os.path.exists(file_path): | 1103 if not os.path.exists(file_path): |
1091 continue | 1104 continue |
1092 raise | 1105 raise |
OLD | NEW |