Skip to content

Commit 145646a

Browse files
committed
Merge remote-tracking branch 'alexband/size'
2 parents 5074435 + c0b1ab9 commit 145646a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/diff.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ PyTypeObject DiffIterType = {
271271
(iternextfunc) DiffIter_iternext, /* tp_iternext */
272272
};
273273

274+
Py_ssize_t
275+
Diff_len(Diff *self)
276+
{
277+
assert(self->list);
278+
return (Py_ssize_t)git_diff_num_deltas(self->list);
279+
}
274280

275281
PyDoc_STRVAR(Diff_patch__doc__, "Patch diff string.");
276282

@@ -466,7 +472,7 @@ PyGetSetDef Diff_getseters[] = {
466472
};
467473

468474
PyMappingMethods Diff_as_mapping = {
469-
0, /* mp_length */
475+
(lenfunc)Diff_len, /* mp_length */
470476
(binaryfunc)Diff_getitem, /* mp_subscript */
471477
0, /* mp_ass_subscript */
472478
};

test/test_diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def test_diff_patch(self):
255255

256256
diff = commit_a.tree.diff_to_tree(commit_b.tree)
257257
self.assertEqual(diff.patch, PATCH)
258+
self.assertEqual(len(diff), len([patch for patch in diff]))
258259

259260
def test_diff_oids(self):
260261
commit_a = self.repo[COMMIT_SHA1_1]

0 commit comments

Comments
 (0)