Skip to content
This repository

Update to new release #288

Merged
merged 3 commits into from 5 months ago

3 participants

Carlos Martín Nieto J. David Ibáñez alexband
Carlos Martín Nieto
Owner

Adjust to the changes in 0.20. This includes moving away from callback to iterations, letting us do better error reporting.

added some commits October 30, 2013
Carlos Martín Nieto Adjust to libgit2 development branch
This wraps the previous functionality, though there are some iterator
changes we might still want to bring over.
b7e906e
Carlos Martín Nieto Branch: move from foreach to the iterator 12ea3d2
Carlos Martín Nieto Index: adjust to index_read() force flag 4c47eba
Carlos Martín Nieto
Owner

While doing this update, I noticed that pygit2 returns a tuple when asked for the references in a repo. It seems really odd to me to return a tuple rather than a list, as you don't know how many there are beforehand, and they're not sorted (and sorting wouldn't have any meaning you could put into a tuple anyway). Is there some deeper pythonic reason for this?

J. David Ibáñez jdavid merged commit 4c47eba into from November 20, 2013
J. David Ibáñez jdavid closed this November 20, 2013
J. David Ibáñez
Collaborator

You're right, it would be more correct, pythonic, to return a list.

The Python criteria is, if it is a sequence of semantically the same kind of object, then it is a list. If it is a package of different kind of objects, like a record, then it is a tuple.

alexband

hi @carlosmn is git_diff_list depreciated in libgit2, we here has a kind of fork of pygi2 with some modification. The fork hasn't sync with the main repo for a while, and now there are some conflicts with git_diff_list, I found your commit to adjust to libgit2, is there any explanation or documentation about the git_diff_list thing, either in libgit2 or pygit2. Thanks in advance.

seems that it's just rename libgit2/libgit2@3ff1d12

so I can just rename it , cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Nov 20, 2013
Carlos Martín Nieto Adjust to libgit2 development branch
This wraps the previous functionality, though there are some iterator
changes we might still want to bring over.
b7e906e
Carlos Martín Nieto Branch: move from foreach to the iterator 12ea3d2
Carlos Martín Nieto Index: adjust to index_read() force flag 4c47eba
This page is out of date. Refresh to see the latest.
17  pygit2/__init__.py
@@ -49,9 +49,8 @@ def init_repository(path, bare=False):
49 49
 
50 50
 
51 51
 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):
55 54
     """
56 55
     Clones a new Git repository from *url* in the given *path*.
57 56
 
@@ -60,15 +59,6 @@ def clone_repository(
60 59
     **remote_name** is the name given to the "origin" remote.
61 60
     The default is "origin".
62 61
 
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  
-
72 62
     **checkout_branch** gives the name of the branch to checkout.
73 63
     None means use the remote's *HEAD*.
74 64
 
@@ -83,6 +73,5 @@ def clone_repository(
83 73
     """
84 74
 
85 75
     _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)
88 77
     return Repository(path)
55  src/config.c
@@ -336,55 +336,44 @@ PyDoc_STRVAR(Config_get_multivar__doc__,
336 336
   "parameter is expected to be a regular expression to filter the variables\n"
337 337
   "we're interested in.");
338 338
 
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  
-
360 339
 PyObject *
361 340
 Config_get_multivar(Config *self, PyObject *args)
362 341
 {
363 342
     int err;
364 343
     PyObject *list;
365  
-    Py_ssize_t size;
366 344
     const char *name = NULL;
367 345
     const char *regex = NULL;
  346
+    git_config_iterator *iter;
  347
+    git_config_entry *entry;
368 348
 
369 349
     if (!PyArg_ParseTuple(args, "s|s", &name, &regex))
370 350
         return NULL;
371 351
 
372 352
     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);
376 356
 
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;
383 359
 
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);
386 368
     }
387 369
 
  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
+
388 377
     return list;
389 378
 }
390 379
 
54  src/diff.c
@@ -43,7 +43,7 @@ extern PyTypeObject HunkType;
43 43
 PyTypeObject PatchType;
44 44
 
45 45
 PyObject*
46  
-wrap_diff(git_diff_list *diff, Repository *repo)
  46
+wrap_diff(git_diff *diff, Repository *repo)
47 47
 {
48 48
     Diff *py_diff;
49 49
 
@@ -58,23 +58,24 @@ wrap_diff(git_diff_list *diff, Repository *repo)
58 58
 }
59 59
 
60 60
 PyObject*
61  
-diff_get_patch_byindex(git_diff_list* list, size_t idx)
  61
+diff_get_patch_byindex(git_diff* diff, size_t idx)
62 62
 {
63 63
     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;
69 68
     int err;
70 69
     Hunk *py_hunk = NULL;
71 70
     Patch *py_patch = NULL;
72 71
     PyObject *py_line_origin=NULL, *py_line=NULL;
73 72
 
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)
76 75
         return Error_set(err);
77 76
 
  77
+    delta = git_patch_get_delta(patch);
  78
+
78 79
     py_patch = PyObject_New(Patch, &PatchType);
79 80
     if (py_patch != NULL) {
80 81
         py_patch->old_file_path = delta->old_file.path;
@@ -85,36 +86,34 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
85 86
         py_patch->old_oid = git_oid_allocfmt(&delta->old_file.oid);
86 87
         py_patch->new_oid = git_oid_allocfmt(&delta->new_file.oid);
87 88
 
88  
-        git_diff_patch_line_stats(NULL, &additions, &deletions, patch);
  89
+        git_patch_line_stats(NULL, &additions, &deletions, patch);
89 90
         py_patch->additions = additions;
90 91
         py_patch->deletions = deletions;
91 92
 
92  
-        hunk_amounts = git_diff_patch_num_hunks(patch);
  93
+        hunk_amounts = git_patch_num_hunks(patch);
93 94
         py_patch->hunks = PyList_New(hunk_amounts);
94 95
         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);
97 97
 
98 98
             if (err < 0)
99 99
                 goto cleanup;
100 100
 
101 101
             py_hunk = PyObject_New(Hunk, &HunkType);
102 102
             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;
107 107
 
108 108
                 py_hunk->lines = PyList_New(lines_in_hunk);
109 109
                 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);
112 111
 
113 112
                     if (err < 0)
114 113
                       goto cleanup;
115 114
 
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);
118 117
                     PyList_SetItem(py_hunk->lines, j,
119 118
                         Py_BuildValue("OO",
120 119
                             py_line_origin,
@@ -132,7 +131,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
132 131
     }
133 132
 
134 133
 cleanup:
135  
-    git_diff_patch_free(patch);
  134
+    git_patch_free(patch);
136 135
 
137 136
     return (err < 0) ? Error_set(err) : (PyObject*) py_patch;
138 137
 }
@@ -283,8 +282,7 @@ PyDoc_STRVAR(Diff_patch__doc__, "Patch diff string.");
283 282
 PyObject *
284 283
 Diff_patch__get__(Diff *self)
285 284
 {
286  
-    const git_diff_delta* delta;
287  
-    git_diff_patch* patch;
  285
+    git_patch* patch;
288 286
     char **strings = NULL;
289 287
     char *buffer = NULL;
290 288
     int err = GIT_ERROR;
@@ -295,16 +293,16 @@ Diff_patch__get__(Diff *self)
295 293
     MALLOC(strings, num * sizeof(char*), cleanup);
296 294
 
297 295
     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);
299 297
         if (err < 0)
300 298
             goto cleanup;
301 299
 
302  
-        err = git_diff_patch_to_str(&(strings[i]), patch);
  300
+        err = git_patch_to_str(&(strings[i]), patch);
303 301
         if (err < 0)
304 302
             goto cleanup;
305 303
 
306 304
         len += strlen(strings[i]);
307  
-        git_diff_patch_free(patch);
  305
+        git_patch_free(patch);
308 306
     }
309 307
 
310 308
     CALLOC(buffer, (len + 1), sizeof(char), cleanup);
@@ -461,7 +459,7 @@ Diff_getitem(Diff *self, PyObject *value)
461 459
 static void
462 460
 Diff_dealloc(Diff *self)
463 461
 {
464  
-    git_diff_list_free(self->list);
  462
+    git_diff_free(self->list);
465 463
     Py_CLEAR(self->repo);
466 464
     PyObject_Del(self);
467 465
 }
2  src/diff.h
@@ -41,6 +41,6 @@
41 41
 PyObject* Diff_changes(Diff *self);
42 42
 PyObject* Diff_patch(Diff *self);
43 43
 
44  
-PyObject* wrap_diff(git_diff_list *diff, Repository *repo);
  44
+PyObject* wrap_diff(git_diff *diff, Repository *repo);
45 45
 
46 46
 #endif
23  src/index.c
@@ -135,7 +135,7 @@ PyObject *
135 135
 Index_diff_to_workdir(Index *self, PyObject *args)
136 136
 {
137 137
     git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
138  
-    git_diff_list *diff;
  138
+    git_diff *diff;
139 139
     int err;
140 140
 
141 141
     if (!PyArg_ParseTuple(args, "|IHH", &opts.flags, &opts.context_lines,
@@ -177,7 +177,7 @@ Index_diff_to_tree(Index *self, PyObject *args)
177 177
 {
178 178
     Repository *py_repo;
179 179
     git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
180  
-    git_diff_list *diff;
  180
+    git_diff *diff;
181 181
     int err;
182 182
 
183 183
     Tree *py_tree = NULL;
@@ -222,17 +222,24 @@ Index__find(Index *self, PyObject *py_path)
222 222
 
223 223
 
224 224
 PyDoc_STRVAR(Index_read__doc__,
225  
-  "read()\n"
  225
+  "read(force=True)\n"
226 226
   "\n"
227 227
   "Update the contents of an existing index object in memory by reading from\n"
228  
-  "the hard disk.");
  228
+  "the hard disk."
  229
+  "Arguments:\n"
  230
+  "\n"
  231
+  "force: if True (the default) allways reload. If False, only if the file has changed"
  232
+);
229 233
 
230 234
 PyObject *
231  
-Index_read(Index *self)
  235
+Index_read(Index *self, PyObject *args)
232 236
 {
233  
-    int err;
  237
+    int err, force = 1;
  238
+
  239
+    if (!PyArg_ParseTuple(args, "|i", &force))
  240
+        return NULL;
234 241
 
235  
-    err = git_index_read(self->index);
  242
+    err = git_index_read(self->index, force);
236 243
     if (err < GIT_OK)
237 244
         return Error_set(err);
238 245
 
@@ -427,7 +434,7 @@ PyMethodDef Index_methods[] = {
427 434
     METHOD(Index, diff_to_workdir, METH_VARARGS),
428 435
     METHOD(Index, diff_to_tree, METH_VARARGS),
429 436
     METHOD(Index, _find, METH_O),
430  
-    METHOD(Index, read, METH_NOARGS),
  437
+    METHOD(Index, read, METH_VARARGS),
431 438
     METHOD(Index, write, METH_NOARGS),
432 439
     METHOD(Index, read_tree, METH_O),
433 440
     METHOD(Index, write_tree, METH_NOARGS),
2  src/index.h
@@ -35,7 +35,7 @@
35 35
 PyObject* Index_add(Index *self, PyObject *args);
36 36
 PyObject* Index_clear(Index *self);
37 37
 PyObject* Index_find(Index *self, PyObject *py_path);
38  
-PyObject* Index_read(Index *self);
  38
+PyObject* Index_read(Index *self, PyObject *args);
39 39
 PyObject* Index_write(Index *self);
40 40
 PyObject* Index_iter(Index *self);
41 41
 PyObject* Index_getitem(Index *self, PyObject *value);
29  src/pygit2.c
@@ -99,8 +99,7 @@ init_repository(PyObject *self, PyObject *args) {
99 99
 };
100 100
 
101 101
 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"
104 103
     "\n"
105 104
     "Clones a Git repository in the given url to the given path "
106 105
     "with the specified options.\n"
@@ -115,14 +114,6 @@ PyDoc_STRVAR(clone_repository__doc__,
115 114
     "  If 'bare' is not 0, then a bare git repository will be created.\n"
116 115
     "remote_name\n"
117 116
     "  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"
126 117
     "checkout_branch\n"
127 118
     "  The name of the branch to checkout. None means use the remote's "
128 119
     "HEAD.\n");
@@ -133,22 +124,18 @@ clone_repository(PyObject *self, PyObject *args) {
133 124
     git_repository *repo;
134 125
     const char *url;
135 126
     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;
139 129
     int err;
140 130
     git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
141 131
 
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))
145 134
         return NULL;
146 135
 
147 136
     opts.bare = bare;
  137
+    opts.ignore_cert_errors = ignore_cert_errors;
148 138
     opts.remote_name = remote_name;
149  
-    opts.pushurl = push_url;
150  
-    opts.fetch_spec = fetch_spec;
151  
-    opts.push_spec = push_spec;
152 139
     opts.checkout_branch = checkout_branch;
153 140
 
154 141
     err = git_clone(&repo, url, path, &opts);
@@ -392,8 +379,8 @@ moduleinit(PyObject* m)
392 379
     ADD_CONSTANT_INT(m, GIT_DIFF_RECURSE_UNTRACKED_DIRS)
393 380
     ADD_CONSTANT_INT(m, GIT_DIFF_RECURSE_UNTRACKED_DIRS)
394 381
     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)
397 384
     ADD_CONSTANT_INT(m, GIT_DIFF_SKIP_BINARY_CHECK)
398 385
     ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE)
399 386
     ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE_TREES)
12  src/reference.c
@@ -309,13 +309,19 @@ PyDoc_STRVAR(Reference_log__doc__,
309 309
 PyObject *
310 310
 Reference_log(Reference *self)
311 311
 {
  312
+    int err;
312 313
     RefLogIter *iter;
  314
+    git_repository *repo;
313 315
 
314 316
     CHECK_REFERENCE(self);
315 317
 
  318
+    repo = git_reference_owner(self->reference);
316 319
     iter = PyObject_New(RefLogIter, &RefLogIterType);
317 320
     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
+
319 325
         iter->size = git_reflog_entrycount(iter->reflog);
320 326
         iter->i = 0;
321 327
     }
@@ -341,6 +347,7 @@ Reference_log_append(Reference *self, PyObject *args)
341 347
     Signature *py_committer;
342 348
     PyObject *py_message = NULL;
343 349
     char *encoding = NULL;
  350
+    git_repository *repo;
344 351
 
345 352
     CHECK_REFERENCE(self);
346 353
 
@@ -366,7 +373,8 @@ Reference_log_append(Reference *self, PyObject *args)
366 373
     }
367 374
 
368 375
     /* 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));
370 378
     if (err < 0) {
371 379
         free((void *)message);
372 380
         return NULL;
2  src/remote.c
@@ -179,7 +179,7 @@ Remote_fetch(Remote *self, PyObject *args)
179 179
 
180 180
     err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH);
181 181
     if (err == GIT_OK) {
182  
-        err = git_remote_download(self->remote, NULL, NULL);
  182
+        err = git_remote_download(self->remote);
183 183
         if (err == GIT_OK) {
184 184
             stats = git_remote_stats(self->remote);
185 185
             py_stats = Py_BuildValue("{s:I,s:I,s:n}",
111  src/repository.c
@@ -208,14 +208,14 @@ Repository_head_is_detached__get__(Repository *self)
208 208
 }
209 209
 
210 210
 
211  
-PyDoc_STRVAR(Repository_head_is_orphaned__doc__,
212  
-  "An orphan branch is one named from HEAD but which doesn't exist in the\n"
  211
+PyDoc_STRVAR(Repository_head_is_unborn__doc__,
  212
+  "An unborn branch is one named from HEAD but which doesn't exist in the\n"
213 213
   "refs namespace, because it doesn't have any commit to point to.");
214 214
 
215 215
 PyObject *
216  
-Repository_head_is_orphaned__get__(Repository *self)
  216
+Repository_head_is_unborn__get__(Repository *self)
217 217
 {
218  
-    if (git_repository_head_orphan(self->repo) > 0)
  218
+    if (git_repository_head_unborn(self->repo) > 0)
219 219
         Py_RETURN_TRUE;
220 220
 
221 221
     Py_RETURN_FALSE;
@@ -430,9 +430,9 @@ Repository_write(Repository *self, PyObject *args)
430 430
     if (err < 0)
431 431
         return Error_set(err);
432 432
 
433  
-    stream->write(stream, buffer, buflen);
434  
-    err = stream->finalize_write(&oid, stream);
435  
-    stream->free(stream);
  433
+    git_odb_stream_write(stream, buffer, buflen);
  434
+    err = git_odb_stream_finalize_write(&oid, stream);
  435
+    git_odb_stream_free(stream);
436 436
     return git_oid_to_python(&oid);
437 437
 }
438 438
 
@@ -920,69 +920,64 @@ PyDoc_STRVAR(Repository_listall_branches__doc__,
920 920
   "\n"
921 921
   "Return a tuple with all the branches in the repository.");
922 922
 
923  
-struct branch_foreach_s {
924  
-    PyObject *tuple;
925  
-    Py_ssize_t pos;
926  
-};
927  
-
928  
-int
929  
-branch_foreach_cb(const char *branch_name, git_branch_t branch_type, void *payload)
930  
-{
931  
-    /* This is the callback that will be called in git_branch_foreach. It
932  
-     * will be called for every branch.
933  
-     * payload is a struct branch_foreach_s.
934  
-     */
935  
-    int err;
936  
-    struct branch_foreach_s *payload_s = (struct branch_foreach_s *)payload;
937  
-
938  
-    if (PyTuple_Size(payload_s->tuple) <= payload_s->pos)
939  
-    {
940  
-        err = _PyTuple_Resize(&(payload_s->tuple), payload_s->pos * 2);
941  
-        if (err) {
942  
-            Py_CLEAR(payload_s->tuple);
943  
-            return GIT_ERROR;
944  
-        }
945  
-    }
946  
-
947  
-    PyObject *py_branch_name = to_path(branch_name);
948  
-    if (py_branch_name == NULL) {
949  
-        Py_CLEAR(payload_s->tuple);
950  
-        return GIT_ERROR;
951  
-    }
952  
-
953  
-    PyTuple_SET_ITEM(payload_s->tuple, payload_s->pos++, py_branch_name);
954  
-
955  
-    return GIT_OK;
956  
-}
957  
-
958  
-
959 923
 PyObject *
960 924
 Repository_listall_branches(Repository *self, PyObject *args)
961 925
 {
962  
-    unsigned int list_flags = GIT_BRANCH_LOCAL;
  926
+    git_branch_t list_flags = GIT_BRANCH_LOCAL;
  927
+    git_branch_iterator *iter;
  928
+    git_reference *ref = NULL;
  929
+    Py_ssize_t pos = 0;
963 930
     int err;
  931
+    git_branch_t type;
  932
+    PyObject *tuple;
964 933
 
965 934
     /* 1- Get list_flags */
966 935
     if (!PyArg_ParseTuple(args, "|I", &list_flags))
967 936
         return NULL;
968 937
 
969  
-    /* 2- Get the C result */
970  
-    struct branch_foreach_s payload;
971  
-    payload.tuple = PyTuple_New(4);
972  
-    if (payload.tuple == NULL)
973  
-        return NULL;
  938
+    tuple = PyTuple_New(4);
  939
+    if (tuple == NULL)
  940
+	    return NULL;
974 941
 
975  
-    payload.pos = 0;
976  
-    err = git_branch_foreach(self->repo, list_flags, branch_foreach_cb, &payload);
977  
-    if (err != GIT_OK)
978  
-        return Error_set(err);
  942
+    if ((err = git_branch_iterator_new(&iter, self->repo, list_flags)) < 0)
  943
+	    return Error_set(err);
  944
+
  945
+    while ((err = git_branch_next(&ref, &type, iter)) == 0) {
  946
+        if (PyTuple_Size(tuple) <= pos) {
  947
+            if (_PyTuple_Resize(&tuple, pos * 2) < 0)
  948
+                goto on_error;
  949
+        }
  950
+
  951
+        PyObject *py_branch_name = to_path(git_reference_shorthand(ref));
  952
+        git_reference_free(ref);
  953
+        ref = NULL;
  954
+
  955
+        if (py_branch_name == NULL)
  956
+            goto on_error;
  957
+
  958
+        PyTuple_SET_ITEM(tuple, pos++, py_branch_name);
  959
+    }
979 960
 
980  
-    /* 3- Trim the tuple */
981  
-    err = _PyTuple_Resize(&payload.tuple, payload.pos);
982  
-    if (err)
  961
+    git_branch_iterator_free(iter);
  962
+    if (err == GIT_ITEROVER)
  963
+	    err = 0;
  964
+
  965
+    if (err < 0) {
  966
+        Py_CLEAR(tuple);
  967
+	    return Error_set(err);
  968
+    }
  969
+
  970
+    /* Remove the elements we might have overallocated in the loop */
  971
+    if (_PyTuple_Resize(&tuple, pos) < 0)
983 972
         return Error_set(err);
984 973
 
985  
-    return payload.tuple;
  974
+    return tuple;
  975
+
  976
+  on_error:
  977
+    git_reference_free(ref);
  978
+    git_branch_iterator_free(iter);
  979
+    Py_CLEAR(tuple);
  980
+    return NULL;
986 981
 }
987 982
 
988 983
 
@@ -1480,7 +1475,7 @@ PyGetSetDef Repository_getseters[] = {
1480 1475
     GETTER(Repository, path),
1481 1476
     GETSET(Repository, head),
1482 1477
     GETTER(Repository, head_is_detached),
1483  
-    GETTER(Repository, head_is_orphaned),
  1478
+    GETTER(Repository, head_is_unborn),
1484 1479
     GETTER(Repository, is_empty),
1485 1480
     GETTER(Repository, is_bare),
1486 1481
     GETTER(Repository, config),
6  src/tree.c
@@ -290,7 +290,7 @@ PyObject *
290 290
 Tree_diff_to_workdir(Tree *self, PyObject *args)
291 291
 {
292 292
     git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
293  
-    git_diff_list *diff;
  293
+    git_diff *diff;
294 294
     Repository *py_repo;
295 295
     int err;
296 296
 
@@ -328,7 +328,7 @@ PyObject *
328 328
 Tree_diff_to_index(Tree *self, PyObject *args, PyObject *kwds)
329 329
 {
330 330
     git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
331  
-    git_diff_list *diff;
  331
+    git_diff *diff;
332 332
     Repository *py_repo;
333 333
     int err;
334 334
 
@@ -373,7 +373,7 @@ PyObject *
373 373
 Tree_diff_to_tree(Tree *self, PyObject *args, PyObject *kwds)
374 374
 {
375 375
     git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
376  
-    git_diff_list *diff;
  376
+    git_diff *diff;
377 377
     git_tree *from, *to, *tmp;
378 378
     Repository *py_repo;
379 379
     int err, swap = 0;
2  src/types.h
@@ -95,7 +95,7 @@ typedef struct {
95 95
 
96 96
 
97 97
 /* git _diff */
98  
-SIMPLE_TYPE(Diff, git_diff_list, list)
  98
+SIMPLE_TYPE(Diff, git_diff, list)
99 99
 
100 100
 typedef struct {
101 101
     PyObject_HEAD
4  test/test_repository.py
@@ -65,7 +65,7 @@ def test_head(self):
65 65
         head = self.repo.head
66 66
         self.assertEqual(HEAD_SHA, head.target.hex)
67 67
         self.assertEqual(type(head), Reference)
68  
-        self.assertFalse(self.repo.head_is_orphaned)
  68
+        self.assertFalse(self.repo.head_is_unborn)
69 69
         self.assertFalse(self.repo.head_is_detached)
70 70
 
71 71
     def test_read(self):
@@ -294,7 +294,7 @@ def test_is_base(self):
294 294
         self.assertFalse(self.repo.is_bare)
295 295
 
296 296
     def test_head(self):
297  
-        self.assertTrue(self.repo.head_is_orphaned)
  297
+        self.assertTrue(self.repo.head_is_unborn)
298 298
         self.assertFalse(self.repo.head_is_detached)
299 299
 
300 300
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.