MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Patch_create_from

Function Patch_create_from

src/patch.c:102–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100 "Create a patch from blobs, buffers, or a blob and a buffer");
101
102static PyObject *
103Patch_create_from(PyObject *self, PyObject *args, PyObject *kwds)
104{
105 /* A generic wrapper around
106 * git_patch_from_blob_and_buffer
107 * git_patch_from_buffers
108 * git_patch_from_blobs
109 */
110 git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
111 git_patch *patch;
112 char *old_as_path = NULL, *new_as_path = NULL;
113 PyObject *oldobj = NULL, *newobj = NULL;
114 Blob *oldblob = NULL, *newblob = NULL;
115 const char *oldbuf = NULL, *newbuf = NULL;
116 Py_ssize_t oldbuflen, newbuflen;
117 int err;
118
119 char *keywords[] = {"old", "new", "old_as_path", "new_as_path",
120 "flag", "context_lines", "interhunk_lines",
121 NULL};
122
123 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|zzIHH", keywords,
124 &oldobj, &newobj, &old_as_path, &new_as_path,
125 &opts.flags, &opts.context_lines,
126 &opts.interhunk_lines))
127 return NULL;
128
129 if (oldobj != Py_None && PyObject_TypeCheck(oldobj, &BlobType))
130 {
131 /* The old object exists and is a blob */
132 oldblob = (Blob*)oldobj;
133 if (Object__load((Object*)oldblob) == NULL) { return NULL; } // Lazy load
134
135 if (newobj != Py_None && PyObject_TypeCheck(newobj, &BlobType))
136 {
137 /* The new object exists and is a blob */
138 newblob = (Blob*)newobj;
139 if (Object__load((Object*)newblob) == NULL) { return NULL; } // Lazy load
140
141 err = git_patch_from_blobs(&patch, oldblob->blob, old_as_path,
142 newblob->blob, new_as_path, &opts);
143 }
144 else {
145 /* The new object does not exist or is a buffer */
146 if (!PyArg_Parse(newobj, "z#", &newbuf, &newbuflen))
147 return NULL;
148
149 err = git_patch_from_blob_and_buffer(&patch, oldblob->blob, old_as_path,
150 newbuf, newbuflen, new_as_path,
151 &opts);
152 }
153 }
154 else
155 {
156 /* The old object does exist and is a buffer */
157 if (!PyArg_Parse(oldobj, "z#", &oldbuf, &oldbuflen))
158 return NULL;
159

Callers

nothing calls this directly

Calls 3

Object__loadFunction · 0.85
Error_setFunction · 0.85
wrap_patchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…