Chromium Code Reviews| Index: gclient_scm.py |
| diff --git a/gclient_scm.py b/gclient_scm.py |
| index 7a918b8b5f699d32b7e708eef2ce8bbef24cf278..b183f91f8ab66412535dae41dfc362f5bfc646a9 100644 |
| --- a/gclient_scm.py |
| +++ b/gclient_scm.py |
| @@ -300,9 +300,7 @@ class GitWrapper(SCMWrapper): |
| quiet = ['--quiet'] |
| self._UpdateBranchHeads(options, fetch=False) |
| - cfg = gclient_utils.DefaultIndexPackConfig(self.url) |
| - fetch_cmd = cfg + ['fetch', self.remote, '--prune'] |
| - self._Run(fetch_cmd + quiet, options, retry=True) |
| + self._Fetch(options, prune=True, quiet=options.verbose) |
| self._Run(['reset', '--hard', revision] + quiet, options) |
| if file_list is not None: |
| files = self._Capture(['ls-files']).splitlines() |
| @@ -696,7 +694,7 @@ class GitWrapper(SCMWrapper): |
| logging.debug('Looking for git-svn configuration optimizations.') |
| if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
| cwd=self.checkout_path): |
| - scm.GIT.Capture(['fetch'], cwd=self.checkout_path) |
| + self._Fetch(options) |
| except subprocess2.CalledProcessError: |
| logging.debug('git config --get svn-remote.svn.fetch failed, ' |
| 'ignoring possible optimization.') |
| @@ -724,7 +722,7 @@ class GitWrapper(SCMWrapper): |
| else: |
| # May exist in origin, but we don't have it yet, so fetch and look |
| # again. |
| - scm.GIT.Capture(['fetch', self.remote], cwd=self.checkout_path) |
| + self._Fetch(options) |
| if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
| sha1 = rev |
| @@ -1012,6 +1010,23 @@ class GitWrapper(SCMWrapper): |
| checkout_args.append(ref) |
| return self._Capture(checkout_args) |
| + def _Fetch(self, options, remote=None, prune=False, quiet=False): |
| + if remote is None: |
| + remote = self.remote |
| + cfg = gclient_utils.DefaultIndexPackConfig(self.url) |
| + fetch_cmd = cfg + ['fetch', remote] |
| + |
| + if prune: |
| + fetch_cmd.append('--prune') |
| + if options.verbose: |
| + fetch_cmd.append('--verbose') |
| + elif quiet: |
| + fetch_cmd.append('--quiet') |
| + self._Run(fetch_cmd, options, _show_header=options.verbose, retry=True) |
| + |
| + # Return the revision that was fetched; this will be stored in 'FETCH_HEAD' |
| + return self._Capture(['rev-parse', '--verify', 'FETCH_HEAD']) |
| + |
| def _UpdateBranchHeads(self, options, fetch=False): |
| """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" |
| if hasattr(options, 'with_branch_heads') and options.with_branch_heads: |
| @@ -1020,21 +1035,19 @@ class GitWrapper(SCMWrapper): |
| '^\\+refs/branch-heads/\\*:.*$'] |
| self._Run(config_cmd, options) |
| if fetch: |
| - cfg = gclient_utils.DefaultIndexPackConfig(self.url) |
| - fetch_cmd = cfg + ['fetch', self.remote] |
| - if options.verbose: |
| - fetch_cmd.append('--verbose') |
| - self._Run(fetch_cmd, options, retry=True) |
| + self._Fetch(options) |
| - def _Run(self, args, options, **kwargs): |
| + def _Run(self, args, options, _show_header=True, **kwargs): |
|
M-A Ruel
2014/06/24 21:11:52
Why an underscore prefix?
dnj
2014/06/24 21:45:23
The thought is that since this is opaquely wrappin
|
| + # Disable 'unused options' warning | pylint: disable=W0613 |
| cwd = kwargs.setdefault('cwd', self.checkout_path) |
| kwargs.setdefault('stdout', self.out_fh) |
| kwargs['filter_fn'] = self.filter |
| kwargs.setdefault('print_stdout', False) |
| env = scm.GIT.ApplyEnvVars(kwargs) |
| cmd = ['git'] + args |
| - header = "running '%s' in '%s'" % (' '.join(cmd), cwd) |
| - self.filter(header) |
| + if _show_header: |
| + header = "running '%s' in '%s'" % (' '.join(cmd), cwd) |
| + self.filter(header) |
| return gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs) |