Remove all warnings during compilation.
- Many PyLong_FromLong changed into PyLong_FromLongLong. - A long used as out argument for git_config_parse_int64 changed into a int64_t. - Many len variables changed from int into Py_ssize_t. Removed some castings related to those variables. - Functions py_str_to_git_oid(_expand) return a Py_ssize_t, which is the return type of PyBytes_AsStringAndSize. Error values are usually casted to int, since the only error returned from those functions is -1. - Changed RefLogIter i and size fields from int into size_t. - Marked to_unicode_n and to_bytes inline functions as "unused". Not all compilation units which include utils.h use them. Tested with: $ clang --version Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.3.0 Thread model: posix
This commit is contained in:
@@ -37,7 +37,7 @@ PyDoc_STRVAR(Blob_size__doc__, "Size.");
|
|||||||
PyObject *
|
PyObject *
|
||||||
Blob_size__get__(Blob *self)
|
Blob_size__get__(Blob *self)
|
||||||
{
|
{
|
||||||
return PyLong_FromLong(git_blob_rawsize(self->blob));
|
return PyLong_FromLongLong(git_blob_rawsize(self->blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ PyDoc_STRVAR(Commit_commit_time__doc__, "Commit time.");
|
|||||||
PyObject *
|
PyObject *
|
||||||
Commit_commit_time__get__(Commit *commit)
|
Commit_commit_time__get__(Commit *commit)
|
||||||
{
|
{
|
||||||
return PyLong_FromLong(git_commit_time(commit->commit));
|
return PyLong_FromLongLong(git_commit_time(commit->commit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -172,7 +172,7 @@ Config_contains(Config *self, PyObject *py_key) {
|
|||||||
PyObject *
|
PyObject *
|
||||||
Config_getitem(Config *self, PyObject *py_key)
|
Config_getitem(Config *self, PyObject *py_key)
|
||||||
{
|
{
|
||||||
long value_int;
|
int64_t value_int;
|
||||||
int err, value_bool;
|
int err, value_bool;
|
||||||
const char *value_str;
|
const char *value_str;
|
||||||
char *key;
|
char *key;
|
||||||
@@ -187,7 +187,7 @@ Config_getitem(Config *self, PyObject *py_key)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (git_config_parse_int64(&value_int, value_str) == 0)
|
if (git_config_parse_int64(&value_int, value_str) == 0)
|
||||||
py_value = PyLong_FromLong(value_int);
|
py_value = PyLong_FromLongLong(value_int);
|
||||||
else if(git_config_parse_bool(&value_bool, value_str) == 0)
|
else if(git_config_parse_bool(&value_bool, value_str) == 0)
|
||||||
py_value = PyBool_FromLong(value_bool);
|
py_value = PyBool_FromLong(value_bool);
|
||||||
else
|
else
|
||||||
|
@@ -351,14 +351,14 @@ Index_read_tree(Index *self, PyObject *value)
|
|||||||
{
|
{
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
int err, len;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
|
|
||||||
len = py_str_to_git_oid(value, &oid);
|
len = py_str_to_git_oid(value, &oid);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_tree_lookup_prefix(&tree, self->repo->repo, &oid,
|
err = git_tree_lookup_prefix(&tree, self->repo->repo, &oid, len);
|
||||||
(unsigned int)len);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
|
12
src/oid.c
12
src/oid.c
@@ -45,7 +45,7 @@ git_oid_to_python(const git_oid *oid)
|
|||||||
return (PyObject*)py_oid;
|
return (PyObject*)py_oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Py_ssize_t
|
||||||
_oid_from_hex(PyObject *py_oid, git_oid *oid)
|
_oid_from_hex(PyObject *py_oid, git_oid *oid)
|
||||||
{
|
{
|
||||||
PyObject *py_hex;
|
PyObject *py_hex;
|
||||||
@@ -97,7 +97,7 @@ _oid_from_hex(PyObject *py_oid, git_oid *oid)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Py_ssize_t
|
||||||
py_str_to_git_oid(PyObject *py_oid, git_oid *oid)
|
py_str_to_git_oid(PyObject *py_oid, git_oid *oid)
|
||||||
{
|
{
|
||||||
/* Oid */
|
/* Oid */
|
||||||
@@ -110,11 +110,11 @@ py_str_to_git_oid(PyObject *py_oid, git_oid *oid)
|
|||||||
return _oid_from_hex(py_oid, oid);
|
return _oid_from_hex(py_oid, oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Py_ssize_t
|
||||||
py_str_to_git_oid_expand(git_repository *repo, PyObject *py_str, git_oid *oid)
|
py_str_to_git_oid_expand(git_repository *repo, PyObject *py_str, git_oid *oid)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int len;
|
Py_ssize_t len;
|
||||||
git_odb *odb;
|
git_odb *odb;
|
||||||
git_odb_object *obj;
|
git_odb_object *obj;
|
||||||
|
|
||||||
@@ -197,8 +197,8 @@ Oid_init(Oid *self, PyObject *args, PyObject *kw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Case 2: hex */
|
/* Case 2: hex */
|
||||||
err = _oid_from_hex(hex, &self->oid);
|
len = _oid_from_hex(hex, &self->oid);
|
||||||
if (err < 0)
|
if (len < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -32,9 +32,9 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
int py_str_to_git_oid(PyObject *py_str, git_oid *oid);
|
Py_ssize_t py_str_to_git_oid(PyObject *py_str, git_oid *oid);
|
||||||
int py_str_to_git_oid_expand(git_repository *repo, PyObject *py_str,
|
Py_ssize_t py_str_to_git_oid_expand(git_repository *repo, PyObject *py_str,
|
||||||
git_oid *oid);
|
git_oid *oid);
|
||||||
PyObject* git_oid_to_python(const git_oid *oid);
|
PyObject* git_oid_to_python(const git_oid *oid);
|
||||||
PyObject* git_oid_to_py_str(const git_oid *oid);
|
PyObject* git_oid_to_py_str(const git_oid *oid);
|
||||||
|
|
||||||
|
@@ -226,6 +226,7 @@ Reference_target__set__(Reference *self, PyObject *py_target)
|
|||||||
git_oid oid;
|
git_oid oid;
|
||||||
char *c_name;
|
char *c_name;
|
||||||
int err;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
git_reference *new_ref;
|
git_reference *new_ref;
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
|
|
||||||
@@ -234,9 +235,11 @@ Reference_target__set__(Reference *self, PyObject *py_target)
|
|||||||
/* Case 1: Direct */
|
/* Case 1: Direct */
|
||||||
if (GIT_REF_OID == git_reference_type(self->reference)) {
|
if (GIT_REF_OID == git_reference_type(self->reference)) {
|
||||||
repo = git_reference_owner(self->reference);
|
repo = git_reference_owner(self->reference);
|
||||||
err = py_str_to_git_oid_expand(repo, py_target, &oid);
|
len = py_str_to_git_oid_expand(repo, py_target, &oid);
|
||||||
if (err < 0)
|
if (len < 0) {
|
||||||
|
err = (int)len;
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
err = git_reference_set_target(&new_ref, self->reference, &oid);
|
err = git_reference_set_target(&new_ref, self->reference, &oid);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
|
@@ -246,7 +246,8 @@ PyDoc_STRVAR(Repository_git_object_lookup_prefix__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Repository_git_object_lookup_prefix(Repository *self, PyObject *key)
|
Repository_git_object_lookup_prefix(Repository *self, PyObject *key)
|
||||||
{
|
{
|
||||||
int err, len;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_object *obj;
|
git_object *obj;
|
||||||
|
|
||||||
@@ -254,8 +255,7 @@ Repository_git_object_lookup_prefix(Repository *self, PyObject *key)
|
|||||||
if (len < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_object_lookup_prefix(&obj, self->repo, &oid,
|
err = git_object_lookup_prefix(&obj, self->repo, &oid, len, GIT_OBJ_ANY);
|
||||||
(unsigned int)len, GIT_OBJ_ANY);
|
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
return wrap_object(obj, self);
|
return wrap_object(obj, self);
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ Repository_read(Repository *self, PyObject *py_hex)
|
|||||||
{
|
{
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_odb_object *obj;
|
git_odb_object *obj;
|
||||||
int len;
|
Py_ssize_t len;
|
||||||
PyObject* tuple;
|
PyObject* tuple;
|
||||||
|
|
||||||
len = py_str_to_git_oid(py_hex, &oid);
|
len = py_str_to_git_oid(py_hex, &oid);
|
||||||
@@ -509,6 +509,7 @@ Repository_walk(Repository *self, PyObject *args)
|
|||||||
PyObject *value;
|
PyObject *value;
|
||||||
unsigned int sort;
|
unsigned int sort;
|
||||||
int err;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_revwalk *walk;
|
git_revwalk *walk;
|
||||||
Walker *py_walker;
|
Walker *py_walker;
|
||||||
@@ -525,10 +526,10 @@ Repository_walk(Repository *self, PyObject *args)
|
|||||||
|
|
||||||
/* Push */
|
/* Push */
|
||||||
if (value != Py_None) {
|
if (value != Py_None) {
|
||||||
err = py_str_to_git_oid_expand(self->repo, value, &oid);
|
len = py_str_to_git_oid_expand(self->repo, value, &oid);
|
||||||
if (err < 0) {
|
if (len < 0) {
|
||||||
git_revwalk_free(walk);
|
git_revwalk_free(walk);
|
||||||
return Error_set(err);
|
return Error_set((int)len);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = git_revwalk_push(walk, &oid);
|
err = git_revwalk_push(walk, &oid);
|
||||||
@@ -639,7 +640,8 @@ Repository_create_commit(Repository *self, PyObject *args)
|
|||||||
git_tree *tree = NULL;
|
git_tree *tree = NULL;
|
||||||
int parent_count;
|
int parent_count;
|
||||||
git_commit **parents = NULL;
|
git_commit **parents = NULL;
|
||||||
int err = 0, i = 0, len;
|
int err = 0, i = 0;
|
||||||
|
Py_ssize_t len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "zO!O!OOO!|s",
|
if (!PyArg_ParseTuple(args, "zO!O!OOO!|s",
|
||||||
&update_ref,
|
&update_ref,
|
||||||
@@ -659,7 +661,7 @@ Repository_create_commit(Repository *self, PyObject *args)
|
|||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
err = git_tree_lookup_prefix(&tree, self->repo, &oid, (unsigned int)len);
|
err = git_tree_lookup_prefix(&tree, self->repo, &oid, len);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
Error_set(err);
|
Error_set(err);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -717,7 +719,8 @@ Repository_create_tag(Repository *self, PyObject *args)
|
|||||||
char *tag_name, *message;
|
char *tag_name, *message;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_object *target = NULL;
|
git_object *target = NULL;
|
||||||
int err, target_type, len;
|
int err, target_type;
|
||||||
|
Py_ssize_t len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sOiO!s",
|
if (!PyArg_ParseTuple(args, "sOiO!s",
|
||||||
&tag_name,
|
&tag_name,
|
||||||
@@ -840,13 +843,14 @@ Repository_create_reference_direct(Repository *self, PyObject *args,
|
|||||||
char *c_name;
|
char *c_name;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
int err, force;
|
int err, force;
|
||||||
|
Py_ssize_t len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sOi", &c_name, &py_obj, &force))
|
if (!PyArg_ParseTuple(args, "sOi", &c_name, &py_obj, &force))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = py_str_to_git_oid_expand(self->repo, py_obj, &oid);
|
len = py_str_to_git_oid_expand(self->repo, py_obj, &oid);
|
||||||
if (err < 0)
|
if (len < 0)
|
||||||
return Error_set(err);
|
return Error_set((int)len);
|
||||||
|
|
||||||
err = git_reference_create(&c_reference, self->repo, c_name, &oid, force);
|
err = git_reference_create(&c_reference, self->repo, c_name, &oid, force);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@@ -967,6 +971,7 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
|||||||
git_tree *tree = NULL;
|
git_tree *tree = NULL;
|
||||||
git_tree *must_free = NULL;
|
git_tree *must_free = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|O", &py_src))
|
if (!PyArg_ParseTuple(args, "|O", &py_src))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -980,8 +985,8 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
tree = py_tree->tree;
|
tree = py_tree->tree;
|
||||||
} else {
|
} else {
|
||||||
err = py_str_to_git_oid_expand(self->repo, py_src, &oid);
|
len = py_str_to_git_oid_expand(self->repo, py_src, &oid);
|
||||||
if (err < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_tree_lookup(&tree, self->repo, &oid);
|
err = git_tree_lookup(&tree, self->repo, &oid);
|
||||||
|
@@ -148,7 +148,7 @@ PyDoc_STRVAR(Signature_time__doc__, "Unix time.");
|
|||||||
PyObject *
|
PyObject *
|
||||||
Signature_time__get__(Signature *self)
|
Signature_time__get__(Signature *self)
|
||||||
{
|
{
|
||||||
return PyLong_FromLong(self->signature->when.time);
|
return PyLong_FromLongLong(self->signature->when.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -53,7 +53,8 @@ PyObject *
|
|||||||
TreeBuilder_insert(TreeBuilder *self, PyObject *args)
|
TreeBuilder_insert(TreeBuilder *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *py_oid;
|
PyObject *py_oid;
|
||||||
int len, err, attr;
|
Py_ssize_t len;
|
||||||
|
int err, attr;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
const char *fname;
|
const char *fname;
|
||||||
|
|
||||||
|
@@ -174,8 +174,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
git_reflog *reflog;
|
git_reflog *reflog;
|
||||||
int i;
|
size_t i;
|
||||||
int size;
|
size_t size;
|
||||||
} RefLogIter;
|
} RefLogIter;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -33,6 +33,12 @@
|
|||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
# define PYGIT2_FN_UNUSED __attribute__((unused))
|
||||||
|
#else
|
||||||
|
# define PYGIT2_FN_UNUSED
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Python 2 support */
|
/* Python 2 support */
|
||||||
#if PY_MAJOR_VERSION == 2
|
#if PY_MAJOR_VERSION == 2
|
||||||
#define PyLong_FromSize_t PyInt_FromSize_t
|
#define PyLong_FromSize_t PyInt_FromSize_t
|
||||||
@@ -75,6 +81,7 @@
|
|||||||
/* Utilities */
|
/* Utilities */
|
||||||
#define to_unicode(x, encoding, errors) to_unicode_n(x, strlen(x), encoding, errors)
|
#define to_unicode(x, encoding, errors) to_unicode_n(x, strlen(x), encoding, errors)
|
||||||
|
|
||||||
|
PYGIT2_FN_UNUSED
|
||||||
Py_LOCAL_INLINE(PyObject*)
|
Py_LOCAL_INLINE(PyObject*)
|
||||||
to_unicode_n(const char *value, size_t len, const char *encoding, const char *errors)
|
to_unicode_n(const char *value, size_t len, const char *encoding, const char *errors)
|
||||||
{
|
{
|
||||||
@@ -90,6 +97,7 @@ to_unicode_n(const char *value, size_t len, const char *encoding, const char *er
|
|||||||
return PyUnicode_Decode(value, len, encoding, errors);
|
return PyUnicode_Decode(value, len, encoding, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PYGIT2_FN_UNUSED
|
||||||
Py_LOCAL_INLINE(PyObject*)
|
Py_LOCAL_INLINE(PyObject*)
|
||||||
to_bytes(const char * value)
|
to_bytes(const char * value)
|
||||||
{
|
{
|
||||||
|
14
src/walker.c
14
src/walker.c
@@ -53,11 +53,12 @@ PyObject *
|
|||||||
Walker_hide(Walker *self, PyObject *py_hex)
|
Walker_hide(Walker *self, PyObject *py_hex)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
|
|
||||||
err = py_str_to_git_oid_expand(self->repo->repo, py_hex, &oid);
|
len = py_str_to_git_oid_expand(self->repo->repo, py_hex, &oid);
|
||||||
if (err < 0)
|
if (len < 0)
|
||||||
return Error_set(err);
|
return Error_set((int)len);
|
||||||
|
|
||||||
err = git_revwalk_hide(self->walk, &oid);
|
err = git_revwalk_hide(self->walk, &oid);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@@ -76,11 +77,12 @@ PyObject *
|
|||||||
Walker_push(Walker *self, PyObject *py_hex)
|
Walker_push(Walker *self, PyObject *py_hex)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
Py_ssize_t len;
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
|
|
||||||
err = py_str_to_git_oid_expand(self->repo->repo, py_hex, &oid);
|
len = py_str_to_git_oid_expand(self->repo->repo, py_hex, &oid);
|
||||||
if (err < 0)
|
if (len < 0)
|
||||||
return Error_set(err);
|
return Error_set((int)len);
|
||||||
|
|
||||||
err = git_revwalk_push(self->walk, &oid);
|
err = git_revwalk_push(self->walk, &oid);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
|
Reference in New Issue
Block a user