Merge branch 'master' into next
Conflicts: include/pygit2/types.h src/oid.c
This commit is contained in:
@@ -38,6 +38,6 @@ int py_str_to_git_oid_expand(git_repository *repo, PyObject *py_str,
|
||||
PyObject* git_oid_to_py_str(const git_oid *oid);
|
||||
|
||||
#define git_oid_to_python(id) \
|
||||
PyString_FromStringAndSize((const char*)id, GIT_OID_RAWSZ)
|
||||
PyBytes_FromStringAndSize((const char*)id, GIT_OID_RAWSZ)
|
||||
|
||||
#endif
|
||||
|
@@ -32,39 +32,47 @@
|
||||
#include <Python.h>
|
||||
#include <git2.h>
|
||||
|
||||
/* Python objects */
|
||||
/*
|
||||
* Python objects
|
||||
*
|
||||
**/
|
||||
|
||||
/* git_repository */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
git_repository *repo;
|
||||
PyObject *index; /* It will be None for a bare repository */
|
||||
PyObject *config;
|
||||
PyObject *index; /* It will be None for a bare repository */
|
||||
PyObject *config; /* It will be None for a bare repository */
|
||||
} Repository;
|
||||
|
||||
/* The structs for some of the object subtypes are identical except for
|
||||
* the type of their object pointers. */
|
||||
#define OBJECT_STRUCT(_name, _ptr_type, _ptr_name) \
|
||||
|
||||
#define SIMPLE_TYPE(_name, _ptr_type, _ptr_name) \
|
||||
typedef struct {\
|
||||
PyObject_HEAD\
|
||||
Repository *repo;\
|
||||
_ptr_type *_ptr_name;\
|
||||
} _name;
|
||||
|
||||
OBJECT_STRUCT(Object, git_object, obj)
|
||||
OBJECT_STRUCT(Commit, git_commit, commit)
|
||||
OBJECT_STRUCT(Tree, git_tree, tree)
|
||||
OBJECT_STRUCT(TreeBuilder, git_treebuilder, bld)
|
||||
OBJECT_STRUCT(Blob, git_blob, blob)
|
||||
OBJECT_STRUCT(Tag, git_tag, tag)
|
||||
OBJECT_STRUCT(Index, git_index, index)
|
||||
OBJECT_STRUCT(Walker, git_revwalk, walk)
|
||||
OBJECT_STRUCT(Remote, git_remote, remote)
|
||||
OBJECT_STRUCT(Diff, git_diff_list, list)
|
||||
|
||||
/* git object types
|
||||
*
|
||||
* The structs for some of the object subtypes are identical except for
|
||||
* the type of their object pointers. */
|
||||
SIMPLE_TYPE(Object, git_object, obj)
|
||||
SIMPLE_TYPE(Commit, git_commit, commit)
|
||||
SIMPLE_TYPE(Tree, git_tree, tree)
|
||||
SIMPLE_TYPE(Blob, git_blob, blob)
|
||||
SIMPLE_TYPE(Tag, git_tag, tag)
|
||||
|
||||
|
||||
/* git_config */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
git_config* config;
|
||||
} Config;
|
||||
|
||||
|
||||
/* git_note */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Repository *repo;
|
||||
@@ -79,9 +87,12 @@ typedef struct {
|
||||
char* ref;
|
||||
} NoteIter;
|
||||
|
||||
|
||||
/* git _diff */
|
||||
SIMPLE_TYPE(Diff, git_diff_list, list)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
Diff* diff;
|
||||
size_t i;
|
||||
size_t n;
|
||||
@@ -98,12 +109,6 @@ typedef struct {
|
||||
unsigned similarity;
|
||||
} Patch;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *owner; /* Tree or TreeBuilder */
|
||||
const git_tree_entry *entry;
|
||||
} TreeEntry;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject* lines;
|
||||
@@ -113,12 +118,26 @@ typedef struct {
|
||||
int new_lines;
|
||||
} Hunk;
|
||||
|
||||
|
||||
/* git_tree_walk , git_treebuilder*/
|
||||
SIMPLE_TYPE(TreeBuilder, git_treebuilder, bld)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *owner; /* Tree or TreeBuilder */
|
||||
const git_tree_entry *entry;
|
||||
} TreeEntry;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Tree *owner;
|
||||
int i;
|
||||
} TreeIter;
|
||||
|
||||
|
||||
/* git_index */
|
||||
SIMPLE_TYPE(Index, git_index, index)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
const git_index_entry *entry;
|
||||
@@ -130,6 +149,10 @@ typedef struct {
|
||||
int i;
|
||||
} IndexIter;
|
||||
|
||||
|
||||
/* git_reference, git_reflog */
|
||||
SIMPLE_TYPE(Walker, git_revwalk, walk)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
git_reference *reference;
|
||||
@@ -137,9 +160,9 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *oid_old;
|
||||
PyObject *oid_new;
|
||||
PyObject *committer;
|
||||
git_signature *signature;
|
||||
char *oid_old;
|
||||
char *oid_new;
|
||||
char *message;
|
||||
} RefLogEntry;
|
||||
|
||||
@@ -151,6 +174,7 @@ typedef struct {
|
||||
} RefLogIter;
|
||||
|
||||
|
||||
/* git_signature */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Object *obj;
|
||||
@@ -159,6 +183,10 @@ typedef struct {
|
||||
} Signature;
|
||||
|
||||
|
||||
/* git_remote */
|
||||
SIMPLE_TYPE(Remote, git_remote, remote)
|
||||
|
||||
|
||||
PyObject* lookup_object(Repository *repo, const git_oid *oid, git_otype type);
|
||||
|
||||
#endif
|
||||
|
@@ -33,25 +33,22 @@
|
||||
#include <git2.h>
|
||||
#include <pygit2/types.h>
|
||||
|
||||
|
||||
/* Python 3 support */
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyInt_AsLong PyLong_AsLong
|
||||
#define PyInt_Check PyLong_Check
|
||||
#define PyInt_FromLong PyLong_FromLong
|
||||
#define PyString_AS_STRING PyBytes_AS_STRING
|
||||
#define PyString_AsString PyBytes_AsString
|
||||
#define PyString_AsStringAndSize PyBytes_AsStringAndSize
|
||||
#define PyString_Check PyBytes_Check
|
||||
#define PyString_FromString PyBytes_FromString
|
||||
#define PyString_FromStringAndSize PyBytes_FromStringAndSize
|
||||
#define PyString_Size PyBytes_Size
|
||||
#endif
|
||||
|
||||
/* Python 2 support */
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#define PyLong_FromSize_t PyInt_FromSize_t
|
||||
#define PyLong_AsLong PyInt_AsLong
|
||||
#undef PyLong_Check
|
||||
#define PyLong_Check PyInt_Check
|
||||
#define PyLong_FromLong PyInt_FromLong
|
||||
#define PyBytes_AS_STRING PyString_AS_STRING
|
||||
#define PyBytes_AsString PyString_AsString
|
||||
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
|
||||
#define PyBytes_Check PyString_Check
|
||||
#define PyBytes_FromString PyString_FromString
|
||||
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
||||
#define PyBytes_Size PyString_Size
|
||||
#define to_path(x) to_bytes(x)
|
||||
#define to_encoding(x) to_bytes(x)
|
||||
#define PyLong_FromSize_t PyInt_FromSize_t
|
||||
#else
|
||||
#define to_path(x) to_unicode(x, Py_FileSystemDefaultEncoding, "strict")
|
||||
#define to_encoding(x) PyUnicode_DecodeASCII(x, strlen(x), "strict")
|
||||
@@ -69,9 +66,12 @@
|
||||
return -1;\
|
||||
}
|
||||
|
||||
|
||||
/* Utilities */
|
||||
#define to_unicode(x, encoding, errors) to_unicode_n(x, strlen(x), encoding, errors)
|
||||
|
||||
Py_LOCAL_INLINE(PyObject*)
|
||||
to_unicode(const char *value, const char *encoding, const char *errors)
|
||||
to_unicode_n(const char *value, size_t len, const char *encoding, const char *errors)
|
||||
{
|
||||
if (encoding == NULL) {
|
||||
/* If the encoding is not explicit, it may not be UTF-8, so it
|
||||
@@ -81,13 +81,14 @@ to_unicode(const char *value, const char *encoding, const char *errors)
|
||||
encoding = "utf-8";
|
||||
errors = "replace";
|
||||
}
|
||||
return PyUnicode_Decode(value, strlen(value), encoding, errors);
|
||||
|
||||
return PyUnicode_Decode(value, len, encoding, errors);
|
||||
}
|
||||
|
||||
Py_LOCAL_INLINE(PyObject*)
|
||||
to_bytes(const char * value)
|
||||
{
|
||||
return PyString_FromString(value);
|
||||
return PyBytes_FromString(value);
|
||||
}
|
||||
|
||||
char * py_str_to_c_str(PyObject *value, const char *encoding);
|
||||
|
@@ -25,14 +25,16 @@
|
||||
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
|
||||
from .version import __version__
|
||||
# Import from the future
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Low level API
|
||||
import _pygit2
|
||||
from _pygit2 import *
|
||||
|
||||
# High level API
|
||||
from repository import Repository
|
||||
from .repository import Repository
|
||||
from .version import __version__
|
||||
import pygit2.utils
|
||||
|
||||
|
||||
|
@@ -37,7 +37,7 @@ PyDoc_STRVAR(Blob_size__doc__, "Size.");
|
||||
PyObject *
|
||||
Blob_size__get__(Blob *self)
|
||||
{
|
||||
return PyInt_FromLong(git_blob_rawsize(self->blob));
|
||||
return PyLong_FromLong(git_blob_rawsize(self->blob));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -68,7 +68,7 @@ PyDoc_STRVAR(Commit__message__doc__, "Message (bytes).");
|
||||
PyObject *
|
||||
Commit__message__get__(Commit *commit)
|
||||
{
|
||||
return PyString_FromString(git_commit_message(commit->commit));
|
||||
return PyBytes_FromString(git_commit_message(commit->commit));
|
||||
}
|
||||
|
||||
|
||||
|
10
src/config.c
10
src/config.c
@@ -191,7 +191,7 @@ Config_getitem(Config *self, PyObject *py_key)
|
||||
else if(git_config_parse_bool(&value_bool, value_str) == 0)
|
||||
py_value = PyBool_FromLong(value_bool);
|
||||
else
|
||||
py_value = PyUnicode_FromString(value_str);
|
||||
py_value = to_unicode(value_str, NULL, NULL);
|
||||
|
||||
cleanup:
|
||||
free(key);
|
||||
@@ -223,9 +223,9 @@ Config_setitem(Config *self, PyObject *py_key, PyObject *py_value)
|
||||
else if (PyBool_Check(py_value)) {
|
||||
err = git_config_set_bool(self->config, key,
|
||||
(int)PyObject_IsTrue(py_value));
|
||||
} else if (PyInt_Check(py_value)) {
|
||||
} else if (PyLong_Check(py_value)) {
|
||||
err = git_config_set_int64(self->config, key,
|
||||
(int64_t)PyInt_AsLong(py_value));
|
||||
(int64_t)PyLong_AsLong(py_value));
|
||||
} else {
|
||||
value = py_str_to_c_str(py_value, NULL);
|
||||
err = git_config_set_string(self->config, key, value);
|
||||
@@ -300,7 +300,7 @@ Config_foreach(Config *self, PyObject *args)
|
||||
ret = git_config_foreach(self->config, Config_foreach_callback_wrapper,
|
||||
(void *)args);
|
||||
|
||||
return PyInt_FromLong((long)ret);
|
||||
return PyLong_FromLong((long)ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data)
|
||||
{
|
||||
PyObject *item = NULL;
|
||||
|
||||
if (!(item = PyUnicode_FromString(value->value)))
|
||||
if (!(item = to_unicode(value->value, NULL, NULL)))
|
||||
return -2;
|
||||
|
||||
PyList_Append((PyObject *)data, item);
|
||||
|
14
src/diff.c
14
src/diff.c
@@ -58,7 +58,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
py_patch = (Patch*) PyType_GenericNew(&PatchType, NULL, NULL);
|
||||
py_patch = PyObject_New(Patch, &PatchType);
|
||||
if (py_patch != NULL) {
|
||||
py_patch->old_file_path = delta->old_file.path;
|
||||
py_patch->new_file_path = delta->new_file.path;
|
||||
@@ -77,7 +77,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
if (err < 0)
|
||||
goto cleanup;
|
||||
|
||||
py_hunk = (Hunk*)PyType_GenericNew(&HunkType, NULL, NULL);
|
||||
py_hunk = PyObject_New(Hunk, &HunkType);
|
||||
if (py_hunk != NULL) {
|
||||
py_hunk->old_start = range->old_start;
|
||||
py_hunk->old_lines = range->old_lines;
|
||||
@@ -85,8 +85,8 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
py_hunk->new_lines = range->new_lines;
|
||||
|
||||
py_hunk->lines = PyList_New(lines_in_hunk + 1);
|
||||
PyList_SetItem(py_hunk->lines, 0,
|
||||
PyUnicode_FromStringAndSize(header, header_len));
|
||||
PyList_SetItem(py_hunk->lines, 0,
|
||||
to_unicode_n(header, header_len, NULL, NULL));
|
||||
for (j=1; j < lines_in_hunk + 1; ++j) {
|
||||
err = git_diff_patch_get_line_in_hunk(NULL, &line,
|
||||
&line_len, NULL, NULL, patch, i, j - 1);
|
||||
@@ -95,7 +95,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
goto cleanup;
|
||||
|
||||
PyList_SetItem(py_hunk->lines, j,
|
||||
PyUnicode_FromStringAndSize(line, line_len));
|
||||
to_unicode_n(line, line_len, NULL, NULL));
|
||||
}
|
||||
|
||||
PyList_SetItem((PyObject*) py_patch->hunks, i,
|
||||
@@ -247,7 +247,7 @@ Diff_patch__get__(Diff *self)
|
||||
err = git_diff_get_patch(&patch, &delta, self->list, i);
|
||||
if (err < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
err = git_diff_patch_to_str(&(strings[i]), patch);
|
||||
if (err < 0)
|
||||
goto cleanup;
|
||||
@@ -263,7 +263,7 @@ Diff_patch__get__(Diff *self)
|
||||
}
|
||||
free(strings);
|
||||
|
||||
py_patch = PyUnicode_FromString(buffer);
|
||||
py_patch = to_unicode(buffer, NULL, NULL);
|
||||
free(buffer);
|
||||
|
||||
cleanup:
|
||||
|
10
src/index.c
10
src/index.c
@@ -178,7 +178,7 @@ Index__find(Index *self, PyObject *py_path)
|
||||
size_t idx;
|
||||
int err;
|
||||
|
||||
path = PyString_AsString(py_path);
|
||||
path = PyBytes_AsString(py_path);
|
||||
if (!path)
|
||||
return NULL;
|
||||
|
||||
@@ -236,8 +236,8 @@ Index_get_position(Index *self, PyObject *value)
|
||||
int err;
|
||||
|
||||
/* Case 1: integer */
|
||||
if (PyInt_Check(value)) {
|
||||
err = (int)PyInt_AsLong(value);
|
||||
if (PyLong_Check(value)) {
|
||||
err = (int)PyLong_AsLong(value);
|
||||
if (err == -1 && PyErr_Occurred())
|
||||
return -1;
|
||||
if (err < 0) {
|
||||
@@ -542,7 +542,7 @@ PyTypeObject IndexIterType = {
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
@@ -567,7 +567,7 @@ PyDoc_STRVAR(IndexEntry_mode__doc__, "Mode.");
|
||||
PyObject *
|
||||
IndexEntry_mode__get__(IndexEntry *self)
|
||||
{
|
||||
return PyInt_FromLong(self->entry->mode);
|
||||
return PyLong_FromLong(self->entry->mode);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -82,7 +82,7 @@ PyDoc_STRVAR(Note_message__doc__,
|
||||
PyObject *
|
||||
Note_message__get__(Note *self)
|
||||
{
|
||||
return PyUnicode_FromString(git_note_message(self->note));
|
||||
return to_unicode(git_note_message(self->note), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ NoteIter_iternext(NoteIter *self)
|
||||
void
|
||||
NoteIter_dealloc(NoteIter *self)
|
||||
{
|
||||
Py_CLEAR(self->repo);
|
||||
git_note_iterator_free(self->iter);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
@@ -216,7 +217,7 @@ wrap_note(Repository* repo, git_oid* annotated_id, const char* ref)
|
||||
Note* py_note = NULL;
|
||||
int err = GIT_ERROR;
|
||||
|
||||
py_note = (Note*) PyType_GenericNew(&NoteType, NULL, NULL);
|
||||
py_note = PyObject_New(Note, &NoteType);
|
||||
if (py_note == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
|
@@ -86,7 +86,7 @@ PyDoc_STRVAR(Object_type__doc__,
|
||||
PyObject *
|
||||
Object_type__get__(Object *self)
|
||||
{
|
||||
return PyInt_FromLong(git_object_type(self->obj));
|
||||
return PyLong_FromLong(git_object_type(self->obj));
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ Object_read_raw(Object *self)
|
||||
if (obj == NULL)
|
||||
return NULL;
|
||||
|
||||
aux = PyString_FromStringAndSize(
|
||||
aux = PyBytes_FromStringAndSize(
|
||||
git_odb_object_data(obj),
|
||||
git_odb_object_size(obj));
|
||||
|
||||
|
@@ -41,7 +41,7 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid)
|
||||
Py_ssize_t len;
|
||||
|
||||
/* Case 1: raw sha */
|
||||
if (PyString_Check(py_str)) {
|
||||
if (PyBytes_Check(py_str)) {
|
||||
err = PyString_AsStringAndSize(py_str, &hex_or_bin, &len);
|
||||
if (err)
|
||||
return -1;
|
||||
@@ -54,7 +54,7 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid)
|
||||
py_hex = PyUnicode_AsASCIIString(py_str);
|
||||
if (py_hex == NULL)
|
||||
return -1;
|
||||
err = PyString_AsStringAndSize(py_hex, &hex_or_bin, &len);
|
||||
err = PyBytes_AsStringAndSize(py_hex, &hex_or_bin, &len);
|
||||
if (err) {
|
||||
Py_DECREF(py_hex);
|
||||
return -1;
|
||||
@@ -118,6 +118,6 @@ git_oid_to_py_str(const git_oid *oid)
|
||||
char hex[GIT_OID_HEXSZ];
|
||||
|
||||
git_oid_fmt(hex, oid);
|
||||
return PyUnicode_DecodeASCII(hex, GIT_OID_HEXSZ, "strict");
|
||||
return to_unicode_n(hex, GIT_OID_HEXSZ, "utf-8", "strict");
|
||||
}
|
||||
|
||||
|
@@ -47,40 +47,24 @@ void RefLogIter_dealloc(RefLogIter *self)
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
PyObject* RefLogIter_iternext(PyObject *self)
|
||||
PyObject* RefLogIter_iternext(RefLogIter *self)
|
||||
{
|
||||
RefLogIter *p = (RefLogIter *) self;
|
||||
const git_reflog_entry *entry;
|
||||
char oid_old[40], oid_new[40];
|
||||
RefLogEntry *py_entry;
|
||||
|
||||
if (p->i < p->size) {
|
||||
RefLogEntry *py_entry;
|
||||
git_signature *signature;
|
||||
|
||||
entry = git_reflog_entry_byindex(p->reflog, p->i);
|
||||
py_entry = (RefLogEntry*) PyType_GenericNew(&RefLogEntryType, NULL,
|
||||
NULL);
|
||||
|
||||
git_oid_fmt(oid_old, git_reflog_entry_id_old(entry));
|
||||
git_oid_fmt(oid_new, git_reflog_entry_id_new(entry));
|
||||
|
||||
py_entry->oid_new = PyUnicode_FromStringAndSize(oid_new, 40);
|
||||
py_entry->oid_old = PyUnicode_FromStringAndSize(oid_old, 40);
|
||||
if (self->i < self->size) {
|
||||
entry = git_reflog_entry_byindex(self->reflog, self->i);
|
||||
py_entry = PyObject_New(RefLogEntry, &RefLogEntryType);
|
||||
|
||||
py_entry->oid_old = git_oid_allocfmt(git_reflog_entry_id_old(entry));
|
||||
py_entry->oid_new = git_oid_allocfmt(git_reflog_entry_id_new(entry));
|
||||
py_entry->message = strdup(git_reflog_entry_message(entry));
|
||||
py_entry->signature = git_signature_dup(
|
||||
git_reflog_entry_committer(entry));
|
||||
|
||||
signature = git_signature_dup(
|
||||
git_reflog_entry_committer(entry)
|
||||
);
|
||||
|
||||
if (signature != NULL)
|
||||
py_entry->committer = build_signature(
|
||||
(Object*)py_entry, signature, "utf-8");
|
||||
|
||||
++(p->i);
|
||||
++(self->i);
|
||||
|
||||
return (PyObject*) py_entry;
|
||||
|
||||
}
|
||||
|
||||
PyErr_SetNone(PyExc_StopIteration);
|
||||
@@ -358,7 +342,7 @@ Reference_type__get__(Reference *self)
|
||||
|
||||
CHECK_REFERENCE(self);
|
||||
c_type = git_reference_type(self->reference);
|
||||
return PyInt_FromLong(c_type);
|
||||
return PyLong_FromLong(c_type);
|
||||
}
|
||||
|
||||
|
||||
@@ -383,13 +367,23 @@ Reference_log(Reference *self)
|
||||
return (PyObject*)iter;
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(RefLogEntry_committer__doc__, "Committer.");
|
||||
|
||||
PyObject *
|
||||
RefLogEntry_committer__get__(RefLogEntry *self)
|
||||
{
|
||||
return build_signature((Object*) self, self->signature, "utf-8");
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->oid_old = Py_None;
|
||||
self->oid_new = Py_None;
|
||||
self->message = "";
|
||||
self->committer = Py_None;
|
||||
self->oid_old = NULL;
|
||||
self->oid_new = NULL;
|
||||
self->message = NULL;
|
||||
self->signature = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -398,18 +392,22 @@ RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
|
||||
static void
|
||||
RefLogEntry_dealloc(RefLogEntry *self)
|
||||
{
|
||||
Py_CLEAR(self->oid_old);
|
||||
Py_CLEAR(self->oid_new);
|
||||
Py_CLEAR(self->committer);
|
||||
free(self->oid_old);
|
||||
free(self->oid_new);
|
||||
free(self->message);
|
||||
git_signature_free(self->signature);
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
PyMemberDef RefLogEntry_members[] = {
|
||||
MEMBER(RefLogEntry, oid_new, T_OBJECT, "New oid."),
|
||||
MEMBER(RefLogEntry, oid_old, T_OBJECT, "Old oid."),
|
||||
MEMBER(RefLogEntry, oid_new, T_STRING, "New oid."),
|
||||
MEMBER(RefLogEntry, oid_old, T_STRING, "Old oid."),
|
||||
MEMBER(RefLogEntry, message, T_STRING, "Message."),
|
||||
MEMBER(RefLogEntry, committer, T_OBJECT, "Committer."),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyGetSetDef RefLogEntry_getseters[] = {
|
||||
GETTER(RefLogEntry, committer),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@@ -446,7 +444,7 @@ PyTypeObject RefLogEntryType = {
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
RefLogEntry_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
RefLogEntry_getseters, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
|
@@ -71,7 +71,7 @@ PyDoc_STRVAR(Remote_name__doc__, "Name of the remote refspec");
|
||||
PyObject *
|
||||
Remote_name__get__(Remote *self)
|
||||
{
|
||||
return PyUnicode_FromString(git_remote_name(self->remote));
|
||||
return to_unicode(git_remote_name(self->remote), NULL, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -100,7 +100,7 @@ PyDoc_STRVAR(Remote_url__doc__, "Url of the remote");
|
||||
PyObject *
|
||||
Remote_url__get__(Remote *self)
|
||||
{
|
||||
return PyUnicode_FromString(git_remote_url(self->remote));
|
||||
return to_unicode(git_remote_url(self->remote), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -351,7 +351,11 @@ Repository_read(Repository *self, PyObject *py_hex)
|
||||
return NULL;
|
||||
|
||||
tuple = Py_BuildValue(
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
"(ns#)",
|
||||
#else
|
||||
"(ny#)",
|
||||
#endif
|
||||
git_odb_object_type(obj),
|
||||
git_odb_object_data(obj),
|
||||
git_odb_object_size(obj));
|
||||
@@ -863,11 +867,11 @@ Repository_git_reference_symbolic_create(Repository *self, PyObject *args,
|
||||
return NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
c_target = PyString_AsString(py_obj);
|
||||
c_target = PyBytes_AsString(py_obj);
|
||||
#else
|
||||
// increases ref counter, so we have to release it afterwards
|
||||
PyObject* py_str = PyUnicode_AsASCIIString(py_obj);
|
||||
c_target = PyString_AsString(py_str);
|
||||
c_target = PyBytes_AsString(py_str);
|
||||
#endif
|
||||
if (c_target == NULL)
|
||||
return NULL;
|
||||
@@ -899,7 +903,7 @@ read_status_cb(const char *path, unsigned int status_flags, void *payload)
|
||||
PyObject *flags;
|
||||
int err;
|
||||
|
||||
flags = PyInt_FromLong((long) status_flags);
|
||||
flags = PyLong_FromLong((long) status_flags);
|
||||
err = PyDict_SetItemString(payload, path, flags);
|
||||
Py_CLEAR(flags);
|
||||
|
||||
@@ -943,7 +947,7 @@ Repository_status_file(Repository *self, PyObject *value)
|
||||
free(path);
|
||||
return err_obj;
|
||||
}
|
||||
return PyInt_FromLong(status);
|
||||
return PyLong_FromLong(status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1024,7 +1028,7 @@ Repository_create_remote(Repository *self, PyObject *args)
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
py_remote = (Remote*) PyType_GenericNew(&RemoteType, NULL, NULL);
|
||||
py_remote = PyObject_New(Remote, &RemoteType);
|
||||
py_remote->repo = self;
|
||||
py_remote->remote = remote;
|
||||
|
||||
|
@@ -148,7 +148,7 @@ PyDoc_STRVAR(Signature_time__doc__, "Unix time.");
|
||||
PyObject *
|
||||
Signature_time__get__(Signature *self)
|
||||
{
|
||||
return PyInt_FromLong(self->signature->when.time);
|
||||
return PyLong_FromLong(self->signature->when.time);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ PyDoc_STRVAR(Signature_offset__doc__, "Offset from UTC in minutes.");
|
||||
PyObject *
|
||||
Signature_offset__get__(Signature *self)
|
||||
{
|
||||
return PyInt_FromLong(self->signature->when.offset);
|
||||
return PyLong_FromLong(self->signature->when.offset);
|
||||
}
|
||||
|
||||
PyGetSetDef Signature_getseters[] = {
|
||||
|
@@ -91,7 +91,7 @@ PyDoc_STRVAR(Tag__message__doc__, "Tag message (bytes).");
|
||||
PyObject *
|
||||
Tag__message__get__(Tag *self)
|
||||
{
|
||||
return PyString_FromString(git_tag_message(self->tag));
|
||||
return PyBytes_FromString(git_tag_message(self->tag));
|
||||
}
|
||||
|
||||
PyGetSetDef Tag_getseters[] = {
|
||||
|
@@ -53,7 +53,7 @@ PyDoc_STRVAR(TreeEntry_filemode__doc__, "Filemode.");
|
||||
PyObject *
|
||||
TreeEntry_filemode__get__(TreeEntry *self)
|
||||
{
|
||||
return PyInt_FromLong(git_tree_entry_filemode(self->entry));
|
||||
return PyLong_FromLong(git_tree_entry_filemode(self->entry));
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ Tree_fix_index(Tree *self, PyObject *py_index)
|
||||
size_t len;
|
||||
long slen;
|
||||
|
||||
index = PyInt_AsLong(py_index);
|
||||
index = PyLong_AsLong(py_index);
|
||||
if (PyErr_Occurred())
|
||||
return -1;
|
||||
|
||||
@@ -263,7 +263,7 @@ Tree_getitem(Tree *self, PyObject *value)
|
||||
int err;
|
||||
|
||||
/* Case 1: integer */
|
||||
if (PyInt_Check(value))
|
||||
if (PyLong_Check(value))
|
||||
return Tree_getitem_by_index(self, value);
|
||||
|
||||
/* Case 2: byte or text string */
|
||||
@@ -462,7 +462,7 @@ PyTypeObject TreeIterType = {
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
|
@@ -38,8 +38,8 @@ char * py_str_to_c_str(PyObject *value, const char *encoding)
|
||||
{
|
||||
char *c_str = NULL;
|
||||
/* Case 1: byte string */
|
||||
if (PyString_Check(value))
|
||||
return strdup(PyString_AsString(value));
|
||||
if (PyBytes_Check(value))
|
||||
return strdup(PyBytes_AsString(value));
|
||||
|
||||
/* Case 2: text string */
|
||||
if (PyUnicode_Check(value)) {
|
||||
@@ -50,7 +50,7 @@ char * py_str_to_c_str(PyObject *value, const char *encoding)
|
||||
value = PyUnicode_AsEncodedString(value, encoding, "strict");
|
||||
if (value == NULL)
|
||||
return NULL;
|
||||
c_str = strdup(PyString_AsString(value));
|
||||
c_str = strdup(PyBytes_AsString(value));
|
||||
Py_DECREF(value);
|
||||
return c_str;
|
||||
}
|
||||
|
@@ -100,7 +100,7 @@ Walker_sort(Walker *self, PyObject *py_sort_mode)
|
||||
{
|
||||
int sort_mode;
|
||||
|
||||
sort_mode = (int)PyInt_AsLong(py_sort_mode);
|
||||
sort_mode = (int)PyLong_AsLong(py_sort_mode);
|
||||
if (sort_mode == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
|
||||
|
@@ -55,13 +55,13 @@ class ConfigTest(utils.RepoTestCase):
|
||||
def test_global_config(self):
|
||||
try:
|
||||
self.assertNotEqual(None, pygit2.Config.get_global_config())
|
||||
except IOError:
|
||||
except IOError: # there is no user config
|
||||
pass
|
||||
|
||||
def test_system_config(self):
|
||||
try:
|
||||
self.assertNotEqual(None, pygit2.Config.get_system_config())
|
||||
except IOError:
|
||||
except IOError: # there is no system config
|
||||
pass
|
||||
|
||||
def test_new(self):
|
||||
@@ -155,14 +155,19 @@ class ConfigTest(utils.RepoTestCase):
|
||||
|
||||
config.add_file(config_filename, 5)
|
||||
self.assertTrue('this.that' in config)
|
||||
l = config.get_multivar('this.that', 'foo.*')
|
||||
self.assertEqual(len(l), 2)
|
||||
|
||||
config.set_multivar('this.that', '^.*beer', 'fool')
|
||||
l = config.get_multivar('this.that', 'fool')
|
||||
self.assertEqual(len(l), 1)
|
||||
self.assertEqual(l[0], 'fool')
|
||||
config.set_multivar('this.that', 'foo.*', '123456')
|
||||
|
||||
config.set_multivar('this.that', 'foo.*', 'foo-123456')
|
||||
l = config.get_multivar('this.that', 'foo.*')
|
||||
self.assertEqual(len(l), 2)
|
||||
for i in l:
|
||||
self.assertEqual(i, '123456')
|
||||
self.assertEqual(i, 'foo-123456')
|
||||
|
||||
def test_foreach(self):
|
||||
config = self.repo.config
|
||||
|
@@ -28,6 +28,7 @@
|
||||
"""Tests for Remote objects."""
|
||||
|
||||
|
||||
import unittest
|
||||
import pygit2
|
||||
from . import utils
|
||||
|
||||
@@ -104,3 +105,7 @@ class EmptyRepositoryTest(utils.EmptyRepoTestCase):
|
||||
self.assertEqual(stats['received_bytes'], REMOTE_REPO_BYTES)
|
||||
self.assertEqual(stats['indexed_objects'], REMOTE_REPO_OBJECTS)
|
||||
self.assertEqual(stats['received_objects'], REMOTE_REPO_OBJECTS)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@@ -70,14 +70,14 @@ class RepositoryTest(utils.BareRepoTestCase):
|
||||
ab = self.repo.read(A_BIN_SHA)
|
||||
a = self.repo.read(A_HEX_SHA)
|
||||
self.assertEqual(ab, a)
|
||||
self.assertEqual((GIT_OBJ_BLOB, 'a contents\n'), a)
|
||||
self.assertEqual((GIT_OBJ_BLOB, b'a contents\n'), a)
|
||||
|
||||
a2 = self.repo.read('7f129fd57e31e935c6d60a0c794efe4e6927664b')
|
||||
self.assertEqual((GIT_OBJ_BLOB, 'a contents 2\n'), a2)
|
||||
self.assertEqual((GIT_OBJ_BLOB, b'a contents 2\n'), a2)
|
||||
|
||||
a_hex_prefix = A_HEX_SHA[:4]
|
||||
a3 = self.repo.read(a_hex_prefix)
|
||||
self.assertEqual((GIT_OBJ_BLOB, 'a contents\n'), a3)
|
||||
self.assertEqual((GIT_OBJ_BLOB, b'a contents\n'), a3)
|
||||
|
||||
def test_write(self):
|
||||
data = b"hello world"
|
||||
|
@@ -32,7 +32,6 @@ from __future__ import unicode_literals
|
||||
import operator
|
||||
import unittest
|
||||
|
||||
import pygit2
|
||||
from . import utils
|
||||
|
||||
|
||||
@@ -82,21 +81,26 @@ class TreeTest(utils.BareRepoTestCase):
|
||||
sha = '297efb891a47de80be0cfe9c639e4b8c9b450989'
|
||||
self.assertTreeEntryEqual(subtree[0], sha, 'd', 0o0100644)
|
||||
|
||||
# TODO This test worked with libgit2 v0.10.0, update to use the
|
||||
# tree-builder
|
||||
def xtest_new_tree(self):
|
||||
b = self.repo.TreeBuilder()
|
||||
b.insert('1' * 40, 'x', 0o0100644)
|
||||
b.insert('2' * 40, 'y', 0o0100755)
|
||||
tree = self.repo[b.write()]
|
||||
def test_new_tree(self):
|
||||
b0 = self.repo.create_blob('1')
|
||||
b1 = self.repo.create_blob('2')
|
||||
t = self.repo.TreeBuilder()
|
||||
t.insert('x', b0, 0o0100644)
|
||||
t.insert('y', b1, 0o0100755)
|
||||
tree = self.repo[t.write()]
|
||||
|
||||
self.assertTrue('x' in tree)
|
||||
self.assertTrue('y' in tree)
|
||||
self.assertRaisesWithArg(KeyError, '1' * 40, tree['x'].to_object)
|
||||
|
||||
contents = '100644 x\0%s100755 y\0%s' % ('\x11' * 20, '\x22' * 20)
|
||||
self.assertEqual((pygit2.GIT_OBJ_TREE, contents),
|
||||
self.repo.read(tree.hex))
|
||||
x = tree['x']
|
||||
y = tree['y']
|
||||
self.assertEqual(x.filemode, 0o0100644)
|
||||
self.assertEqual(y.filemode, 0o0100755)
|
||||
|
||||
self.assertEqual(x.to_object().oid, b0)
|
||||
self.assertEqual(y.to_object().oid, b1)
|
||||
|
||||
|
||||
|
||||
def test_modify_tree(self):
|
||||
tree = self.repo[TREE_SHA]
|
||||
|
Reference in New Issue
Block a user