Skip to content

Commit b7e906e

Browse files
committed
Adjust to libgit2 development branch
This wraps the previous functionality, though there are some iterator changes we might still want to bring over.
1 parent c267891 commit b7e906e

File tree

12 files changed

+87
-116
lines changed

12 files changed

+87
-116
lines changed

pygit2/__init__.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def init_repository(path, bare=False):
4949

5050

5151
def clone_repository(
52-
url, path, bare=False, remote_name="origin",
53-
push_url=None, fetch_spec=None,
54-
push_spec=None, checkout_branch=None):
52+
url, path, bare=False, ignore_cert_errors=False,
53+
remote_name="origin", checkout_branch=None):
5554
"""
5655
Clones a new Git repository from *url* in the given *path*.
5756
@@ -60,15 +59,6 @@ def clone_repository(
6059
**remote_name** is the name given to the "origin" remote.
6160
The default is "origin".
6261
63-
**push_url** is a URL to be used for pushing.
64-
None means use the *url* parameter.
65-
66-
**fetch_spec** defines the the default fetch spec.
67-
None results in the same behavior as *GIT_REMOTE_DEFAULT_FETCH*.
68-
69-
**push_spec** is the fetch specification to be used for pushing.
70-
None means use the same spec as for *fetch_spec*.
71-
7262
**checkout_branch** gives the name of the branch to checkout.
7363
None means use the remote's *HEAD*.
7464
@@ -83,6 +73,5 @@ def clone_repository(
8373
"""
8474

8575
_pygit2.clone_repository(
86-
url, path, bare, remote_name, push_url,
87-
fetch_spec, push_spec, checkout_branch)
76+
url, path, bare, ignore_cert_errors, remote_name, checkout_branch)
8877
return Repository(path)

src/config.c

+22-33
Original file line numberDiff line numberDiff line change
@@ -336,55 +336,44 @@ PyDoc_STRVAR(Config_get_multivar__doc__,
336336
"parameter is expected to be a regular expression to filter the variables\n"
337337
"we're interested in.");
338338

339-
int
340-
Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data)
341-
{
342-
PyObject *item;
343-
344-
item = to_unicode(value->value, NULL, NULL);
345-
if (item == NULL)
346-
/* FIXME Right now there is no way to forward errors through the
347-
* libgit2 API, open an issue or pull-request to libgit2.
348-
*
349-
* See libgit2/src/config_file.c:443 (config_get_multivar).
350-
* Comment says "early termination by the user is not an error".
351-
* That's wrong.
352-
*/
353-
return -2;
354-
355-
PyList_Append((PyObject *)data, item);
356-
Py_CLEAR(item);
357-
return 0;
358-
}
359-
360339
PyObject *
361340
Config_get_multivar(Config *self, PyObject *args)
362341
{
363342
int err;
364343
PyObject *list;
365-
Py_ssize_t size;
366344
const char *name = NULL;
367345
const char *regex = NULL;
346+
git_config_iterator *iter;
347+
git_config_entry *entry;
368348

369349
if (!PyArg_ParseTuple(args, "s|s", &name, &regex))
370350
return NULL;
371351

372352
list = PyList_New(0);
373-
err = git_config_get_multivar(self->config, name, regex,
374-
Config_get_multivar_fn_wrapper,
375-
(void *)list);
353+
err = git_config_multivar_iterator_new(&iter, self->config, name, regex);
354+
if (err < 0)
355+
return Error_set(err);
376356

377-
if (err < 0) {
378-
/* XXX The return value of git_config_get_multivar is not reliable,
379-
* see https://github.com/libgit2/libgit2/pull/1712
380-
* Once libgit2 0.20 is released, we will remove this test. */
381-
if (err == GIT_ENOTFOUND && PyList_Size(list) != 0)
382-
return list;
357+
while ((err = git_config_next(&entry, iter)) == 0) {
358+
PyObject *item;
383359

384-
Py_CLEAR(list);
385-
return Error_set(err);
360+
item = to_unicode(entry->value, NULL, NULL);
361+
if (item == NULL) {
362+
git_config_iterator_free(iter);
363+
return NULL;
364+
}
365+
366+
PyList_Append(list, item);
367+
Py_CLEAR(item);
386368
}
387369

370+
git_config_iterator_free(iter);
371+
if (err == GIT_ITEROVER)
372+
err = 0;
373+
374+
if (err < 0)
375+
return Error_set(err);
376+
388377
return list;
389378
}
390379

src/diff.c

+26-28
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern PyTypeObject HunkType;
4343
PyTypeObject PatchType;
4444

4545
PyObject*
46-
wrap_diff(git_diff_list *diff, Repository *repo)
46+
wrap_diff(git_diff *diff, Repository *repo)
4747
{
4848
Diff *py_diff;
4949

@@ -58,23 +58,24 @@ wrap_diff(git_diff_list *diff, Repository *repo)
5858
}
5959

6060
PyObject*
61-
diff_get_patch_byindex(git_diff_list* list, size_t idx)
61+
diff_get_patch_byindex(git_diff* diff, size_t idx)
6262
{
6363
const git_diff_delta* delta;
64-
const git_diff_range* range;
65-
git_diff_patch* patch = NULL;
66-
size_t i, j, hunk_amounts, lines_in_hunk, line_len, header_len, additions, deletions;
67-
const char* line, *header;
68-
char line_origin;
64+
const git_diff_hunk *hunk;
65+
const git_diff_line *line;
66+
git_patch* patch = NULL;
67+
size_t i, j, hunk_amounts, lines_in_hunk, additions, deletions;
6968
int err;
7069
Hunk *py_hunk = NULL;
7170
Patch *py_patch = NULL;
7271
PyObject *py_line_origin=NULL, *py_line=NULL;
7372

74-
err = git_diff_get_patch(&patch, &delta, list, idx);
75-
if (err < 0)
73+
err = git_patch_from_diff(&patch, diff, idx);
74+
if (err < 0)
7675
return Error_set(err);
7776

77+
delta = git_patch_get_delta(patch);
78+
7879
py_patch = PyObject_New(Patch, &PatchType);
7980
if (py_patch != NULL) {
8081
py_patch->old_file_path = delta->old_file.path;
@@ -85,36 +86,34 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
8586
py_patch->old_oid = git_oid_allocfmt(&delta->old_file.oid);
8687
py_patch->new_oid = git_oid_allocfmt(&delta->new_file.oid);
8788

88-
git_diff_patch_line_stats(NULL, &additions, &deletions, patch);
89+
git_patch_line_stats(NULL, &additions, &deletions, patch);
8990
py_patch->additions = additions;
9091
py_patch->deletions = deletions;
9192

92-
hunk_amounts = git_diff_patch_num_hunks(patch);
93+
hunk_amounts = git_patch_num_hunks(patch);
9394
py_patch->hunks = PyList_New(hunk_amounts);
9495
for (i=0; i < hunk_amounts; ++i) {
95-
err = git_diff_patch_get_hunk(&range, &header, &header_len,
96-
&lines_in_hunk, patch, i);
96+
err = git_patch_get_hunk(&hunk, &lines_in_hunk, patch, i);
9797

9898
if (err < 0)
9999
goto cleanup;
100100

101101
py_hunk = PyObject_New(Hunk, &HunkType);
102102
if (py_hunk != NULL) {
103-
py_hunk->old_start = range->old_start;
104-
py_hunk->old_lines = range->old_lines;
105-
py_hunk->new_start = range->new_start;
106-
py_hunk->new_lines = range->new_lines;
103+
py_hunk->old_start = hunk->old_start;
104+
py_hunk->old_lines = hunk->old_lines;
105+
py_hunk->new_start = hunk->new_start;
106+
py_hunk->new_lines = hunk->new_lines;
107107

108108
py_hunk->lines = PyList_New(lines_in_hunk);
109109
for (j=0; j < lines_in_hunk; ++j) {
110-
err = git_diff_patch_get_line_in_hunk(&line_origin,
111-
&line, &line_len, NULL, NULL, patch, i, j);
110+
err = git_patch_get_line_in_hunk(&line, patch, i, j);
112111

113112
if (err < 0)
114113
goto cleanup;
115114

116-
py_line_origin = to_unicode_n(&line_origin, 1, NULL, NULL);
117-
py_line = to_unicode_n(line, line_len, NULL, NULL);
115+
py_line_origin = to_unicode_n(&line->origin, 1, NULL, NULL);
116+
py_line = to_unicode_n(line->content, line->content_len, NULL, NULL);
118117
PyList_SetItem(py_hunk->lines, j,
119118
Py_BuildValue("OO",
120119
py_line_origin,
@@ -132,7 +131,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
132131
}
133132

134133
cleanup:
135-
git_diff_patch_free(patch);
134+
git_patch_free(patch);
136135

137136
return (err < 0) ? Error_set(err) : (PyObject*) py_patch;
138137
}
@@ -283,8 +282,7 @@ PyDoc_STRVAR(Diff_patch__doc__, "Patch diff string.");
283282
PyObject *
284283
Diff_patch__get__(Diff *self)
285284
{
286-
const git_diff_delta* delta;
287-
git_diff_patch* patch;
285+
git_patch* patch;
288286
char **strings = NULL;
289287
char *buffer = NULL;
290288
int err = GIT_ERROR;
@@ -295,16 +293,16 @@ Diff_patch__get__(Diff *self)
295293
MALLOC(strings, num * sizeof(char*), cleanup);
296294

297295
for (i = 0, len = 1; i < num ; ++i) {
298-
err = git_diff_get_patch(&patch, &delta, self->list, i);
296+
err = git_patch_from_diff(&patch, self->list, i);
299297
if (err < 0)
300298
goto cleanup;
301299

302-
err = git_diff_patch_to_str(&(strings[i]), patch);
300+
err = git_patch_to_str(&(strings[i]), patch);
303301
if (err < 0)
304302
goto cleanup;
305303

306304
len += strlen(strings[i]);
307-
git_diff_patch_free(patch);
305+
git_patch_free(patch);
308306
}
309307

310308
CALLOC(buffer, (len + 1), sizeof(char), cleanup);
@@ -461,7 +459,7 @@ Diff_getitem(Diff *self, PyObject *value)
461459
static void
462460
Diff_dealloc(Diff *self)
463461
{
464-
git_diff_list_free(self->list);
462+
git_diff_free(self->list);
465463
Py_CLEAR(self->repo);
466464
PyObject_Del(self);
467465
}

src/diff.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
PyObject* Diff_changes(Diff *self);
4242
PyObject* Diff_patch(Diff *self);
4343

44-
PyObject* wrap_diff(git_diff_list *diff, Repository *repo);
44+
PyObject* wrap_diff(git_diff *diff, Repository *repo);
4545

4646
#endif

src/index.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ PyObject *
135135
Index_diff_to_workdir(Index *self, PyObject *args)
136136
{
137137
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
138-
git_diff_list *diff;
138+
git_diff *diff;
139139
int err;
140140

141141
if (!PyArg_ParseTuple(args, "|IHH", &opts.flags, &opts.context_lines,
@@ -177,7 +177,7 @@ Index_diff_to_tree(Index *self, PyObject *args)
177177
{
178178
Repository *py_repo;
179179
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
180-
git_diff_list *diff;
180+
git_diff *diff;
181181
int err;
182182

183183
Tree *py_tree = NULL;

src/pygit2.c

+8-21
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ init_repository(PyObject *self, PyObject *args) {
9999
};
100100

101101
PyDoc_STRVAR(clone_repository__doc__,
102-
"clone_repository(url, path, bare, remote_name, push_url,"
103-
"fetch_spec, push_spec, checkout_branch)\n"
102+
"clone_repository(url, path, bare, remote_name, checkout_branch)\n"
104103
"\n"
105104
"Clones a Git repository in the given url to the given path "
106105
"with the specified options.\n"
@@ -115,14 +114,6 @@ PyDoc_STRVAR(clone_repository__doc__,
115114
" If 'bare' is not 0, then a bare git repository will be created.\n"
116115
"remote_name\n"
117116
" The name given to the 'origin' remote. The default is 'origin'.\n"
118-
"push_url\n"
119-
" URL to be used for pushing.\n"
120-
"fetch_spec\n"
121-
" The fetch specification to be used for fetching. None results in "
122-
"the same behavior as GIT_REMOTE_DEFAULT_FETCH.\n"
123-
"push_spec\n"
124-
" The fetch specification to be used for pushing. None means use the "
125-
"same spec as for 'fetch_spec'\n"
126117
"checkout_branch\n"
127118
" The name of the branch to checkout. None means use the remote's "
128119
"HEAD.\n");
@@ -133,22 +124,18 @@ clone_repository(PyObject *self, PyObject *args) {
133124
git_repository *repo;
134125
const char *url;
135126
const char *path;
136-
unsigned int bare;
137-
const char *remote_name, *push_url, *fetch_spec;
138-
const char *push_spec, *checkout_branch;
127+
unsigned int bare, ignore_cert_errors;
128+
const char *remote_name, *checkout_branch;
139129
int err;
140130
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
141131

142-
if (!PyArg_ParseTuple(args, "zzIzzzzz",
143-
&url, &path, &bare, &remote_name, &push_url,
144-
&fetch_spec, &push_spec, &checkout_branch))
132+
if (!PyArg_ParseTuple(args, "zzIIzz",
133+
&url, &path, &bare, &ignore_cert_errors, &remote_name, &checkout_branch))
145134
return NULL;
146135

147136
opts.bare = bare;
137+
opts.ignore_cert_errors = ignore_cert_errors;
148138
opts.remote_name = remote_name;
149-
opts.pushurl = push_url;
150-
opts.fetch_spec = fetch_spec;
151-
opts.push_spec = push_spec;
152139
opts.checkout_branch = checkout_branch;
153140

154141
err = git_clone(&repo, url, path, &opts);
@@ -392,8 +379,8 @@ moduleinit(PyObject* m)
392379
ADD_CONSTANT_INT(m, GIT_DIFF_RECURSE_UNTRACKED_DIRS)
393380
ADD_CONSTANT_INT(m, GIT_DIFF_RECURSE_UNTRACKED_DIRS)
394381
ADD_CONSTANT_INT(m, GIT_DIFF_DISABLE_PATHSPEC_MATCH)
395-
ADD_CONSTANT_INT(m, GIT_DIFF_DELTAS_ARE_ICASE)
396-
ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_UNTRACKED_CONTENT)
382+
ADD_CONSTANT_INT(m, GIT_DIFF_IGNORE_CASE)
383+
ADD_CONSTANT_INT(m, GIT_DIFF_SHOW_UNTRACKED_CONTENT)
397384
ADD_CONSTANT_INT(m, GIT_DIFF_SKIP_BINARY_CHECK)
398385
ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE)
399386
ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE_TREES)

src/reference.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,19 @@ PyDoc_STRVAR(Reference_log__doc__,
309309
PyObject *
310310
Reference_log(Reference *self)
311311
{
312+
int err;
312313
RefLogIter *iter;
314+
git_repository *repo;
313315

314316
CHECK_REFERENCE(self);
315317

318+
repo = git_reference_owner(self->reference);
316319
iter = PyObject_New(RefLogIter, &RefLogIterType);
317320
if (iter != NULL) {
318-
git_reflog_read(&iter->reflog, self->reference);
321+
err = git_reflog_read(&iter->reflog, repo, git_reference_name(self->reference));
322+
if (err < 0)
323+
return Error_set(err);
324+
319325
iter->size = git_reflog_entrycount(iter->reflog);
320326
iter->i = 0;
321327
}
@@ -341,6 +347,7 @@ Reference_log_append(Reference *self, PyObject *args)
341347
Signature *py_committer;
342348
PyObject *py_message = NULL;
343349
char *encoding = NULL;
350+
git_repository *repo;
344351

345352
CHECK_REFERENCE(self);
346353

@@ -366,7 +373,8 @@ Reference_log_append(Reference *self, PyObject *args)
366373
}
367374

368375
/* Go */
369-
err = git_reflog_read(&reflog, self->reference);
376+
repo = git_reference_owner(self->reference);
377+
err = git_reflog_read(&reflog, repo, git_reference_name(self->reference));
370378
if (err < 0) {
371379
free((void *)message);
372380
return NULL;

src/remote.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Remote_fetch(Remote *self, PyObject *args)
179179

180180
err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH);
181181
if (err == GIT_OK) {
182-
err = git_remote_download(self->remote, NULL, NULL);
182+
err = git_remote_download(self->remote);
183183
if (err == GIT_OK) {
184184
stats = git_remote_stats(self->remote);
185185
py_stats = Py_BuildValue("{s:I,s:I,s:n}",

0 commit comments

Comments
 (0)