Skip to content

Commit 91dfaf2

Browse files
committed
Review Patch, fixes #757
1 parent 007ac2a commit 91dfaf2

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

src/patch.c

+14-27
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ wrap_patch(git_patch *patch)
4646
PyObject *py_hunk;
4747
size_t i, hunk_amounts;
4848

49-
if (!patch)
50-
Py_RETURN_NONE;
49+
assert(patch);
5150

5251
py_patch = PyObject_New(Patch, &PatchType);
5352
if (py_patch) {
@@ -78,9 +77,7 @@ PyDoc_STRVAR(Patch_delta__doc__, "Get the delta associated with a patch.");
7877
PyObject *
7978
Patch_delta__get__(Patch *self)
8079
{
81-
if (!self->patch)
82-
Py_RETURN_NONE;
83-
80+
assert(self->patch);
8481
return wrap_diff_delta(git_patch_get_delta(self->patch));
8582
}
8683

@@ -93,11 +90,8 @@ Patch_line_stats__get__(Patch *self)
9390
size_t context, additions, deletions;
9491
int err;
9592

96-
if (!self->patch)
97-
Py_RETURN_NONE;
98-
99-
err = git_patch_line_stats(&context, &additions, &deletions,
100-
self->patch);
93+
assert(self->patch);
94+
err = git_patch_line_stats(&context, &additions, &deletions, self->patch);
10195
if (err < 0)
10296
return Error_set(err);
10397

@@ -171,12 +165,11 @@ Patch_create_from(PyObject *self, PyObject *args, PyObject *kwds)
171165
err = git_patch_from_buffers(&patch, oldbuf, oldbuflen, old_as_path,
172166
newbuf, newbuflen, new_as_path, &opts);
173167
}
174-
168+
175169
if (err < 0)
176170
return Error_set(err);
177171

178172
return wrap_patch(patch);
179-
180173
}
181174

182175

@@ -186,24 +179,18 @@ PyDoc_STRVAR(Patch_patch__doc__,
186179
PyObject *
187180
Patch_patch__get__(Patch *self)
188181
{
189-
git_buf buf = {NULL};
190-
int err = GIT_ERROR;
191-
PyObject *py_patch = NULL;
192-
193-
err = git_patch_to_buf(&buf, self->patch);
194-
195-
if (!self->patch)
196-
Py_RETURN_NONE;
197-
198-
if (err < 0)
199-
goto cleanup;
182+
git_buf buf = {NULL};
183+
int err;
184+
PyObject *py_patch;
200185

201-
py_patch = to_unicode(buf.ptr, NULL, NULL);
202-
git_buf_free(&buf);
186+
assert(self->patch);
187+
err = git_patch_to_buf(&buf, self->patch);
188+
if (err < 0)
189+
return Error_set(err);
203190

204-
cleanup:
191+
py_patch = to_unicode(buf.ptr, NULL, NULL);
205192
git_buf_free(&buf);
206-
return (err < 0) ? Error_set(err) : py_patch;
193+
return py_patch;
207194
}
208195

209196
PyMethodDef Patch_methods[] = {

0 commit comments

Comments
 (0)