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 """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 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 def __init__(self, relpath): | 27 def __init__(self, relpath): |
28 # Note that we always use '/' as the path separator to be | 28 # Note that we always use '/' as the path separator to be |
29 # consistent with svn's cygwin-style output on Windows | 29 # consistent with svn's cygwin-style output on Windows |
30 self._relpath = relpath.replace("\\", "/") | 30 self._relpath = relpath.replace("\\", "/") |
31 self._current_file = None | 31 self._current_file = None |
32 | 32 |
33 def SetCurrentFile(self, current_file): | 33 def SetCurrentFile(self, current_file): |
34 self._current_file = current_file | 34 self._current_file = current_file |
35 | 35 |
36 @property | 36 @property |
37 def _replacement_file(self): | 37 def _replacement_file(self): |
38 return posixpath.join(self._relpath, self._current_file) | 38 return posixpath.join(self._relpath, self._current_file) |
39 | 39 |
40 def _Replace(self, line): | 40 def _Replace(self, line): |
41 return line.replace(self._current_file, self._replacement_file) | 41 return line.replace(self._current_file, self._replacement_file) |
42 | 42 |
43 def Filter(self, line): | 43 def Filter(self, line): |
44 if (line.startswith(self.index_string)): | 44 if (line.startswith(self.index_string)): |
45 self.SetCurrentFile(line[len(self.index_string):]) | 45 self.SetCurrentFile(line[len(self.index_string):]) |
46 line = self._Replace(line) | 46 line = self._Replace(line) |
47 else: | 47 else: |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 self._Run(['diff', '--name-status', merge_base], options) | 560 self._Run(['diff', '--name-status', merge_base], options) |
561 files = self._Capture(['diff', '--name-only', merge_base]).split() | 561 files = self._Capture(['diff', '--name-only', merge_base]).split() |
562 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 562 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
563 | 563 |
564 def GetUsableRev(self, rev, options): | 564 def GetUsableRev(self, rev, options): |
565 """Finds a useful revision for this repository. | 565 """Finds a useful revision for this repository. |
566 | 566 |
567 If SCM is git-svn and the head revision is less than |rev|, git svn fetch | 567 If SCM is git-svn and the head revision is less than |rev|, git svn fetch |
568 will be called on the source.""" | 568 will be called on the source.""" |
569 sha1 = None | 569 sha1 = None |
570 # Handles an SVN rev. As an optimization, only verify an SVN revision as | 570 if not os.path.isdir(self.checkout_path): |
M-A Ruel
2013/02/19 19:07:44
Why are you breaking svn users? It's not necessary
iannucci
2013/02/19 19:18:33
I'm not, this was in the second if statement in th
M-A Ruel
2013/02/19 19:21:42
Oh right, this is only for git checkouts, ok fine.
| |
571 # [0-9]{1,6} for now to avoid making a network request. | 571 raise gclient_utils.Error( |
572 if rev.isdigit() and len(rev) < 7: | 572 ( 'We could not find a valid hash for safesync_url response "%s".\n' |
573 # If the content of the safesync_url appears to be an SVN rev and the | 573 'Safesync URLs with a git checkout currently require the repo to\n' |
574 # URL of the source appears to be git, we can only attempt to find out | 574 'be cloned without a safesync_url before adding the safesync_url.\n' |
575 # if a revision is useful after we've cloned the original URL, so just | 575 'For more info, see: ' |
576 # ignore for now. | 576 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
577 if (os.path.isdir(self.checkout_path) and | 577 '#Initial_checkout' ) % rev) |
578 scm.GIT.IsGitSvn(cwd=self.checkout_path)): | 578 elif rev.isdigit() and len(rev) < 7: |
579 # Handles an SVN rev. As an optimization, only verify an SVN revision as | |
580 # [0-9]{1,6} for now to avoid making a network request. | |
581 if scm.GIT.IsGitSvn(cwd=self.checkout_path): | |
579 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) | 582 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) |
580 if not local_head or local_head < int(rev): | 583 if not local_head or local_head < int(rev): |
581 try: | 584 try: |
582 logging.debug('Looking for git-svn configuration optimizations.') | 585 logging.debug('Looking for git-svn configuration optimizations.') |
583 if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], | 586 if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
584 cwd=self.checkout_path): | 587 cwd=self.checkout_path): |
585 scm.GIT.Capture(['fetch'], cwd=self.checkout_path) | 588 scm.GIT.Capture(['fetch'], cwd=self.checkout_path) |
586 except subprocess2.CalledProcessError: | 589 except subprocess2.CalledProcessError: |
587 logging.debug('git config --get svn-remote.svn.fetch failed, ' | 590 logging.debug('git config --get svn-remote.svn.fetch failed, ' |
588 'ignoring possible optimization.') | 591 'ignoring possible optimization.') |
589 if options.verbose: | 592 if options.verbose: |
590 print('Running git svn fetch. This might take a while.\n') | 593 print('Running git svn fetch. This might take a while.\n') |
591 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) | 594 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) |
592 try: | 595 try: |
593 sha1 = scm.GIT.GetBlessedSha1ForSvnRev( | 596 sha1 = scm.GIT.GetBlessedSha1ForSvnRev( |
594 cwd=self.checkout_path, rev=rev) | 597 cwd=self.checkout_path, rev=rev) |
595 except gclient_utils.Error, e: | 598 except gclient_utils.Error, e: |
596 sha1 = e.message | 599 sha1 = e.message |
597 print('\nWarning: Could not find a git revision with accurate\n' | 600 print('\nWarning: Could not find a git revision with accurate\n' |
598 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n' | 601 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n' |
599 'the closest sane git revision, which is:\n' | 602 'the closest sane git revision, which is:\n' |
600 ' %s\n' % (rev, e.message)) | 603 ' %s\n' % (rev, e.message)) |
601 if not sha1: | 604 if not sha1: |
602 raise gclient_utils.Error( | 605 raise gclient_utils.Error( |
603 ( 'It appears that either your git-svn remote is incorrectly\n' | 606 ( 'It appears that either your git-svn remote is incorrectly\n' |
604 'configured or the revision in your safesync_url is\n' | 607 'configured or the revision in your safesync_url is\n' |
605 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' | 608 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' |
606 'corresponding git hash for SVN rev %s.' ) % rev) | 609 'corresponding git hash for SVN rev %s.' ) % rev) |
607 elif scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): | 610 else: |
608 sha1 = rev | 611 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
612 sha1 = rev | |
613 else: | |
614 # May exist in origin, but we don't have it yet, so fetch and look | |
615 # again. | |
616 scm.GIT.Capture(['fetch', 'origin'], cwd=self.checkout_path) | |
617 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): | |
618 sha1 = rev | |
609 | 619 |
610 if not sha1: | 620 if not sha1: |
611 raise gclient_utils.Error( | 621 raise gclient_utils.Error( |
612 ( 'We could not find a valid hash for safesync_url response "%s".\n' | 622 ( 'We could not find a valid hash for safesync_url response "%s".\n' |
613 'Safesync URLs with a git checkout currently require a git-svn\n' | 623 'Safesync URLs with a git checkout currently require a git-svn\n' |
614 'remote or a safesync_url that provides git sha1s. Please add a\n' | 624 'remote or a safesync_url that provides git sha1s. Please add a\n' |
615 'git-svn remote or change your safesync_url. For more info, see:\n' | 625 'git-svn remote or change your safesync_url. For more info, see:\n' |
616 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 626 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
617 '#Initial_checkout' ) % rev) | 627 '#Initial_checkout' ) % rev) |
618 | 628 |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 new_command.append('--force') | 1225 new_command.append('--force') |
1216 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1226 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1217 new_command.extend(('--accept', 'theirs-conflict')) | 1227 new_command.extend(('--accept', 'theirs-conflict')) |
1218 elif options.manually_grab_svn_rev: | 1228 elif options.manually_grab_svn_rev: |
1219 new_command.append('--force') | 1229 new_command.append('--force') |
1220 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1230 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1221 new_command.extend(('--accept', 'postpone')) | 1231 new_command.extend(('--accept', 'postpone')) |
1222 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1232 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1223 new_command.extend(('--accept', 'postpone')) | 1233 new_command.extend(('--accept', 'postpone')) |
1224 return new_command | 1234 return new_command |
OLD | NEW |