| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return scm_class(url, root_dir, relpath) | 109 return scm_class(url, root_dir, relpath) |
| 110 | 110 |
| 111 | 111 |
| 112 # SCMWrapper base class | 112 # SCMWrapper base class |
| 113 | 113 |
| 114 class SCMWrapper(object): | 114 class SCMWrapper(object): |
| 115 """Add necessary glue between all the supported SCM. | 115 """Add necessary glue between all the supported SCM. |
| 116 | 116 |
| 117 This is the abstraction layer to bind to different SCM. | 117 This is the abstraction layer to bind to different SCM. |
| 118 """ | 118 """ |
| 119 nag_timer = 30 |
| 120 nag_max = 3 |
| 121 |
| 119 def __init__(self, url=None, root_dir=None, relpath=None): | 122 def __init__(self, url=None, root_dir=None, relpath=None): |
| 120 self.url = url | 123 self.url = url |
| 121 self._root_dir = root_dir | 124 self._root_dir = root_dir |
| 122 if self._root_dir: | 125 if self._root_dir: |
| 123 self._root_dir = self._root_dir.replace('/', os.sep) | 126 self._root_dir = self._root_dir.replace('/', os.sep) |
| 124 self.relpath = relpath | 127 self.relpath = relpath |
| 125 if self.relpath: | 128 if self.relpath: |
| 126 self.relpath = self.relpath.replace('/', os.sep) | 129 self.relpath = self.relpath.replace('/', os.sep) |
| 127 if self.relpath and self._root_dir: | 130 if self.relpath and self._root_dir: |
| 128 self.checkout_path = os.path.join(self._root_dir, self.relpath) | 131 self.checkout_path = os.path.join(self._root_dir, self.relpath) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 """Generates a patch file which can be applied to the root of the | 191 """Generates a patch file which can be applied to the root of the |
| 189 repository. | 192 repository. |
| 190 | 193 |
| 191 The patch file is generated from a diff of the merge base of HEAD and | 194 The patch file is generated from a diff of the merge base of HEAD and |
| 192 its upstream branch. | 195 its upstream branch. |
| 193 """ | 196 """ |
| 194 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 197 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) |
| 195 gclient_utils.CheckCallAndFilter( | 198 gclient_utils.CheckCallAndFilter( |
| 196 ['git', 'diff', merge_base], | 199 ['git', 'diff', merge_base], |
| 197 cwd=self.checkout_path, | 200 cwd=self.checkout_path, |
| 201 nag_timer=self.nag_timer, |
| 202 nag_max=self.nag_max, |
| 198 filter_fn=GitDiffFilterer(self.relpath).Filter) | 203 filter_fn=GitDiffFilterer(self.relpath).Filter) |
| 199 | 204 |
| 200 def UpdateSubmoduleConfig(self): | 205 def UpdateSubmoduleConfig(self): |
| 201 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', | 206 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', |
| 202 'submodule.$name.ignore', '||', | 207 'submodule.$name.ignore', '||', |
| 203 'git', 'config', '-f', '$toplevel/.git/config', | 208 'git', 'config', '-f', '$toplevel/.git/config', |
| 204 'submodule.$name.ignore', 'all'] | 209 'submodule.$name.ignore', 'all'] |
| 205 cmd = ['git', 'submodule', '--quiet', 'foreach', ' '.join(submod_cmd)] | 210 cmd = ['git', 'submodule', '--quiet', 'foreach', ' '.join(submod_cmd)] |
| 206 cmd2 = ['git', 'config', 'diff.ignoreSubmodules', 'all'] | 211 cmd2 = ['git', 'config', 'diff.ignoreSubmodules', 'all'] |
| 207 cmd3 = ['git', 'config', 'branch.autosetupmerge'] | 212 cmd3 = ['git', 'config', 'branch.autosetupmerge'] |
| 208 cmd4 = ['git', 'config', 'fetch.recurseSubmodules', 'false'] | 213 cmd4 = ['git', 'config', 'fetch.recurseSubmodules', 'false'] |
| 209 kwargs = {'cwd': self.checkout_path, | 214 kwargs = {'cwd': self.checkout_path, |
| 210 'print_stdout': False, | 215 'print_stdout': False, |
| 216 'nag_timer': self.nag_timer, |
| 217 'nag_max': self.nag_max, |
| 211 'filter_fn': lambda x: None} | 218 'filter_fn': lambda x: None} |
| 212 try: | 219 try: |
| 213 gclient_utils.CheckCallAndFilter(cmd, **kwargs) | 220 gclient_utils.CheckCallAndFilter(cmd, **kwargs) |
| 214 gclient_utils.CheckCallAndFilter(cmd2, **kwargs) | 221 gclient_utils.CheckCallAndFilter(cmd2, **kwargs) |
| 215 except subprocess2.CalledProcessError: | 222 except subprocess2.CalledProcessError: |
| 216 # Not a fatal error, or even very interesting in a non-git-submodule | 223 # Not a fatal error, or even very interesting in a non-git-submodule |
| 217 # world. So just keep it quiet. | 224 # world. So just keep it quiet. |
| 218 pass | 225 pass |
| 219 try: | 226 try: |
| 220 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) | 227 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 # Returns name of current branch or None for detached HEAD | 852 # Returns name of current branch or None for detached HEAD |
| 846 branch = self._Capture(['rev-parse', '--abbrev-ref=strict', 'HEAD']) | 853 branch = self._Capture(['rev-parse', '--abbrev-ref=strict', 'HEAD']) |
| 847 if branch == 'HEAD': | 854 if branch == 'HEAD': |
| 848 return None | 855 return None |
| 849 return branch | 856 return branch |
| 850 | 857 |
| 851 def _Capture(self, args): | 858 def _Capture(self, args): |
| 852 return subprocess2.check_output( | 859 return subprocess2.check_output( |
| 853 ['git'] + args, | 860 ['git'] + args, |
| 854 stderr=subprocess2.PIPE, | 861 stderr=subprocess2.PIPE, |
| 862 nag_timer=self.nag_timer, |
| 863 nag_max=self.nag_max, |
| 855 cwd=self.checkout_path).strip() | 864 cwd=self.checkout_path).strip() |
| 856 | 865 |
| 857 def _UpdateBranchHeads(self, options, fetch=False): | 866 def _UpdateBranchHeads(self, options, fetch=False): |
| 858 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" | 867 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" |
| 859 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: | 868 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: |
| 860 backoff_time = 5 | 869 backoff_time = 5 |
| 861 for _ in range(3): | 870 for _ in range(3): |
| 862 try: | 871 try: |
| 863 config_cmd = ['config', 'remote.origin.fetch', | 872 config_cmd = ['config', 'remote.origin.fetch', |
| 864 '+refs/branch-heads/*:refs/remotes/branch-heads/*', | 873 '+refs/branch-heads/*:refs/remotes/branch-heads/*', |
| 865 '^\\+refs/branch-heads/\\*:.*$'] | 874 '^\\+refs/branch-heads/\\*:.*$'] |
| 866 self._Run(config_cmd, options) | 875 self._Run(config_cmd, options) |
| 867 if fetch: | 876 if fetch: |
| 868 fetch_cmd = ['fetch', 'origin'] | 877 fetch_cmd = ['fetch', 'origin'] |
| 869 if options.verbose: | 878 if options.verbose: |
| 870 fetch_cmd.append('--verbose') | 879 fetch_cmd.append('--verbose') |
| 871 self._Run(fetch_cmd, options) | 880 self._Run(fetch_cmd, options) |
| 872 break | 881 break |
| 873 except subprocess2.CalledProcessError, e: | 882 except subprocess2.CalledProcessError, e: |
| 874 print(str(e)) | 883 print(str(e)) |
| 875 print('Retrying in %.1f seconds...' % backoff_time) | 884 print('Retrying in %.1f seconds...' % backoff_time) |
| 876 time.sleep(backoff_time) | 885 time.sleep(backoff_time) |
| 877 backoff_time *= 1.3 | 886 backoff_time *= 1.3 |
| 878 | 887 |
| 879 def _Run(self, args, options, **kwargs): | 888 def _Run(self, args, options, **kwargs): |
| 880 kwargs.setdefault('cwd', self.checkout_path) | 889 kwargs.setdefault('cwd', self.checkout_path) |
| 881 kwargs.setdefault('print_stdout', True) | 890 kwargs.setdefault('print_stdout', True) |
| 891 kwargs.setdefault('nag_timer', self.nag_timer) |
| 892 kwargs.setdefault('nag_max', self.nag_max) |
| 882 stdout = kwargs.get('stdout', sys.stdout) | 893 stdout = kwargs.get('stdout', sys.stdout) |
| 883 stdout.write('\n________ running \'git %s\' in \'%s\'\n' % ( | 894 stdout.write('\n________ running \'git %s\' in \'%s\'\n' % ( |
| 884 ' '.join(args), kwargs['cwd'])) | 895 ' '.join(args), kwargs['cwd'])) |
| 885 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs) | 896 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs) |
| 886 | 897 |
| 887 | 898 |
| 888 class SVNWrapper(SCMWrapper): | 899 class SVNWrapper(SCMWrapper): |
| 889 """ Wrapper for SVN """ | 900 """ Wrapper for SVN """ |
| 890 | 901 |
| 891 @staticmethod | 902 @staticmethod |
| (...skipping 29 matching lines...) Expand all Loading... |
| 921 def pack(self, options, args, file_list): | 932 def pack(self, options, args, file_list): |
| 922 """Generates a patch file which can be applied to the root of the | 933 """Generates a patch file which can be applied to the root of the |
| 923 repository.""" | 934 repository.""" |
| 924 if not os.path.isdir(self.checkout_path): | 935 if not os.path.isdir(self.checkout_path): |
| 925 raise gclient_utils.Error('Directory %s is not present.' % | 936 raise gclient_utils.Error('Directory %s is not present.' % |
| 926 self.checkout_path) | 937 self.checkout_path) |
| 927 gclient_utils.CheckCallAndFilter( | 938 gclient_utils.CheckCallAndFilter( |
| 928 ['svn', 'diff', '-x', '--ignore-eol-style'] + args, | 939 ['svn', 'diff', '-x', '--ignore-eol-style'] + args, |
| 929 cwd=self.checkout_path, | 940 cwd=self.checkout_path, |
| 930 print_stdout=False, | 941 print_stdout=False, |
| 942 nag_timer=self.nag_timer, |
| 943 nag_max=self.nag_max, |
| 931 filter_fn=SvnDiffFilterer(self.relpath).Filter) | 944 filter_fn=SvnDiffFilterer(self.relpath).Filter) |
| 932 | 945 |
| 933 def update(self, options, args, file_list): | 946 def update(self, options, args, file_list): |
| 934 """Runs svn to update or transparently checkout the working copy. | 947 """Runs svn to update or transparently checkout the working copy. |
| 935 | 948 |
| 936 All updated files will be appended to file_list. | 949 All updated files will be appended to file_list. |
| 937 | 950 |
| 938 Raises: | 951 Raises: |
| 939 Error: if can't get URL for relative path. | 952 Error: if can't get URL for relative path. |
| 940 """ | 953 """ |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 'correct.') % rev) | 1231 'correct.') % rev) |
| 1219 return rev | 1232 return rev |
| 1220 | 1233 |
| 1221 def FullUrlForRelativeUrl(self, url): | 1234 def FullUrlForRelativeUrl(self, url): |
| 1222 # Find the forth '/' and strip from there. A bit hackish. | 1235 # Find the forth '/' and strip from there. A bit hackish. |
| 1223 return '/'.join(self.url.split('/')[:4]) + url | 1236 return '/'.join(self.url.split('/')[:4]) + url |
| 1224 | 1237 |
| 1225 def _Run(self, args, options, **kwargs): | 1238 def _Run(self, args, options, **kwargs): |
| 1226 """Runs a commands that goes to stdout.""" | 1239 """Runs a commands that goes to stdout.""" |
| 1227 kwargs.setdefault('cwd', self.checkout_path) | 1240 kwargs.setdefault('cwd', self.checkout_path) |
| 1241 kwargs.setdefault('nag_timer', self.nag_timer) |
| 1242 kwargs.setdefault('nag_max', self.nag_max) |
| 1228 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args, | 1243 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args, |
| 1229 always=options.verbose, **kwargs) | 1244 always=options.verbose, **kwargs) |
| 1230 | 1245 |
| 1231 def _RunAndGetFileList(self, args, options, file_list, cwd=None): | 1246 def _RunAndGetFileList(self, args, options, file_list, cwd=None): |
| 1232 """Runs a commands that goes to stdout and grabs the file listed.""" | 1247 """Runs a commands that goes to stdout and grabs the file listed.""" |
| 1233 cwd = cwd or self.checkout_path | 1248 cwd = cwd or self.checkout_path |
| 1234 scm.SVN.RunAndGetFileList( | 1249 scm.SVN.RunAndGetFileList( |
| 1235 options.verbose, | 1250 options.verbose, |
| 1236 args + ['--ignore-externals'], | 1251 args + ['--ignore-externals'], |
| 1237 cwd=cwd, | 1252 cwd=cwd, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1260 new_command.append('--force') | 1275 new_command.append('--force') |
| 1261 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1276 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1262 new_command.extend(('--accept', 'theirs-conflict')) | 1277 new_command.extend(('--accept', 'theirs-conflict')) |
| 1263 elif options.manually_grab_svn_rev: | 1278 elif options.manually_grab_svn_rev: |
| 1264 new_command.append('--force') | 1279 new_command.append('--force') |
| 1265 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1280 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1266 new_command.extend(('--accept', 'postpone')) | 1281 new_command.extend(('--accept', 'postpone')) |
| 1267 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1282 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1268 new_command.extend(('--accept', 'postpone')) | 1283 new_command.extend(('--accept', 'postpone')) |
| 1269 return new_command | 1284 return new_command |
| OLD | NEW |