Show More
@@ -16,4 +16,4 b'' | |||
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | |
|
18 | 18 | |
|
19 | from .app import create_app | |
|
19 | from .app import create_app # noqa |
@@ -17,7 +17,6 b'' | |||
|
17 | 17 | |
|
18 | 18 | import re |
|
19 | 19 | import logging |
|
20 | from wsgiref.util import FileWrapper | |
|
21 | 20 | |
|
22 | 21 | from pyramid.config import Configurator |
|
23 | 22 | from pyramid.response import Response, FileIter |
@@ -33,7 +32,7 b' from vcsserver.str_utils import safe_int' | |||
|
33 | 32 | log = logging.getLogger(__name__) |
|
34 | 33 | |
|
35 | 34 | |
|
36 | GIT_LFS_CONTENT_TYPE = 'application/vnd.git-lfs' #+json ? | |
|
35 | GIT_LFS_CONTENT_TYPE = 'application/vnd.git-lfs' # +json ? | |
|
37 | 36 | GIT_LFS_PROTO_PAT = re.compile(r'^/(.+)/(info/lfs/(.+))') |
|
38 | 37 | |
|
39 | 38 |
@@ -35,7 +35,7 b' import mercurial.node' | |||
|
35 | 35 | from vcsserver.lib.rc_json import json |
|
36 | 36 | from vcsserver import exceptions, subprocessio, settings |
|
37 | 37 | from vcsserver.str_utils import ascii_str, safe_str |
|
38 | from vcsserver.remote.git import Repository | |
|
38 | from vcsserver.remote.git_remote import Repository | |
|
39 | 39 | |
|
40 | 40 | log = logging.getLogger(__name__) |
|
41 | 41 |
@@ -40,20 +40,7 b' from vcsserver.lib.rc_json import json' | |||
|
40 | 40 | from vcsserver.config.settings_maker import SettingsMaker |
|
41 | 41 | from vcsserver.str_utils import safe_int |
|
42 | 42 | from vcsserver.lib.statsd_client import StatsdClient |
|
43 |
from vcsserver.tweens.request_wrapper import |
|
|
44 | ||
|
45 | log = logging.getLogger(__name__) | |
|
46 | ||
|
47 | # due to Mercurial/glibc2.27 problems we need to detect if locale settings are | |
|
48 | # causing problems and "fix" it in case they do and fallback to LC_ALL = C | |
|
49 | ||
|
50 | try: | |
|
51 | locale.setlocale(locale.LC_ALL, '') | |
|
52 | except locale.Error as e: | |
|
53 | log.error( | |
|
54 | 'LOCALE ERROR: failed to set LC_ALL, fallback to LC_ALL=C, org error: %s', e) | |
|
55 | os.environ['LC_ALL'] = 'C' | |
|
56 | ||
|
43 | from vcsserver.tweens.request_wrapper import get_headers_call_context | |
|
57 | 44 | |
|
58 | 45 | import vcsserver |
|
59 | 46 | from vcsserver import remote_wsgi, scm_app, settings, hgpatches |
@@ -68,7 +55,7 b' strict_vcs = True' | |||
|
68 | 55 | |
|
69 | 56 | git_import_err = None |
|
70 | 57 | try: |
|
71 | from vcsserver.remote.git import GitFactory, GitRemote | |
|
58 | from vcsserver.remote.git_remote import GitFactory, GitRemote | |
|
72 | 59 | except ImportError as e: |
|
73 | 60 | GitFactory = None |
|
74 | 61 | GitRemote = None |
@@ -79,7 +66,7 b' except ImportError as e:' | |||
|
79 | 66 | |
|
80 | 67 | hg_import_err = None |
|
81 | 68 | try: |
|
82 | from vcsserver.remote.hg import MercurialFactory, HgRemote | |
|
69 | from vcsserver.remote.hg_remote import MercurialFactory, HgRemote | |
|
83 | 70 | except ImportError as e: |
|
84 | 71 | MercurialFactory = None |
|
85 | 72 | HgRemote = None |
@@ -90,7 +77,7 b' except ImportError as e:' | |||
|
90 | 77 | |
|
91 | 78 | svn_import_err = None |
|
92 | 79 | try: |
|
93 | from vcsserver.remote.svn import SubversionFactory, SvnRemote | |
|
80 | from vcsserver.remote.svn_remote import SubversionFactory, SvnRemote | |
|
94 | 81 | except ImportError as e: |
|
95 | 82 | SubversionFactory = None |
|
96 | 83 | SvnRemote = None |
@@ -98,6 +85,18 b' except ImportError as e:' | |||
|
98 | 85 | if strict_vcs: |
|
99 | 86 | raise |
|
100 | 87 | |
|
88 | log = logging.getLogger(__name__) | |
|
89 | ||
|
90 | # due to Mercurial/glibc2.27 problems we need to detect if locale settings are | |
|
91 | # causing problems and "fix" it in case they do and fallback to LC_ALL = C | |
|
92 | ||
|
93 | try: | |
|
94 | locale.setlocale(locale.LC_ALL, '') | |
|
95 | except locale.Error as e: | |
|
96 | log.error( | |
|
97 | 'LOCALE ERROR: failed to set LC_ALL, fallback to LC_ALL=C, org error: %s', e) | |
|
98 | os.environ['LC_ALL'] = 'C' | |
|
99 | ||
|
101 | 100 | |
|
102 | 101 | def _is_request_chunked(environ): |
|
103 | 102 | stream = environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked' |
@@ -444,10 +443,7 b' class HTTPApplication(object):' | |||
|
444 | 443 | method = method.split('stream:')[-1] |
|
445 | 444 | chunk_size = safe_int(payload.get('chunk_size')) or 4096 |
|
446 | 445 | |
|
447 | try: | |
|
448 | resp = getattr(remote, method)(*args, **kwargs) | |
|
449 | except Exception as e: | |
|
450 | raise | |
|
446 | resp = getattr(remote, method)(*args, **kwargs) | |
|
451 | 447 | |
|
452 | 448 | def get_chunked_data(method_resp): |
|
453 | 449 | stream = io.BytesIO(method_resp) |
@@ -694,7 +690,7 b' class ResponseFilter(object):' | |||
|
694 | 690 | |
|
695 | 691 | |
|
696 | 692 | def sanitize_settings_and_apply_defaults(global_config, settings): |
|
697 | global_settings_maker = SettingsMaker(global_config) | |
|
693 | _global_settings_maker = SettingsMaker(global_config) | |
|
698 | 694 | settings_maker = SettingsMaker(settings) |
|
699 | 695 | |
|
700 | 696 | settings_maker.make_setting('logging.autoconfigure', False, parser='bool') |
@@ -770,5 +766,3 b' def main(global_config, **settings):' | |||
|
770 | 766 | total_time = time.time() - start_time |
|
771 | 767 | log.info('Pyramid app created and configured in %.2fs', total_time) |
|
772 | 768 | return pyramid_app |
|
773 | ||
|
774 |
|
1 | NO CONTENT: file renamed from vcsserver/remote/git.py to vcsserver/remote/git_remote.py |
|
1 | NO CONTENT: file renamed from vcsserver/remote/hg.py to vcsserver/remote/hg_remote.py |
@@ -37,12 +37,20 b' import svn.fs # noqa' | |||
|
37 | 37 | import svn.repos # noqa |
|
38 | 38 | |
|
39 | 39 | from vcsserver import svn_diff, exceptions, subprocessio, settings |
|
40 | from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, store_archive_in_cache, BytesEnvelope, BinaryEnvelope | |
|
40 | from vcsserver.base import ( | |
|
41 | RepoFactory, | |
|
42 | raise_from_original, | |
|
43 | ArchiveNode, | |
|
44 | store_archive_in_cache, | |
|
45 | BytesEnvelope, | |
|
46 | BinaryEnvelope, | |
|
47 | ) | |
|
41 | 48 | from vcsserver.exceptions import NoContentException |
|
42 | 49 | from vcsserver.str_utils import safe_str, safe_bytes |
|
43 | 50 | from vcsserver.type_utils import assert_bytes |
|
44 | 51 | from vcsserver.vcs_base import RemoteBase |
|
45 | 52 | from vcsserver.lib.svnremoterepo import svnremoterepo |
|
53 | ||
|
46 | 54 | log = logging.getLogger(__name__) |
|
47 | 55 | |
|
48 | 56 |
@@ -21,7 +21,7 b' import pytest' | |||
|
21 | 21 | import dulwich.errors |
|
22 | 22 | from mock import Mock, patch |
|
23 | 23 | |
|
24 | from vcsserver.remote import git | |
|
24 | from vcsserver.remote import git_remote | |
|
25 | 25 | |
|
26 | 26 | SAMPLE_REFS = { |
|
27 | 27 | 'HEAD': 'fd627b9e0dd80b47be81af07c4a98518244ed2f7', |
@@ -33,17 +33,17 b' SAMPLE_REFS = {' | |||
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | @pytest.fixture |
|
36 | def git_remote(): | |
|
36 | def git_remote_fix(): | |
|
37 | 37 | """ |
|
38 | 38 | A GitRemote instance with a mock factory. |
|
39 | 39 | """ |
|
40 | 40 | factory = Mock() |
|
41 | remote = git.GitRemote(factory) | |
|
41 | remote = git_remote.GitRemote(factory) | |
|
42 | 42 | return remote |
|
43 | 43 | |
|
44 | 44 | |
|
45 | def test_discover_git_version(git_remote): | |
|
46 | version = git_remote.discover_git_version() | |
|
45 | def test_discover_git_version(git_remote_fix): | |
|
46 | version = git_remote_fix.discover_git_version() | |
|
47 | 47 | assert version |
|
48 | 48 | |
|
49 | 49 | |
@@ -52,7 +52,7 b' class TestGitFetch(object):' | |||
|
52 | 52 | self.mock_repo = Mock() |
|
53 | 53 | factory = Mock() |
|
54 | 54 | factory.repo = Mock(return_value=self.mock_repo) |
|
55 | self.remote_git = git.GitRemote(factory) | |
|
55 | self.remote_git = git_remote.GitRemote(factory) | |
|
56 | 56 | |
|
57 | 57 | def test_fetches_all_when_no_commit_ids_specified(self): |
|
58 | 58 | def side_effect(determine_wants, *args, **kwargs): |
@@ -85,14 +85,14 b' class TestGitFetch(object):' | |||
|
85 | 85 | |
|
86 | 86 | def test_get_remote_refs(self): |
|
87 | 87 | factory = Mock() |
|
88 | remote_git = git.GitRemote(factory) | |
|
89 | url = 'http://example.com/test/test.git' | |
|
88 | remote_git = git_remote.GitRemote(factory) | |
|
89 | url = 'https://example.com/test/test.git' | |
|
90 | 90 | sample_refs = { |
|
91 | 91 | 'refs/tags/v0.1.8': '74ebce002c088b8a5ecf40073db09375515ecd68', |
|
92 | 92 | 'refs/tags/v0.1.3': '5a3a8fb005554692b16e21dee62bf02667d8dc3e', |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | with patch('vcsserver.remote.git.Repo', create=False) as mock_repo: | |
|
95 | with patch('vcsserver.remote.git_remote.Repo', create=False) as mock_repo: | |
|
96 | 96 | mock_repo().get_refs.return_value = sample_refs |
|
97 | 97 | remote_refs = remote_git.get_remote_refs(wire={}, url=url) |
|
98 | 98 | mock_repo().get_refs.assert_called_once_with() |
@@ -103,14 +103,14 b' class TestReraiseSafeExceptions(object):' | |||
|
103 | 103 | |
|
104 | 104 | def test_method_decorated_with_reraise_safe_exceptions(self): |
|
105 | 105 | factory = Mock() |
|
106 | git_remote = git.GitRemote(factory) | |
|
106 | git_remote_instance = git_remote.GitRemote(factory) | |
|
107 | 107 | |
|
108 | 108 | def fake_function(): |
|
109 | 109 | return None |
|
110 | 110 | |
|
111 | decorator = git.reraise_safe_exceptions(fake_function) | |
|
111 | decorator = git_remote.reraise_safe_exceptions(fake_function) | |
|
112 | 112 | |
|
113 | methods = inspect.getmembers(git_remote, predicate=inspect.ismethod) | |
|
113 | methods = inspect.getmembers(git_remote_instance, predicate=inspect.ismethod) | |
|
114 | 114 | for method_name, method in methods: |
|
115 | 115 | if not method_name.startswith('_') and method_name not in ['vcsserver_invalidate_cache']: |
|
116 | 116 | assert method.__func__.__code__ == decorator.__code__ |
@@ -124,7 +124,7 b' class TestReraiseSafeExceptions(object):' | |||
|
124 | 124 | (dulwich.errors.UnexpectedCommandError('test-cmd'), 'error'), |
|
125 | 125 | ]) |
|
126 | 126 | def test_safe_exceptions_reraised(self, side_effect, expected_type): |
|
127 | @git.reraise_safe_exceptions | |
|
127 | @git_remote.reraise_safe_exceptions | |
|
128 | 128 | def fake_method(): |
|
129 | 129 | raise side_effect |
|
130 | 130 | |
@@ -137,9 +137,9 b' class TestReraiseSafeExceptions(object):' | |||
|
137 | 137 | class TestDulwichRepoWrapper(object): |
|
138 | 138 | def test_calls_close_on_delete(self): |
|
139 | 139 | isdir_patcher = patch('dulwich.repo.os.path.isdir', return_value=True) |
|
140 | with patch.object(git.Repo, 'close') as close_mock: | |
|
140 | with patch.object(git_remote.Repo, 'close') as close_mock: | |
|
141 | 141 | with isdir_patcher: |
|
142 | repo = git.Repo('/tmp/abcde') | |
|
142 | repo = git_remote.Repo('/tmp/abcde') | |
|
143 | 143 | assert repo is not None |
|
144 | 144 | repo.__del__() |
|
145 | 145 | # can't use del repo as in python3 this isn't always calling .__del__() |
@@ -152,11 +152,11 b' class TestGitFactory(object):' | |||
|
152 | 152 | |
|
153 | 153 | with patch('vcsserver.lib.rc_cache.region_meta.dogpile_cache_regions') as mock: |
|
154 | 154 | mock.side_effect = {'repo_objects': ''} |
|
155 | factory = git.GitFactory() | |
|
155 | factory = git_remote.GitFactory() | |
|
156 | 156 | wire = { |
|
157 | 157 | 'path': '/tmp/abcde' |
|
158 | 158 | } |
|
159 | 159 | isdir_patcher = patch('dulwich.repo.os.path.isdir', return_value=True) |
|
160 | 160 | with isdir_patcher: |
|
161 | 161 | result = factory._create_repo(wire, True) |
|
162 | assert isinstance(result, git.Repo) | |
|
162 | assert isinstance(result, git_remote.Repo) |
@@ -24,19 +24,19 b' from mercurial.error import LookupError' | |||
|
24 | 24 | from mock import Mock, patch |
|
25 | 25 | |
|
26 | 26 | from vcsserver import exceptions, hgcompat |
|
27 | from vcsserver.remote import hg | |
|
27 | from vcsserver.remote import hg_remote | |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | class TestDiff(object): |
|
31 | 31 | def test_raising_safe_exception_when_lookup_failed(self): |
|
32 | 32 | |
|
33 | 33 | factory = Mock() |
|
34 | hg_remote = hg.HgRemote(factory) | |
|
34 | hg_remote_instance = hg_remote.HgRemote(factory) | |
|
35 | 35 | with patch('mercurial.patch.diff') as diff_mock: |
|
36 | 36 | diff_mock.side_effect = LookupError(b'deadbeef', b'index', b'message') |
|
37 | 37 | |
|
38 | 38 | with pytest.raises(Exception) as exc_info: |
|
39 | hg_remote.diff( | |
|
39 | hg_remote_instance.diff( | |
|
40 | 40 | wire={}, commit_id_1='deadbeef', commit_id_2='deadbee1', |
|
41 | 41 | file_filter=None, opt_git=True, opt_ignorews=True, |
|
42 | 42 | context=3) |
@@ -45,25 +45,27 b' class TestDiff(object):' | |||
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | class TestReraiseSafeExceptions(object): |
|
48 | original_traceback = None | |
|
49 | ||
|
48 | 50 | def test_method_decorated_with_reraise_safe_exceptions(self): |
|
49 | 51 | factory = Mock() |
|
50 | hg_remote = hg.HgRemote(factory) | |
|
51 | methods = inspect.getmembers(hg_remote, predicate=inspect.ismethod) | |
|
52 | decorator = hg.reraise_safe_exceptions(None) | |
|
52 | hg_remote_instance = hg_remote.HgRemote(factory) | |
|
53 | methods = inspect.getmembers(hg_remote_instance, predicate=inspect.ismethod) | |
|
54 | decorator = hg_remote.reraise_safe_exceptions(None) | |
|
53 | 55 | for method_name, method in methods: |
|
54 | 56 | if not method_name.startswith('_') and method_name not in ['vcsserver_invalidate_cache']: |
|
55 | 57 | assert method.__func__.__code__ == decorator.__code__ |
|
56 | 58 | |
|
57 | 59 | @pytest.mark.parametrize('side_effect, expected_type', [ |
|
58 | (hgcompat.Abort('failed-abort'), 'abort'), | |
|
59 | (hgcompat.InterventionRequired('intervention-required'), 'abort'), | |
|
60 | (hgcompat.Abort(b'failed-abort'), 'abort'), | |
|
61 | (hgcompat.InterventionRequired(b'intervention-required'), 'abort'), | |
|
60 | 62 | (hgcompat.RepoLookupError(), 'lookup'), |
|
61 | 63 | (hgcompat.LookupError(b'deadbeef', b'index', b'message'), 'lookup'), |
|
62 | 64 | (hgcompat.RepoError(), 'error'), |
|
63 | 65 | (hgcompat.RequirementError(), 'requirement'), |
|
64 | 66 | ]) |
|
65 | 67 | def test_safe_exceptions_reraised(self, side_effect, expected_type): |
|
66 | @hg.reraise_safe_exceptions | |
|
68 | @hg_remote.reraise_safe_exceptions | |
|
67 | 69 | def fake_method(): |
|
68 | 70 | raise side_effect |
|
69 | 71 | |
@@ -73,14 +75,16 b' class TestReraiseSafeExceptions(object):' | |||
|
73 | 75 | assert exc_info.value._vcs_kind == expected_type |
|
74 | 76 | |
|
75 | 77 | def test_keeps_original_traceback(self): |
|
76 | @hg.reraise_safe_exceptions | |
|
78 | ||
|
79 | @hg_remote.reraise_safe_exceptions | |
|
77 | 80 | def fake_method(): |
|
78 | 81 | try: |
|
79 | raise hgcompat.Abort('test-abort') | |
|
82 | raise hgcompat.Abort(b'test-abort') | |
|
80 | 83 | except: |
|
81 | 84 | self.original_traceback = traceback.format_tb(sys.exc_info()[2]) |
|
82 | 85 | raise |
|
83 | 86 | |
|
87 | new_traceback = None | |
|
84 | 88 | try: |
|
85 | 89 | fake_method() |
|
86 | 90 | except Exception: |
@@ -89,8 +93,8 b' class TestReraiseSafeExceptions(object):' | |||
|
89 | 93 | new_traceback_tail = new_traceback[-len(self.original_traceback):] |
|
90 | 94 | assert new_traceback_tail == self.original_traceback |
|
91 | 95 | |
|
92 | def test_maps_unknow_exceptions_to_unhandled(self): | |
|
93 | @hg.reraise_safe_exceptions | |
|
96 | def test_maps_unknown_exceptions_to_unhandled(self): | |
|
97 | @hg_remote.reraise_safe_exceptions | |
|
94 | 98 | def stub_method(): |
|
95 | 99 | raise ValueError('stub') |
|
96 | 100 | |
@@ -99,7 +103,7 b' class TestReraiseSafeExceptions(object):' | |||
|
99 | 103 | assert exc_info.value._vcs_kind == 'unhandled' |
|
100 | 104 | |
|
101 | 105 | def test_does_not_map_known_exceptions(self): |
|
102 | @hg.reraise_safe_exceptions | |
|
106 | @hg_remote.reraise_safe_exceptions | |
|
103 | 107 | def stub_method(): |
|
104 | 108 | raise exceptions.LookupException()('stub') |
|
105 | 109 |
@@ -46,11 +46,11 b" INVALID_CERTIFICATE_STDERR = '\\n'.join([" | |||
|
46 | 46 | @pytest.mark.xfail(sys.platform == "cygwin", |
|
47 | 47 | reason="SVN not packaged for Cygwin") |
|
48 | 48 | def test_import_remote_repository_certificate_error(stderr, expected_reason): |
|
49 | from vcsserver.remote import svn | |
|
49 | from vcsserver.remote import svn_remote | |
|
50 | 50 | factory = mock.Mock() |
|
51 | 51 | factory.repo = mock.Mock(return_value=mock.Mock()) |
|
52 | 52 | |
|
53 | remote = svn.SvnRemote(factory) | |
|
53 | remote = svn_remote.SvnRemote(factory) | |
|
54 | 54 | remote.is_path_valid_repository = lambda wire, path: True |
|
55 | 55 | |
|
56 | 56 | with mock.patch('subprocess.Popen', |
@@ -64,7 +64,7 b' def test_import_remote_repository_certif' | |||
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | def test_svn_libraries_can_be_imported(): |
|
67 | import svn.client | |
|
67 | import svn.client # noqa | |
|
68 | 68 | assert svn.client is not None |
|
69 | 69 | |
|
70 | 70 | |
@@ -76,12 +76,12 b' def test_svn_libraries_can_be_imported()' | |||
|
76 | 76 | ('http://', ('', '', 'http://')), |
|
77 | 77 | ]) |
|
78 | 78 | def test_username_password_extraction_from_url(example_url, parts): |
|
79 | from vcsserver.remote import svn | |
|
79 | from vcsserver.remote import svn_remote | |
|
80 | 80 | |
|
81 | 81 | factory = mock.Mock() |
|
82 | 82 | factory.repo = mock.Mock(return_value=mock.Mock()) |
|
83 | 83 | |
|
84 | remote = svn.SvnRemote(factory) | |
|
84 | remote = svn_remote.SvnRemote(factory) | |
|
85 | 85 | remote.is_path_valid_repository = lambda wire, path: True |
|
86 | 86 | |
|
87 | 87 | assert remote.get_url_and_credentials(example_url) == parts |
@@ -93,11 +93,11 b' def test_username_password_extraction_fr' | |||
|
93 | 93 | b'https://marcink:qweqwe@svn.code.sf.net/p/svnbook/source/trunk/', |
|
94 | 94 | ]) |
|
95 | 95 | def test_check_url(call_url): |
|
96 | from vcsserver.remote import svn | |
|
96 | from vcsserver.remote import svn_remote | |
|
97 | 97 | factory = mock.Mock() |
|
98 | 98 | factory.repo = mock.Mock(return_value=mock.Mock()) |
|
99 | 99 | |
|
100 | remote = svn.SvnRemote(factory) | |
|
100 | remote = svn_remote.SvnRemote(factory) | |
|
101 | 101 | remote.is_path_valid_repository = lambda wire, path: True |
|
102 | 102 | assert remote.check_url(call_url, {'dummy': 'config'}) |
|
103 | 103 |
@@ -15,13 +15,13 b'' | |||
|
15 | 15 | # along with this program; if not, write to the Free Software Foundation, |
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | import base64 |
|
18 | import logging | |
|
18 | 19 | import time |
|
19 | import logging | |
|
20 | 20 | |
|
21 | 21 | import msgpack |
|
22 | 22 | |
|
23 | 23 | import vcsserver |
|
24 |
from vcsserver.str_utils import safe_str |
|
|
24 | from vcsserver.str_utils import safe_str | |
|
25 | 25 | |
|
26 | 26 | log = logging.getLogger(__name__) |
|
27 | 27 |
General Comments 0
You need to be logged in to leave comments.
Login now