walk: make the sorting mode optional
Since the libgit2 has a default sorting method, which we also mention as default in the documentation, there is no particular need to make the user choose a sorting method when the order does not matter. We use sorting NONE in that case.
This commit is contained in:
@@ -626,13 +626,13 @@ Repository_merge(Repository *self, PyObject *py_oid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(Repository_walk__doc__,
|
PyDoc_STRVAR(Repository_walk__doc__,
|
||||||
"walk(oid, sort_mode) -> iterator\n"
|
"walk(oid[, sort_mode]) -> iterator\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Generator that traverses the history starting from the given commit.\n"
|
"Generator that traverses the history starting from the given commit.\n"
|
||||||
"The following types of sorting could be used to control traversing\n"
|
"The following types of sorting could be used to control traversing\n"
|
||||||
"direction:\n"
|
"direction:\n"
|
||||||
"\n"
|
"\n"
|
||||||
"* GIT_SORT_NONE. This is the default sorting for new walkers\n"
|
"* GIT_SORT_NONE. This is the default sorting for new walkers.\n"
|
||||||
" Sort the repository contents in no particular ordering\n"
|
" Sort the repository contents in no particular ordering\n"
|
||||||
"* GIT_SORT_TOPOLOGICAL. Sort the repository contents in topological order\n"
|
"* GIT_SORT_TOPOLOGICAL. Sort the repository contents in topological order\n"
|
||||||
" (parents before children); this sorting mode can be combined with\n"
|
" (parents before children); this sorting mode can be combined with\n"
|
||||||
@@ -656,13 +656,13 @@ PyObject *
|
|||||||
Repository_walk(Repository *self, PyObject *args)
|
Repository_walk(Repository *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
unsigned int sort;
|
unsigned int sort = GIT_SORT_NONE;
|
||||||
int err;
|
int err;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_revwalk *walk;
|
git_revwalk *walk;
|
||||||
Walker *py_walker;
|
Walker *py_walker;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OI", &value, &sort))
|
if (!PyArg_ParseTuple(args, "O|I", &value, &sort))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_revwalk_new(&walk, self->repo);
|
err = git_revwalk_new(&walk, self->repo);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from __future__ import absolute_import
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pygit2 import GIT_SORT_TIME, GIT_SORT_REVERSE
|
from pygit2 import GIT_SORT_NONE, GIT_SORT_TIME, GIT_SORT_REVERSE
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
@@ -107,5 +107,13 @@ class WalkerTest(utils.RepoTestCase):
|
|||||||
walker.simplify_first_parent()
|
walker.simplify_first_parent()
|
||||||
self.assertEqual(len(list(walker)), 3)
|
self.assertEqual(len(list(walker)), 3)
|
||||||
|
|
||||||
|
def test_default_sorting(self):
|
||||||
|
walker = self.repo.walk(log[0], GIT_SORT_NONE)
|
||||||
|
list1 = list([x.id for x in walker])
|
||||||
|
walker = self.repo.walk(log[0])
|
||||||
|
list2 = list([x.id for x in walker])
|
||||||
|
|
||||||
|
self.assertEqual(list1, list2)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user