Skip to content

Commit c0b1ab9

Browse files
author
Huang Huang
committed
add len(diff) instead of diff.size
1 parent 9730564 commit c0b1ab9

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/diff.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ PyTypeObject DiffIterType = {
249249
(iternextfunc) DiffIter_iternext, /* tp_iternext */
250250
};
251251

252-
PyDoc_STRVAR(Diff_size__doc__, "Returns the number of deltas/patches in this diff.");
253-
PyObject *
254-
Diff_size__get__(Diff *self)
252+
Py_ssize_t
253+
Diff_len(Diff *self)
255254
{
256-
return PyLong_FromSize_t(git_diff_num_deltas(self->list));
255+
assert(self->list);
256+
return (Py_ssize_t)git_diff_num_deltas(self->list);
257257
}
258258

259259
PyDoc_STRVAR(Diff_patch__doc__, "Patch diff string.");
@@ -446,12 +446,11 @@ Diff_dealloc(Diff *self)
446446

447447
PyGetSetDef Diff_getseters[] = {
448448
GETTER(Diff, patch),
449-
GETTER(Diff, size),
450449
{NULL}
451450
};
452451

453452
PyMappingMethods Diff_as_mapping = {
454-
0, /* mp_length */
453+
(lenfunc)Diff_len, /* mp_length */
455454
(binaryfunc)Diff_getitem, /* mp_subscript */
456455
0, /* mp_ass_subscript */
457456
};

test/test_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_diff_patch(self):
254254

255255
diff = commit_a.tree.diff_to_tree(commit_b.tree)
256256
self.assertEqual(diff.patch, PATCH)
257-
self.assertEqual(diff.size, len([patch for patch in diff]))
257+
self.assertEqual(len(diff), len([patch for patch in diff]))
258258

259259
def test_diff_oids(self):
260260
commit_a = self.repo[COMMIT_SHA1_1]

0 commit comments

Comments
 (0)