|
28 | 28 | #define PY_SSIZE_T_CLEAN |
29 | 29 | #include <Python.h> |
30 | 30 | #include "blob.h" |
31 | | -#include "diff.h" |
32 | 31 | #include "error.h" |
33 | 32 | #include "object.h" |
34 | | -#include "patch.h" |
35 | 33 | #include "utils.h" |
36 | 34 |
|
37 | 35 | extern PyObject *GitError; |
38 | 36 |
|
39 | 37 | extern PyTypeObject BlobType; |
40 | 38 |
|
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 | | - |
131 | 39 | PyDoc_STRVAR(Blob_size__doc__, "Size."); |
132 | 40 |
|
133 | 41 | PyObject * |
@@ -246,7 +154,7 @@ PyTypeObject BlobType = { |
246 | 154 | 0, /* tp_weaklistoffset */ |
247 | 155 | 0, /* tp_iter */ |
248 | 156 | 0, /* tp_iternext */ |
249 | | - Blob_methods, /* tp_methods */ |
| 157 | + 0, /* tp_methods */ |
250 | 158 | 0, /* tp_members */ |
251 | 159 | Blob_getseters, /* tp_getset */ |
252 | 160 | 0, /* tp_base */ |
|
0 commit comments