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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 """Display status information.""" | 476 """Display status information.""" |
477 if not os.path.isdir(self.checkout_path): | 477 if not os.path.isdir(self.checkout_path): |
478 print(('\n________ couldn\'t run status in %s:\n' | 478 print(('\n________ couldn\'t run status in %s:\n' |
479 'The directory does not exist.') % self.checkout_path) | 479 'The directory does not exist.') % self.checkout_path) |
480 else: | 480 else: |
481 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 481 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) |
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): |
| 487 """Finds a useful revision for this repository. |
| 488 |
| 489 If SCM is git-svn and the head revision is less than |rev|, git svn fetch |
| 490 will be called on the source.""" |
| 491 sha1 = None |
| 492 # As an optimization, only verify an SVN revision as [0-9]{1,6} for now to |
| 493 # avoid making a network request. |
| 494 if (scm.GIT.IsGitSvn(cwd=self.checkout_path) and |
| 495 rev.isdigit() and len(rev) < 7): |
| 496 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) |
| 497 if not local_head or local_head < int(rev): |
| 498 if options.verbose: |
| 499 print('Running git svn fetch. This might take a while.\n') |
| 500 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) |
| 501 sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) |
| 502 elif scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
| 503 sha1 = rev |
| 504 if not sha1: |
| 505 raise gclient_utils.Error( |
| 506 ( '%s is not a value hash. Safesync URLs with a git checkout\n' |
| 507 'currently require a git-svn remote or a safesync_url that\n' |
| 508 'provides git sha1s. Please add a git-svn remote or change\n' |
| 509 'your safesync_url. For more info, see:\n' |
| 510 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
| 511 '#Initial_checkout') % rev) |
| 512 return sha1 |
| 513 |
486 def FullUrlForRelativeUrl(self, url): | 514 def FullUrlForRelativeUrl(self, url): |
487 # Strip from last '/' | 515 # Strip from last '/' |
488 # Equivalent to unix basename | 516 # Equivalent to unix basename |
489 base_url = self.url | 517 base_url = self.url |
490 return base_url[:base_url.rfind('/')] + url | 518 return base_url[:base_url.rfind('/')] + url |
491 | 519 |
492 def _Clone(self, revision, url, options): | 520 def _Clone(self, revision, url, options): |
493 """Clone a git repository from the given URL. | 521 """Clone a git repository from the given URL. |
494 | 522 |
495 Once we've cloned the repo, we checkout a working branch if the specified | 523 Once we've cloned the repo, we checkout a working branch if the specified |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 command = ['status'] + args | 1023 command = ['status'] + args |
996 if not os.path.isdir(self.checkout_path): | 1024 if not os.path.isdir(self.checkout_path): |
997 # svn status won't work if the directory doesn't exist. | 1025 # svn status won't work if the directory doesn't exist. |
998 print(('\n________ couldn\'t run \'%s\' in \'%s\':\n' | 1026 print(('\n________ couldn\'t run \'%s\' in \'%s\':\n' |
999 'The directory does not exist.') % | 1027 'The directory does not exist.') % |
1000 (' '.join(command), self.checkout_path)) | 1028 (' '.join(command), self.checkout_path)) |
1001 # There's no file list to retrieve. | 1029 # There's no file list to retrieve. |
1002 else: | 1030 else: |
1003 self._RunAndGetFileList(command, options, file_list) | 1031 self._RunAndGetFileList(command, options, file_list) |
1004 | 1032 |
| 1033 def GetUsableRev(self, rev, options): |
| 1034 """Verifies the validity of the revision for this repository.""" |
| 1035 if not scm.SVN.IsValidRevision(url='%s@%s' % (self.url, rev)): |
| 1036 raise gclient_utils.Error( |
| 1037 ( '%s isn\'t a valid revision. Please check that your safesync_url is\n' |
| 1038 'correct.') % rev) |
| 1039 return rev |
| 1040 |
1005 def FullUrlForRelativeUrl(self, url): | 1041 def FullUrlForRelativeUrl(self, url): |
1006 # Find the forth '/' and strip from there. A bit hackish. | 1042 # Find the forth '/' and strip from there. A bit hackish. |
1007 return '/'.join(self.url.split('/')[:4]) + url | 1043 return '/'.join(self.url.split('/')[:4]) + url |
1008 | 1044 |
1009 def _Run(self, args, options, **kwargs): | 1045 def _Run(self, args, options, **kwargs): |
1010 """Runs a commands that goes to stdout.""" | 1046 """Runs a commands that goes to stdout.""" |
1011 kwargs.setdefault('cwd', self.checkout_path) | 1047 kwargs.setdefault('cwd', self.checkout_path) |
1012 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args, | 1048 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args, |
1013 always=options.verbose, **kwargs) | 1049 always=options.verbose, **kwargs) |
1014 | 1050 |
(...skipping 29 matching lines...) Expand all Loading... |
1044 new_command.append('--force') | 1080 new_command.append('--force') |
1045 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1081 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1046 new_command.extend(('--accept', 'theirs-conflict')) | 1082 new_command.extend(('--accept', 'theirs-conflict')) |
1047 elif options.manually_grab_svn_rev: | 1083 elif options.manually_grab_svn_rev: |
1048 new_command.append('--force') | 1084 new_command.append('--force') |
1049 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1085 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1050 new_command.extend(('--accept', 'postpone')) | 1086 new_command.extend(('--accept', 'postpone')) |
1051 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1087 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1052 new_command.extend(('--accept', 'postpone')) | 1088 new_command.extend(('--accept', 'postpone')) |
1053 return new_command | 1089 return new_command |
OLD | NEW |