Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add the attribute to show the number of deltas/patches in one diff #281

Merged
merged 2 commits into from

2 participants

@alexband

diff.size returns the number of deltas/patches of one diff

@jdavid
Collaborator

Since we have an iterator for patch in diff, it would be better to implement the length function, so it reads len(diff)

@jdavid
Collaborator

...instead of diff.size

@alexband

@jdavid yes definitely better, see c0b1ab9

@jdavid jdavid merged commit c0b1ab9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 30, 2013
  1. the number of deltas/patches in one diff

    Huang Huang authored
Commits on Nov 1, 2013
  1. add len(diff) instead of diff.size

    Huang Huang authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +7 −1 src/diff.c
  2. +1 −0  test/test_diff.py
View
8 src/diff.c
@@ -249,6 +249,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.");
@@ -444,7 +450,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 */
};
View
1  test/test_diff.py
@@ -254,6 +254,7 @@ def test_diff_patch(self):
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]
Something went wrong with that request. Please try again.