changeset 7144:bfb1ae42bcbb

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.
author domruf <dominikruf@gmail.com>
date Sat, 20 Jan 2018 02:24:38 +0100
parents dc7e37ec3dfd
children 32e6957d0aac
files kallithea/lib/vcs/backends/hg/repository.py kallithea/tests/api/api_base.py
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/hg/repository.py	Thu Nov 23 22:16:34 2017 +0100
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Sat Jan 20 02:24:38 2018 +0100
@@ -540,14 +540,13 @@
         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
 
--- a/kallithea/tests/api/api_base.py	Thu Nov 23 22:16:34 2017 +0100
+++ b/kallithea/tests/api/api_base.py	Sat Jan 20 02:24:38 2018 +0100
@@ -21,6 +21,8 @@
 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 @@
         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)