# HG changeset patch # User Marcin Kuzminski # Date 2019-01-08 10:47:29 # Node ID df15fe03b7d8612b5833848a7d97e8a68749d2f9 # Parent f216af0db3b47b5723b069e730bb2a4b7f9c5cd1 git: use iterative fetch to prevent errors about too many arguments on very large repositories. diff --git a/vcsserver/git.py b/vcsserver/git.py --- a/vcsserver/git.py +++ b/vcsserver/git.py @@ -25,6 +25,7 @@ import urllib import urllib2 from functools import wraps +import more_itertools from dulwich import index, objects from dulwich.client import HttpGitClient, LocalGitClient from dulwich.errors import ( @@ -495,13 +496,16 @@ class GitRemote(object): fetch_refs.append('{}:{}'.format(ref, ref)) elif not refs: fetch_refs.append('{}:{}'.format(ref, ref)) - + log.debug('Finished obtaining fetch refs, total: %s', len(fetch_refs)) if fetch_refs: - _out, _err = self.run_git_command( - wire, ['fetch', url, '--force', '--prune', '--'] + fetch_refs, - fail_on_stderr=False, - _copts=self._remote_conf(config), - extra_env={'GIT_TERMINAL_PROMPT': '0'}) + for chunk in more_itertools.chunked(fetch_refs, 1024 * 4): + fetch_refs_chunks = list(chunk) + log.debug('Fetching %s refs from import url', len(fetch_refs_chunks)) + _out, _err = self.run_git_command( + wire, ['fetch', url, '--force', '--prune', '--'] + fetch_refs_chunks, + fail_on_stderr=False, + _copts=self._remote_conf(config), + extra_env={'GIT_TERMINAL_PROMPT': '0'}) return remote_refs