# HG changeset patch # User Marcin Kuzminski # Date 2017-09-07 20:48:13 # Node ID 6ed1dd13d98f46cee2b560e5e8aeaa24c18de8bd # Parent 195e394c42f4723bf2b67cab1b890b04b16f9568 git: make sure we don't break streaming in case of empty pull messages. This allows much efficient streaming of data. Most cases don't have post message and we shouldn't extract date from iterator in such cases. diff --git a/vcsserver/pygrack.py b/vcsserver/pygrack.py --- a/vcsserver/pygrack.py +++ b/vcsserver/pygrack.py @@ -229,7 +229,7 @@ class GitRepository(object): def _inject_messages_to_response(self, response, capabilities, start_messages, end_messages): """ - Given a list reponse we inject the pre/post-pull messages. + Given a list response we inject the pre/post-pull messages. We only inject the messages if the client supports sideband, and the response has the format: @@ -241,13 +241,18 @@ class GitRepository(object): if not self.SIDE_BAND_CAPS.intersection(capabilities): return response + if not start_messages and not end_messages: + return response + + # make a list out of response if it's an iterator + # so we can investigate it for message injection. + if hasattr(response, '__iter__'): + response = list(response) + if (not response[0].startswith('0008NAK\n') or not response[-1].endswith('0000')): return response - if not start_messages and not end_messages: - return response - new_response = ['0008NAK\n'] new_response.extend(self._get_messages(start_messages, capabilities)) if len(response) == 1: @@ -303,6 +308,7 @@ class GitRepository(object): git_command.encode('utf8')) resp.charset = None + pre_pull_messages = '' if git_command == 'git-upload-pack': status, pre_pull_messages = hooks.git_pre_pull(self.extras) if status != 0: @@ -352,7 +358,6 @@ class GitRepository(object): pass if git_command == 'git-upload-pack': - out = list(out) unused_status, post_pull_messages = hooks.git_post_pull(self.extras) resp.app_iter = self._inject_messages_to_response( out, capabilities, pre_pull_messages, post_pull_messages)