Skip to content

Commit 73170cc

Browse files
committed
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.
1 parent 140305e commit 73170cc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/repository.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,13 @@ Repository_merge(Repository *self, PyObject *py_oid)
626626
}
627627

628628
PyDoc_STRVAR(Repository_walk__doc__,
629-
"walk(oid, sort_mode) -> iterator\n"
629+
"walk(oid[, sort_mode]) -> iterator\n"
630630
"\n"
631631
"Generator that traverses the history starting from the given commit.\n"
632632
"The following types of sorting could be used to control traversing\n"
633633
"direction:\n"
634634
"\n"
635-
"* GIT_SORT_NONE. This is the default sorting for new walkers\n"
635+
"* GIT_SORT_NONE. This is the default sorting for new walkers.\n"
636636
" Sort the repository contents in no particular ordering\n"
637637
"* GIT_SORT_TOPOLOGICAL. Sort the repository contents in topological order\n"
638638
" (parents before children); this sorting mode can be combined with\n"
@@ -656,13 +656,13 @@ PyObject *
656656
Repository_walk(Repository *self, PyObject *args)
657657
{
658658
PyObject *value;
659-
unsigned int sort;
659+
unsigned int sort = GIT_SORT_NONE;
660660
int err;
661661
git_oid oid;
662662
git_revwalk *walk;
663663
Walker *py_walker;
664664

665-
if (!PyArg_ParseTuple(args, "OI", &value, &sort))
665+
if (!PyArg_ParseTuple(args, "O|I", &value, &sort))
666666
return NULL;
667667

668668
err = git_revwalk_new(&walk, self->repo);

test/test_revwalk.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from __future__ import unicode_literals
3232
import unittest
3333

34-
from pygit2 import GIT_SORT_TIME, GIT_SORT_REVERSE
34+
from pygit2 import GIT_SORT_NONE, GIT_SORT_TIME, GIT_SORT_REVERSE
3535
from . import utils
3636

3737

@@ -107,5 +107,13 @@ def test_simplify_first_parent(self):
107107
walker.simplify_first_parent()
108108
self.assertEqual(len(list(walker)), 3)
109109

110+
def test_default_sorting(self):
111+
walker = self.repo.walk(log[0], GIT_SORT_NONE)
112+
list1 = list([x.id for x in walker])
113+
walker = self.repo.walk(log[0])
114+
list2 = list([x.id for x in walker])
115+
116+
self.assertEqual(list1, list2)
117+
110118
if __name__ == '__main__':
111119
unittest.main()

0 commit comments

Comments
 (0)