Skip to content

Commit

Permalink
Review Patch, fixes #757
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavid committed Dec 9, 2017
1 parent 007ac2a commit 91dfaf2
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ wrap_patch(git_patch *patch)
PyObject *py_hunk;
size_t i, hunk_amounts;

if (!patch)
Py_RETURN_NONE;
assert(patch);

py_patch = PyObject_New(Patch, &PatchType);
if (py_patch) {
Expand Down Expand Up @@ -78,9 +77,7 @@ PyDoc_STRVAR(Patch_delta__doc__, "Get the delta associated with a patch.");
PyObject *
Patch_delta__get__(Patch *self)
{
if (!self->patch)
Py_RETURN_NONE;

assert(self->patch);
return wrap_diff_delta(git_patch_get_delta(self->patch));
}

Expand All @@ -93,11 +90,8 @@ 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);
assert(self->patch);
err = git_patch_line_stats(&context, &additions, &deletions, self->patch);
if (err < 0)
return Error_set(err);

Expand Down Expand Up @@ -171,12 +165,11 @@ Patch_create_from(PyObject *self, PyObject *args, PyObject *kwds)
err = git_patch_from_buffers(&patch, oldbuf, oldbuflen, old_as_path,
newbuf, newbuflen, new_as_path, &opts);
}

if (err < 0)
return Error_set(err);

return wrap_patch(patch);

}


Expand All @@ -186,24 +179,18 @@ PyDoc_STRVAR(Patch_patch__doc__,
PyObject *
Patch_patch__get__(Patch *self)
{
git_buf buf = {NULL};
int err = GIT_ERROR;
PyObject *py_patch = NULL;

err = git_patch_to_buf(&buf, self->patch);

if (!self->patch)
Py_RETURN_NONE;

if (err < 0)
goto cleanup;
git_buf buf = {NULL};
int err;
PyObject *py_patch;

py_patch = to_unicode(buf.ptr, NULL, NULL);
git_buf_free(&buf);
assert(self->patch);
err = git_patch_to_buf(&buf, self->patch);
if (err < 0)
return Error_set(err);

cleanup:
py_patch = to_unicode(buf.ptr, NULL, NULL);
git_buf_free(&buf);
return (err < 0) ? Error_set(err) : py_patch;
return py_patch;
}

PyMethodDef Patch_methods[] = {
Expand Down

0 comments on commit 91dfaf2

Please sign in to comment.