Skip to content

Commit a3cb12e

Browse files
petrhosekjdavid
authored andcommitted
Diff and Patch interface refactored
1 parent da98890 commit a3cb12e

File tree

10 files changed

+717
-285
lines changed

10 files changed

+717
-285
lines changed

src/blob.c

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -28,106 +28,14 @@
2828
#define PY_SSIZE_T_CLEAN
2929
#include <Python.h>
3030
#include "blob.h"
31-
#include "diff.h"
3231
#include "error.h"
3332
#include "object.h"
34-
#include "patch.h"
3533
#include "utils.h"
3634

3735
extern PyObject *GitError;
3836

3937
extern PyTypeObject BlobType;
4038

41-
PyDoc_STRVAR(Blob_diff__doc__,
42-
"diff([blob, flag, old_as_path, new_as_path]) -> Patch\n"
43-
"\n"
44-
"Directly generate a :py:class:`pygit2.Patch` from the difference\n"
45-
"between two blobs.\n"
46-
"\n"
47-
":param Blob blob: the :py:class:`~pygit2.Blob` to diff.\n"
48-
"\n"
49-
":param flag: a GIT_DIFF_* constant.\n"
50-
"\n"
51-
":param str old_as_path: treat old blob as if it had this filename.\n"
52-
"\n"
53-
":param str new_as_path: treat new blob as if it had this filename.\n"
54-
"\n"
55-
":rtype: Patch\n");
56-
57-
PyObject *
58-
Blob_diff(Blob *self, PyObject *args, PyObject *kwds)
59-
{
60-
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
61-
git_patch *patch;
62-
char *old_as_path = NULL, *new_as_path = NULL;
63-
Blob *py_blob = NULL;
64-
int err;
65-
char *keywords[] = {"blob", "flag", "old_as_path", "new_as_path", NULL};
66-
67-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!Iss", keywords,
68-
&BlobType, &py_blob, &opts.flags,
69-
&old_as_path, &new_as_path))
70-
return NULL;
71-
72-
err = git_patch_from_blobs(&patch, self->blob, old_as_path,
73-
py_blob ? py_blob->blob : NULL, new_as_path,
74-
&opts);
75-
if (err < 0)
76-
return Error_set(err);
77-
78-
return wrap_patch(patch);
79-
}
80-
81-
82-
PyDoc_STRVAR(Blob_diff_to_buffer__doc__,
83-
"diff_to_buffer([buffer, flag, old_as_path, buffer_as_path]) -> Patch\n"
84-
"\n"
85-
"Directly generate a :py:class:`~pygit2.Patch` from the difference\n"
86-
"between a blob and a buffer.\n"
87-
"\n"
88-
":param Blob buffer: Raw data for new side of diff.\n"
89-
"\n"
90-
":param flag: a GIT_DIFF_* constant.\n"
91-
"\n"
92-
":param str old_as_path: treat old blob as if it had this filename.\n"
93-
"\n"
94-
":param str buffer_as_path: treat buffer as if it had this filename.\n"
95-
"\n"
96-
":rtype: Patch\n");
97-
98-
PyObject *
99-
Blob_diff_to_buffer(Blob *self, PyObject *args, PyObject *kwds)
100-
{
101-
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
102-
git_patch *patch;
103-
char *old_as_path = NULL, *buffer_as_path = NULL;
104-
const char *buffer = NULL;
105-
Py_ssize_t buffer_len;
106-
int err;
107-
char *keywords[] = {"buffer", "flag", "old_as_path", "buffer_as_path",
108-
NULL};
109-
110-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s#Iss", keywords,
111-
&buffer, &buffer_len, &opts.flags,
112-
&old_as_path, &buffer_as_path))
113-
return NULL;
114-
115-
err = git_patch_from_blob_and_buffer(&patch, self->blob, old_as_path,
116-
buffer, buffer_len, buffer_as_path,
117-
&opts);
118-
if (err < 0)
119-
return Error_set(err);
120-
121-
return wrap_patch(patch);
122-
}
123-
124-
static PyMethodDef Blob_methods[] = {
125-
METHOD(Blob, diff, METH_VARARGS | METH_KEYWORDS),
126-
METHOD(Blob, diff_to_buffer, METH_VARARGS | METH_KEYWORDS),
127-
{NULL}
128-
};
129-
130-
13139
PyDoc_STRVAR(Blob_size__doc__, "Size.");
13240

13341
PyObject *
@@ -246,7 +154,7 @@ PyTypeObject BlobType = {
246154
0, /* tp_weaklistoffset */
247155
0, /* tp_iter */
248156
0, /* tp_iternext */
249-
Blob_methods, /* tp_methods */
157+
0, /* tp_methods */
250158
0, /* tp_members */
251159
Blob_getseters, /* tp_getset */
252160
0, /* tp_base */

0 commit comments

Comments
 (0)