OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 self._Run(['diff', '--name-status', merge_base], options) | 482 self._Run(['diff', '--name-status', merge_base], options) |
483 files = self._Capture(['diff', '--name-only', merge_base]).split() | 483 files = self._Capture(['diff', '--name-only', merge_base]).split() |
484 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 484 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
485 | 485 |
486 def GetUsableRev(self, rev, options): | 486 def GetUsableRev(self, rev, options): |
487 """Finds a useful revision for this repository. | 487 """Finds a useful revision for this repository. |
488 | 488 |
489 If SCM is git-svn and the head revision is less than |rev|, git svn fetch | 489 If SCM is git-svn and the head revision is less than |rev|, git svn fetch |
490 will be called on the source.""" | 490 will be called on the source.""" |
491 sha1 = None | 491 sha1 = None |
492 # As an optimization, only verify an SVN revision as [0-9]{1,6} for now to | 492 # Handles an SVN rev. As an optimization, only verify an SVN revision as |
493 # avoid making a network request. | 493 # [0-9]{1,6} for now to avoid making a network request. |
494 if (scm.GIT.IsGitSvn(cwd=self.checkout_path) and | 494 if rev.isdigit() and len(rev) < 7: |
495 rev.isdigit() and len(rev) < 7): | 495 # If the content of the safesync_url appears to be an SVN rev and the |
496 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) | 496 # URL of the source appears to be git, we can only attempt to find out |
497 if not local_head or local_head < int(rev): | 497 # if a revision is useful after we've cloned the original URL, so just |
498 if options.verbose: | 498 # ignore for now. |
499 print('Running git svn fetch. This might take a while.\n') | 499 if (os.path.isdir(self.checkout_path) and |
500 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) | 500 scm.GIT.IsGitSvn(cwd=self.checkout_path)): |
501 sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) | 501 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) |
| 502 if not local_head or local_head < int(rev): |
| 503 if options.verbose: |
| 504 print('Running git svn fetch. This might take a while.\n') |
| 505 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) |
| 506 sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) |
| 507 if not sha1: |
| 508 raise gclient_utils.Error( |
| 509 ( 'It appears that either your git-svn remote is incorrectly\n' |
| 510 'configured or the revision in your safesync_url is\n' |
| 511 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' |
| 512 'corresponding git hash for SVN rev %s.' ) % rev) |
502 elif scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): | 513 elif scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
503 sha1 = rev | 514 sha1 = rev |
| 515 |
504 if not sha1: | 516 if not sha1: |
505 raise gclient_utils.Error( | 517 raise gclient_utils.Error( |
506 ( '%s is not a value hash. Safesync URLs with a git checkout\n' | 518 ( 'We could not find a valid hash for safesync_url response "%s".\n' |
507 'currently require a git-svn remote or a safesync_url that\n' | 519 'Safesync URLs with a git checkout currently require a git-svn\n' |
508 'provides git sha1s. Please add a git-svn remote or change\n' | 520 'remote or a safesync_url that provides git sha1s. Please add a\n' |
509 'your safesync_url. For more info, see:\n' | 521 'git-svn remote or change your safesync_url. For more info, see:\n' |
510 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 522 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
511 '#Initial_checkout') % rev) | 523 '#Initial_checkout' ) % rev) |
| 524 |
512 return sha1 | 525 return sha1 |
513 | 526 |
514 def FullUrlForRelativeUrl(self, url): | 527 def FullUrlForRelativeUrl(self, url): |
515 # Strip from last '/' | 528 # Strip from last '/' |
516 # Equivalent to unix basename | 529 # Equivalent to unix basename |
517 base_url = self.url | 530 base_url = self.url |
518 return base_url[:base_url.rfind('/')] + url | 531 return base_url[:base_url.rfind('/')] + url |
519 | 532 |
520 def _Clone(self, revision, url, options): | 533 def _Clone(self, revision, url, options): |
521 """Clone a git repository from the given URL. | 534 """Clone a git repository from the given URL. |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 new_command.append('--force') | 1093 new_command.append('--force') |
1081 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1094 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1082 new_command.extend(('--accept', 'theirs-conflict')) | 1095 new_command.extend(('--accept', 'theirs-conflict')) |
1083 elif options.manually_grab_svn_rev: | 1096 elif options.manually_grab_svn_rev: |
1084 new_command.append('--force') | 1097 new_command.append('--force') |
1085 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1098 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1086 new_command.extend(('--accept', 'postpone')) | 1099 new_command.extend(('--accept', 'postpone')) |
1087 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1100 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1088 new_command.extend(('--accept', 'postpone')) | 1101 new_command.extend(('--accept', 'postpone')) |
1089 return new_command | 1102 return new_command |
OLD | NEW |