diff --git a/src/diff.c b/src/diff.c index a539000..3b5c4fe 100644 --- a/src/diff.c +++ b/src/diff.c @@ -271,6 +271,12 @@ PyTypeObject DiffIterType = { (iternextfunc) DiffIter_iternext, /* tp_iternext */ }; +Py_ssize_t +Diff_len(Diff *self) +{ + assert(self->list); + return (Py_ssize_t)git_diff_num_deltas(self->list); +} PyDoc_STRVAR(Diff_patch__doc__, "Patch diff string."); @@ -466,7 +472,7 @@ PyGetSetDef Diff_getseters[] = { }; PyMappingMethods Diff_as_mapping = { - 0, /* mp_length */ + (lenfunc)Diff_len, /* mp_length */ (binaryfunc)Diff_getitem, /* mp_subscript */ 0, /* mp_ass_subscript */ }; diff --git a/test/test_diff.py b/test/test_diff.py index 3f762d8..60078ac 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -255,6 +255,7 @@ class DiffTest(utils.BareRepoTestCase): diff = commit_a.tree.diff_to_tree(commit_b.tree) self.assertEqual(diff.patch, PATCH) + self.assertEqual(len(diff), len([patch for patch in diff])) def test_diff_oids(self): commit_a = self.repo[COMMIT_SHA1_1]