# HG changeset patch # User domruf # Date 2018-01-20 02:24:38 # Node ID bfb1ae42bcbbfb6daf5f6a1da4cc896a5eee7a28 # Parent dc7e37ec3dfd6db0c68105351dc763dbb261e521 vcs: fix get_changesets filtering on hg repo to AND the criteria instead of OR Mercurial scmutil.revrange takes a list of filters ... and OR them. But when for example a user uses the api and sets branch name and date, he would expect to only get revisions from the provided branch. So we need to use AND when filtering. When using AND, the special handling of start_date and end_date is no longer necessary. Also add a test to check for this use case. diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py --- a/kallithea/lib/vcs/backends/hg/repository.py +++ b/kallithea/lib/vcs/backends/hg/repository.py @@ -540,14 +540,13 @@ class MercurialRepository(BaseRepository if branch_name: filter_.append('branch("%s")' % (branch_name)) - if start_date and not end_date: + if start_date: filter_.append('date(">%s")' % start_date) - if end_date and not start_date: + if end_date: filter_.append('date("<%s")' % end_date) - if start_date and end_date: - filter_.append('date(">%s") and date("<%s")' % (start_date, end_date)) if filter_: - revisions = scmutil.revrange(self._repo, filter_) + revspec = ' and '.join(filter_) + revisions = scmutil.revrange(self._repo, [revspec]) else: revisions = self.revisions diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py +++ b/kallithea/tests/api/api_base.py @@ -21,6 +21,8 @@ import random import mock import re +import pytest + from kallithea.tests.base import * from kallithea.tests.fixture import Fixture from kallithea.lib.compat import json @@ -2501,6 +2503,19 @@ class _BaseTestApi(object): assert 'message' in result[0] assert 'added' not in result[0] + def test_api_get_changesets_with_branch(self): + if self.REPO == 'vcs_test_hg': + branch = 'stable' + else: + pytest.skip("skipping due to missing branches in git test repo") + id_, params = _build_data(self.apikey, 'get_changesets', + repoid=self.REPO, branch_name=branch, start_date="2011-02-24T00:00:00") + response = api_call(self, params) + result = json.loads(response.body)["result"] + assert len(result) == 5 + assert 'message' in result[0] + assert 'added' not in result[0] + def test_api_get_changesets_with_file_list(self): id_, params = _build_data(self.apikey, 'get_changesets', repoid=self.REPO, start_date="2010-04-07T23:30:30", end_date="2010-04-08T00:31:14", with_file_list=True)