Show More
@@ -1880,6 +1880,8 b' get_repo_nodes' | |||||
1880 | md5, binary, and or content. The valid options are ``basic`` and |
|
1880 | md5, binary, and or content. The valid options are ``basic`` and | |
1881 | ``full``. |
|
1881 | ``full``. | |
1882 | :type details: Optional(str) |
|
1882 | :type details: Optional(str) | |
|
1883 | :param max_file_bytes: Only return file content under this file size bytes | |||
|
1884 | :type details: Optional(int) | |||
1883 |
|
1885 | |||
1884 | Example output: |
|
1886 | Example output: | |
1885 |
|
1887 | |||
@@ -2821,4 +2823,3 b' delete_gist' | |||||
2821 | error : { |
|
2823 | error : { | |
2822 | "failed to delete gist ID:<gist_id>" |
|
2824 | "failed to delete gist ID:<gist_id>" | |
2823 | } |
|
2825 | } | |
2824 |
|
@@ -73,6 +73,29 b' class TestGetRepoNodes(object):' | |||||
73 | expected = 'failed to get repo: `%s` nodes' % (backend.repo_name,) |
|
73 | expected = 'failed to get repo: `%s` nodes' % (backend.repo_name,) | |
74 | assert_error(id_, expected, given=response.body) |
|
74 | assert_error(id_, expected, given=response.body) | |
75 |
|
75 | |||
|
76 | def test_api_get_repo_nodes_max_file_bytes(self, backend): | |||
|
77 | commit_id = 'tip' | |||
|
78 | path = '/' | |||
|
79 | max_file_bytes = 500 | |||
|
80 | ||||
|
81 | id_, params = build_data( | |||
|
82 | self.apikey, 'get_repo_nodes', | |||
|
83 | repoid=backend.repo_name, revision=commit_id, details='full', | |||
|
84 | root_path=path) | |||
|
85 | response = api_call(self.app, params) | |||
|
86 | assert any(file['content'] and len(file['content']) > max_file_bytes | |||
|
87 | for file in response.json['result']) | |||
|
88 | ||||
|
89 | id_, params = build_data( | |||
|
90 | self.apikey, 'get_repo_nodes', | |||
|
91 | repoid=backend.repo_name, revision=commit_id, | |||
|
92 | root_path=path, details='full', | |||
|
93 | max_file_bytes=max_file_bytes) | |||
|
94 | response = api_call(self.app, params) | |||
|
95 | assert all( | |||
|
96 | file['content'] is None if file['size'] > max_file_bytes else True | |||
|
97 | for file in response.json['result']) | |||
|
98 | ||||
76 | def test_api_get_repo_nodes_bad_ret_type(self, backend): |
|
99 | def test_api_get_repo_nodes_bad_ret_type(self, backend): | |
77 | commit_id = 'tip' |
|
100 | commit_id = 'tip' | |
78 | path = '/' |
|
101 | path = '/' |
@@ -400,7 +400,8 b' def get_repo_changesets(request, apiuser' | |||||
400 |
|
400 | |||
401 | @jsonrpc_method() |
|
401 | @jsonrpc_method() | |
402 | def get_repo_nodes(request, apiuser, repoid, revision, root_path, |
|
402 | def get_repo_nodes(request, apiuser, repoid, revision, root_path, | |
403 |
ret_type=Optional('all'), details=Optional('basic') |
|
403 | ret_type=Optional('all'), details=Optional('basic'), | |
|
404 | max_file_bytes=Optional(None)): | |||
404 | """ |
|
405 | """ | |
405 | Returns a list of nodes and children in a flat list for a given |
|
406 | Returns a list of nodes and children in a flat list for a given | |
406 | path at given revision. |
|
407 | path at given revision. | |
@@ -425,6 +426,8 b' def get_repo_nodes(request, apiuser, rep' | |||||
425 | md5, binary, and or content. The valid options are ``basic`` and |
|
426 | md5, binary, and or content. The valid options are ``basic`` and | |
426 | ``full``. |
|
427 | ``full``. | |
427 | :type details: Optional(str) |
|
428 | :type details: Optional(str) | |
|
429 | :param max_file_bytes: Only return file content under this file size bytes | |||
|
430 | :type details: Optional(int) | |||
428 |
|
431 | |||
429 | Example output: |
|
432 | Example output: | |
430 |
|
433 | |||
@@ -472,7 +475,8 b' def get_repo_nodes(request, apiuser, rep' | |||||
472 |
|
475 | |||
473 | _d, _f = ScmModel().get_nodes( |
|
476 | _d, _f = ScmModel().get_nodes( | |
474 | repo, revision, root_path, flat=False, |
|
477 | repo, revision, root_path, flat=False, | |
475 |
extended_info=extended_info, content=content |
|
478 | extended_info=extended_info, content=content, | |
|
479 | max_file_bytes=max_file_bytes) | |||
476 | _map = { |
|
480 | _map = { | |
477 | 'all': _d + _f, |
|
481 | 'all': _d + _f, | |
478 | 'files': _f, |
|
482 | 'files': _f, |
@@ -478,7 +478,7 b' class ScmModel(BaseModel):' | |||||
478 | return data |
|
478 | return data | |
479 |
|
479 | |||
480 | def get_nodes(self, repo_name, commit_id, root_path='/', flat=True, |
|
480 | def get_nodes(self, repo_name, commit_id, root_path='/', flat=True, | |
481 | extended_info=False, content=False): |
|
481 | extended_info=False, content=False, max_file_bytes=None): | |
482 | """ |
|
482 | """ | |
483 | recursive walk in root dir and return a set of all path in that dir |
|
483 | recursive walk in root dir and return a set of all path in that dir | |
484 | based on repository walk function |
|
484 | based on repository walk function | |
@@ -487,6 +487,7 b' class ScmModel(BaseModel):' | |||||
487 | :param commit_id: commit id for which to list nodes |
|
487 | :param commit_id: commit id for which to list nodes | |
488 | :param root_path: root path to list |
|
488 | :param root_path: root path to list | |
489 | :param flat: return as a list, if False returns a dict with description |
|
489 | :param flat: return as a list, if False returns a dict with description | |
|
490 | :param max_file_bytes: will not return file contents over this limit | |||
490 |
|
491 | |||
491 | """ |
|
492 | """ | |
492 | _files = list() |
|
493 | _files = list() | |
@@ -499,6 +500,8 b' class ScmModel(BaseModel):' | |||||
499 | for f in files: |
|
500 | for f in files: | |
500 | _content = None |
|
501 | _content = None | |
501 | _data = f.unicode_path |
|
502 | _data = f.unicode_path | |
|
503 | over_size_limit = (max_file_bytes is not None | |||
|
504 | and f.size > max_file_bytes) | |||
502 |
|
505 | |||
503 | if not flat: |
|
506 | if not flat: | |
504 | _data = { |
|
507 | _data = { | |
@@ -517,7 +520,7 b' class ScmModel(BaseModel):' | |||||
517 |
|
520 | |||
518 | if content: |
|
521 | if content: | |
519 | full_content = None |
|
522 | full_content = None | |
520 | if not f.is_binary: |
|
523 | if not f.is_binary and not over_size_limit: | |
521 | full_content = safe_str(f.content) |
|
524 | full_content = safe_str(f.content) | |
522 |
|
525 | |||
523 | _data.update({ |
|
526 | _data.update({ | |
@@ -1096,4 +1099,4 b' def _check_rhodecode_hook(hook_path):' | |||||
1096 | def _read_hook(hook_path): |
|
1099 | def _read_hook(hook_path): | |
1097 | with open(hook_path, 'rb') as f: |
|
1100 | with open(hook_path, 'rb') as f: | |
1098 | content = f.read() |
|
1101 | content = f.read() | |
1099 | return content No newline at end of file |
|
1102 | return content |
@@ -148,6 +148,23 b' def test_get_nodes_returns_unicode_non_f' | |||||
148 | assert_contains_only_unicode([f['name'] for f in files]) |
|
148 | assert_contains_only_unicode([f['name'] for f in files]) | |
149 |
|
149 | |||
150 |
|
150 | |||
|
151 | def test_get_nodes_max_file_bytes(backend_random): | |||
|
152 | repo = backend_random.repo | |||
|
153 | max_file_bytes = 10 | |||
|
154 | directories, files = scm.ScmModel().get_nodes( | |||
|
155 | repo.repo_name, repo.get_commit(commit_idx=0).raw_id, content=True, | |||
|
156 | extended_info=True, flat=False) | |||
|
157 | assert any(file['content'] and len(file['content']) > max_file_bytes | |||
|
158 | for file in files) | |||
|
159 | ||||
|
160 | directories, files = scm.ScmModel().get_nodes( | |||
|
161 | repo.repo_name, repo.get_commit(commit_idx=0).raw_id, content=True, | |||
|
162 | extended_info=True, flat=False, max_file_bytes=max_file_bytes) | |||
|
163 | assert all( | |||
|
164 | file['content'] is None if file['size'] > max_file_bytes else True | |||
|
165 | for file in files) | |||
|
166 | ||||
|
167 | ||||
151 | def assert_contains_only_unicode(structure): |
|
168 | def assert_contains_only_unicode(structure): | |
152 | assert structure |
|
169 | assert structure | |
153 | for value in structure: |
|
170 | for value in structure: |
General Comments 0
You need to be logged in to leave comments.
Login now