Changeset - bfb1ae42bcbb
[Not reviewed]
default
0 2 0
domruf - 8 years ago 2018-01-20 02:24:38
dominikruf@gmail.com
Grafted from: 2b6ea985a344
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.
2 files changed with 19 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -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
 

	
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -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)
0 comments (0 inline, 0 general)