diff --git a/docs/release-notes/release-notes-5.5.1.rst b/docs/release-notes/release-notes-5.5.1.rst index 43029d86..b5a0fc6a 100644 --- a/docs/release-notes/release-notes-5.5.1.rst +++ b/docs/release-notes/release-notes-5.5.1.rst @@ -30,6 +30,7 @@ Fixes ^^^^^ - Fixed issues with caches key on windows WSL that were over 255 characters +- Fix for SVN dumps with empty revisions Upgrade notes diff --git a/rhodecode/api/tests/test_get_repo_changeset.py b/rhodecode/api/tests/test_get_repo_changeset.py index 36580ad1..a6121a37 100644 --- a/rhodecode/api/tests/test_get_repo_changeset.py +++ b/rhodecode/api/tests/test_get_repo_changeset.py @@ -155,3 +155,26 @@ class TestGetRepoChangeset(object): response = api_call(self.app, params) expected = "commit_id must be a string value got instead" assert_error(id_, expected, given=response.body) + + @pytest.mark.parametrize("details", ["basic", "extended", "full"]) + def test_get_repo_changeset_empty_revs(self, details, backend_svn): + """ + Test case for repositories with empty revisions. + Ensures that no crashes occur and an empty list is returned. + """ + empty_rev_id = "1000" + + __, params = build_data( + self.apikey, + "get_repo_changesets", + repoid=backend_svn.repo_name, + start_rev=empty_rev_id, + limit=10, + details=details, + ) + + response = api_call(self.app, params) + result = response.json["result"] + + assert isinstance(result, list) + assert len(result) == 0 diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py index ee9fb1a7..bdd90be6 100644 --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -43,7 +43,7 @@ from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_str, safe_int from rhodecode.lib.ext_json import json from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError, CommentVersionMismatch from rhodecode.lib.vcs import RepositoryError -from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError +from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError, EmptyRepositoryError from rhodecode.model.changeset_status import ChangesetStatusModel from rhodecode.model.comment import CommentsModel from rhodecode.model.db import Session, ChangesetStatus, RepositoryField, Repository, RepoGroup, ChangesetComment @@ -393,6 +393,8 @@ def get_repo_changesets(request, apiuser, repoid, start_rev, limit, details=Opti commits = vcs_repo.get_commits(start_id=start_rev, pre_load=pre_load, translate_tags=False) except TypeError as e: raise JSONRPCError(safe_str(e)) + except EmptyRepositoryError: + return [] except Exception: log.exception("Fetching of commits failed") raise JSONRPCError("Error occurred during commit fetching") diff --git a/rhodecode/lib/vcs/backends/svn/repository.py b/rhodecode/lib/vcs/backends/svn/repository.py index 2241ba43..d0ae04de 100644 --- a/rhodecode/lib/vcs/backends/svn/repository.py +++ b/rhodecode/lib/vcs/backends/svn/repository.py @@ -306,8 +306,13 @@ class SubversionRepository(base.BaseRepository): self._validate_commit_id(end_id) start_raw_id = self._sanitize_commit_id(start_id) - start_pos = self.commit_ids.index(start_raw_id) if start_id else None end_raw_id = self._sanitize_commit_id(end_id) + + # for empty revisions in SVN + if start_raw_id not in self.commit_ids or end_raw_id not in self.commit_ids: + return base.CollectionGenerator(self, []) + + start_pos = self.commit_ids.index(start_raw_id) if start_id else None end_pos = max(0, self.commit_ids.index(end_raw_id)) if end_id else None if None not in [start_id, end_id] and start_pos > end_pos: