diff --git a/README.rst b/README.rst index 50c3df9..aa17880 100644 --- a/README.rst +++ b/README.rst @@ -44,6 +44,8 @@ API changes:: Patch.status => Patch.delta.status Patch.similarity => Patch.delta.similarity Patch.is_binary => Patch.delta.is_binary + Patch.additions => Patch.line_stats[1] + Patch.deletions => Patch.line_stats[2] 0.22.0 (2015-01-16) diff --git a/src/patch.c b/src/patch.c index 013227b..5a855d5 100644 --- a/src/patch.c +++ b/src/patch.c @@ -48,7 +48,7 @@ wrap_patch(git_patch *patch) py_patch = PyObject_New(Patch, &PatchType); if (py_patch) { - size_t i, j, hunk_amounts, lines_in_hunk, additions, deletions; + size_t i, j, hunk_amounts, lines_in_hunk; const git_diff_delta *delta; const git_diff_hunk *hunk; const git_diff_line *line; @@ -58,10 +58,6 @@ wrap_patch(git_patch *patch) delta = git_patch_get_delta(patch); - git_patch_line_stats(NULL, &additions, &deletions, patch); - py_patch->additions = additions; - py_patch->deletions = deletions; - hunk_amounts = git_patch_num_hunks(patch); py_patch->hunks = PyList_New(hunk_amounts); for (i = 0; i < hunk_amounts; ++i) { @@ -125,15 +121,34 @@ Patch_delta__get__(Patch *self) return wrap_diff_delta(git_patch_get_delta(self->patch)); } +PyDoc_STRVAR(Patch_line_stats__doc__, + "Get line counts of each type in a patch."); + +PyObject * +Patch_line_stats__get__(Patch *self) +{ + size_t context, additions, deletions; + int err; + + if (!self->patch) + Py_RETURN_NONE; + + err = git_patch_line_stats(&context, &additions, &deletions, + self->patch); + if (err < 0) + return Error_set(err); + + return Py_BuildValue("III", context, additions, deletions); +} + PyMemberDef Patch_members[] = { MEMBER(Patch, hunks, T_OBJECT, "hunks"), - MEMBER(Patch, additions, T_INT, "additions"), - MEMBER(Patch, deletions, T_INT, "deletions"), {NULL} }; PyGetSetDef Patch_getseters[] = { GETTER(Patch, delta), + GETTER(Patch, line_stats), {NULL} }; diff --git a/src/types.h b/src/types.h index ea78b90..1f78756 100644 --- a/src/types.h +++ b/src/types.h @@ -95,8 +95,6 @@ typedef struct { PyObject_HEAD git_patch *patch; PyObject* hunks; - unsigned additions; - unsigned deletions; } Patch; /* git_diff */