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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 print('') | 648 print('') |
649 | 649 |
650 clone_cmd = ['clone', '--progress'] | 650 clone_cmd = ['clone', '--progress'] |
651 if revision.startswith('refs/heads/'): | 651 if revision.startswith('refs/heads/'): |
652 clone_cmd.extend(['-b', revision.replace('refs/heads/', '')]) | 652 clone_cmd.extend(['-b', revision.replace('refs/heads/', '')]) |
653 detach_head = False | 653 detach_head = False |
654 else: | 654 else: |
655 detach_head = True | 655 detach_head = True |
656 if options.verbose: | 656 if options.verbose: |
657 clone_cmd.append('--verbose') | 657 clone_cmd.append('--verbose') |
658 # Don't assume 'with_branch_heads' is added by 'gclient sync' setup, since | |
659 # _Clone() can by reached in roundabout ways (e.g. 'gclient revert'). | |
660 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: | |
661 clone_cmd.extend(['--config', 'remote.origin.fetch=+refs/branch-heads/*:' | |
662 'refs/remotes/branch-heads/*']) | |
663 clone_cmd.extend([url, self.checkout_path]) | 658 clone_cmd.extend([url, self.checkout_path]) |
664 | 659 |
665 # If the parent directory does not exist, Git clone on Windows will not | 660 # If the parent directory does not exist, Git clone on Windows will not |
666 # create it, so we need to do it manually. | 661 # create it, so we need to do it manually. |
667 parent_dir = os.path.dirname(self.checkout_path) | 662 parent_dir = os.path.dirname(self.checkout_path) |
668 if not os.path.exists(parent_dir): | 663 if not os.path.exists(parent_dir): |
669 gclient_utils.safe_makedirs(parent_dir) | 664 gclient_utils.safe_makedirs(parent_dir) |
670 | 665 |
671 percent_re = re.compile('.* ([0-9]{1,2})% .*') | 666 percent_re = re.compile('.* ([0-9]{1,2})% .*') |
672 def _GitFilter(line): | 667 def _GitFilter(line): |
673 # git uses an escape sequence to clear the line; elide it. | 668 # git uses an escape sequence to clear the line; elide it. |
674 esc = line.find(unichr(033)) | 669 esc = line.find(unichr(033)) |
675 if esc > -1: | 670 if esc > -1: |
676 line = line[:esc] | 671 line = line[:esc] |
677 match = percent_re.match(line) | 672 match = percent_re.match(line) |
678 if not match or not int(match.group(1)) % 10: | 673 if not match or not int(match.group(1)) % 10: |
679 print '%s' % line | 674 print '%s' % line |
680 | 675 |
681 for _ in range(3): | 676 for _ in range(3): |
682 try: | 677 try: |
683 self._Run(clone_cmd, options, cwd=self._root_dir, filter_fn=_GitFilter, | 678 self._Run(clone_cmd, options, cwd=self._root_dir, filter_fn=_GitFilter, |
684 print_stdout=False) | 679 print_stdout=False) |
685 # Update the "branch-heads" remote-tracking branches, since clone | |
686 # doesn't automatically fetch those, and we might need it to checkout a | |
687 # specific revision below. | |
688 if (hasattr(options, 'with_branch_heads') and | |
689 options.with_branch_heads): | |
690 fetch_cmd = ['fetch', 'origin'] | |
691 if options.verbose: | |
692 fetch_cmd.append('--verbose') | |
693 self._Run(fetch_cmd, options) | |
694 break | 680 break |
695 except subprocess2.CalledProcessError, e: | 681 except subprocess2.CalledProcessError, e: |
696 # Too bad we don't have access to the actual output yet. | 682 # Too bad we don't have access to the actual output yet. |
697 # We should check for "transfer closed with NNN bytes remaining to | 683 # We should check for "transfer closed with NNN bytes remaining to |
698 # read". In the meantime, just make sure .git exists. | 684 # read". In the meantime, just make sure .git exists. |
699 if (e.returncode == 128 and | 685 if (e.returncode == 128 and |
700 os.path.exists(os.path.join(self.checkout_path, '.git'))): | 686 os.path.exists(os.path.join(self.checkout_path, '.git'))): |
701 print(str(e)) | 687 print(str(e)) |
702 print('Retrying...') | 688 print('Retrying...') |
703 continue | 689 continue |
704 raise e | 690 raise e |
705 | 691 |
| 692 for _ in range(3): |
| 693 try: |
| 694 # Add the "branch-heads" refspecs. Do this separately from the clone |
| 695 # command since apparently some versions of git don't support 'clone |
| 696 # --config'. |
| 697 # Don't assume 'with_branch_heads' is added by 'gclient sync' setup, |
| 698 # since _Clone() can by reached in roundabout ways (e.g. 'gclient |
| 699 # revert'). |
| 700 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: |
| 701 config_cmd = ['config', 'remote.origin.fetch', |
| 702 '+refs/branch-heads/*:refs/remotes/branch-heads/*'] |
| 703 self._Run(config_cmd, options) |
| 704 |
| 705 # Update the "branch-heads" remote-tracking branches, since we might |
| 706 # need it to checkout a specific revision below. |
| 707 fetch_cmd = ['fetch', 'origin'] |
| 708 if options.verbose: |
| 709 fetch_cmd.append('--verbose') |
| 710 self._Run(fetch_cmd, options) |
| 711 break |
| 712 except subprocess2.CalledProcessError, e: |
| 713 print(str(e)) |
| 714 print('Retrying...') |
| 715 continue |
| 716 |
706 if detach_head: | 717 if detach_head: |
707 # Squelch git's very verbose detached HEAD warning and use our own | 718 # Squelch git's very verbose detached HEAD warning and use our own |
708 self._Capture(['checkout', '--quiet', '%s' % revision]) | 719 self._Capture(['checkout', '--quiet', '%s' % revision]) |
709 print( | 720 print( |
710 ('Checked out %s to a detached HEAD. Before making any commits\n' | 721 ('Checked out %s to a detached HEAD. Before making any commits\n' |
711 'in this repo, you should use \'git checkout <branch>\' to switch to\n' | 722 'in this repo, you should use \'git checkout <branch>\' to switch to\n' |
712 'an existing branch or use \'git checkout origin -b <branch>\' to\n' | 723 'an existing branch or use \'git checkout origin -b <branch>\' to\n' |
713 'create a new branch for your work.') % revision) | 724 'create a new branch for your work.') % revision) |
714 | 725 |
715 def _AttemptRebase(self, upstream, files, options, newbase=None, | 726 def _AttemptRebase(self, upstream, files, options, newbase=None, |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 new_command.append('--force') | 1250 new_command.append('--force') |
1240 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1251 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1241 new_command.extend(('--accept', 'theirs-conflict')) | 1252 new_command.extend(('--accept', 'theirs-conflict')) |
1242 elif options.manually_grab_svn_rev: | 1253 elif options.manually_grab_svn_rev: |
1243 new_command.append('--force') | 1254 new_command.append('--force') |
1244 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1255 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1245 new_command.extend(('--accept', 'postpone')) | 1256 new_command.extend(('--accept', 'postpone')) |
1246 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1257 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1247 new_command.extend(('--accept', 'postpone')) | 1258 new_command.extend(('--accept', 'postpone')) |
1248 return new_command | 1259 return new_command |
OLD | NEW |