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