Adjust to the git_buf changes
We no longer need the max-path define, so we can get rid of that and the pypy checking.
This commit is contained in:
47
src/branch.c
47
src/branch.c
@@ -135,34 +135,19 @@ PyObject *
|
|||||||
Branch_remote_name__get__(Branch *self)
|
Branch_remote_name__get__(Branch *self)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
git_buf name = {NULL};
|
||||||
const char *branch_name;
|
const char *branch_name;
|
||||||
char *c_name = NULL;
|
|
||||||
PyObject *py_name;
|
PyObject *py_name;
|
||||||
|
|
||||||
CHECK_REFERENCE(self);
|
CHECK_REFERENCE(self);
|
||||||
|
|
||||||
branch_name = git_reference_name(self->reference);
|
branch_name = git_reference_name(self->reference);
|
||||||
/* Get the length of the remote name */
|
err = git_branch_remote_name(&name, self->repo->repo, branch_name);
|
||||||
err = git_branch_remote_name(NULL, 0, self->repo->repo, branch_name);
|
|
||||||
if (err < GIT_OK)
|
if (err < GIT_OK)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
/* Get the actual remote name */
|
py_name = to_unicode(name.ptr, NULL, NULL);
|
||||||
c_name = calloc(err, sizeof(char));
|
git_buf_free(&name);
|
||||||
if (c_name == NULL)
|
|
||||||
return PyErr_NoMemory();
|
|
||||||
|
|
||||||
err = git_branch_remote_name(c_name,
|
|
||||||
err * sizeof(char),
|
|
||||||
self->repo->repo,
|
|
||||||
branch_name);
|
|
||||||
if (err < GIT_OK) {
|
|
||||||
free(c_name);
|
|
||||||
return Error_set(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
py_name = to_unicode_n(c_name, err - 1, NULL, NULL);
|
|
||||||
free(c_name);
|
|
||||||
|
|
||||||
return py_name;
|
return py_name;
|
||||||
}
|
}
|
||||||
@@ -227,34 +212,20 @@ PyObject *
|
|||||||
Branch_upstream_name__get__(Branch *self)
|
Branch_upstream_name__get__(Branch *self)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
git_buf name = {NULL};
|
||||||
const char *branch_name;
|
const char *branch_name;
|
||||||
char *c_name = NULL;
|
|
||||||
PyObject *py_name;
|
PyObject *py_name;
|
||||||
|
|
||||||
CHECK_REFERENCE(self);
|
CHECK_REFERENCE(self);
|
||||||
|
|
||||||
branch_name = git_reference_name(self->reference);
|
branch_name = git_reference_name(self->reference);
|
||||||
/* Get the length of the upstream name */
|
|
||||||
err = git_branch_upstream_name(NULL, 0, self->repo->repo, branch_name);
|
err = git_branch_upstream_name(&name, self->repo->repo, branch_name);
|
||||||
if (err < GIT_OK)
|
if (err < GIT_OK)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
/* Get the actual upstream name */
|
py_name = to_unicode(name.ptr, NULL, NULL);
|
||||||
c_name = calloc(err, sizeof(char));
|
git_buf_free(&name);
|
||||||
if (c_name == NULL)
|
|
||||||
return PyErr_NoMemory();
|
|
||||||
|
|
||||||
err = git_branch_upstream_name(c_name,
|
|
||||||
err * sizeof(char),
|
|
||||||
self->repo->repo,
|
|
||||||
branch_name);
|
|
||||||
if (err < GIT_OK) {
|
|
||||||
free(c_name);
|
|
||||||
return Error_set(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
py_name = to_unicode_n(c_name, err - 1, NULL, NULL);
|
|
||||||
free(c_name);
|
|
||||||
|
|
||||||
return py_name;
|
return py_name;
|
||||||
}
|
}
|
||||||
|
20
src/config.c
20
src/config.c
@@ -103,10 +103,11 @@ PyDoc_STRVAR(Config_get_global_config__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Config_get_global_config(void)
|
Config_get_global_config(void)
|
||||||
{
|
{
|
||||||
char path[GIT_PATH_MAX];
|
git_buf path = {NULL};
|
||||||
|
PyObject *py_config;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = git_config_find_global(path, GIT_PATH_MAX);
|
err = git_config_find_global(&path);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
if (err == GIT_ENOTFOUND) {
|
if (err == GIT_ENOTFOUND) {
|
||||||
PyErr_SetString(PyExc_IOError, "Global config file not found.");
|
PyErr_SetString(PyExc_IOError, "Global config file not found.");
|
||||||
@@ -116,7 +117,10 @@ Config_get_global_config(void)
|
|||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrap_config(path);
|
py_config = wrap_config(path.ptr);
|
||||||
|
|
||||||
|
git_buf_free(&path);
|
||||||
|
return py_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,10 +132,11 @@ PyDoc_STRVAR(Config_get_system_config__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Config_get_system_config(void)
|
Config_get_system_config(void)
|
||||||
{
|
{
|
||||||
char path[GIT_PATH_MAX];
|
git_buf path = {NULL};
|
||||||
|
PyObject *py_config;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = git_config_find_system(path, GIT_PATH_MAX);
|
err = git_config_find_system(&path);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
if (err == GIT_ENOTFOUND) {
|
if (err == GIT_ENOTFOUND) {
|
||||||
PyErr_SetString(PyExc_IOError, "System config file not found.");
|
PyErr_SetString(PyExc_IOError, "System config file not found.");
|
||||||
@@ -140,7 +145,10 @@ Config_get_system_config(void)
|
|||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrap_config(path);
|
py_config = wrap_config(path.ptr);
|
||||||
|
|
||||||
|
git_buf_free(&path);
|
||||||
|
return py_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
20
src/diff.c
20
src/diff.c
@@ -292,8 +292,7 @@ PyObject *
|
|||||||
Diff_patch__get__(Diff *self)
|
Diff_patch__get__(Diff *self)
|
||||||
{
|
{
|
||||||
git_patch* patch;
|
git_patch* patch;
|
||||||
char **strings = NULL;
|
git_buf buf = {NULL};
|
||||||
char *buffer = NULL;
|
|
||||||
int err = GIT_ERROR;
|
int err = GIT_ERROR;
|
||||||
size_t i, len, num;
|
size_t i, len, num;
|
||||||
PyObject *py_patch = NULL;
|
PyObject *py_patch = NULL;
|
||||||
@@ -301,32 +300,25 @@ Diff_patch__get__(Diff *self)
|
|||||||
num = git_diff_num_deltas(self->list);
|
num = git_diff_num_deltas(self->list);
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
MALLOC(strings, num * sizeof(char*), cleanup);
|
|
||||||
|
|
||||||
for (i = 0, len = 1; i < num ; ++i) {
|
for (i = 0, len = 1; i < num ; ++i) {
|
||||||
err = git_patch_from_diff(&patch, self->list, i);
|
err = git_patch_from_diff(&patch, self->list, i);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
err = git_patch_to_str(&(strings[i]), patch);
|
/* This appends to the current buf, so we can simply keep passing it */
|
||||||
|
err = git_patch_to_buf(&buf, patch);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
len += strlen(strings[i]);
|
|
||||||
git_patch_free(patch);
|
git_patch_free(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
CALLOC(buffer, (len + 1), sizeof(char), cleanup);
|
py_patch = to_unicode(buf.ptr, NULL, NULL);
|
||||||
for (i = 0; i < num; ++i) {
|
git_buf_free(&buf);
|
||||||
strcat(buffer, strings[i]);
|
|
||||||
free(strings[i]);
|
|
||||||
}
|
|
||||||
free(strings);
|
|
||||||
|
|
||||||
py_patch = to_unicode(buffer, NULL, NULL);
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
git_buf_free(&buf);
|
||||||
return (err < 0) ? Error_set(err) : py_patch;
|
return (err < 0) ? Error_set(err) : py_patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/pygit2.c
22
src/pygit2.c
@@ -28,11 +28,6 @@
|
|||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
/* Pypy does not provide this header */
|
|
||||||
#ifndef PYPY_VERSION
|
|
||||||
# include <osdefs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -41,11 +36,6 @@
|
|||||||
#include "oid.h"
|
#include "oid.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
/* FIXME: This is for pypy */
|
|
||||||
#ifndef MAXPATHLEN
|
|
||||||
# define MAXPATHLEN 1024
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern PyObject *GitError;
|
extern PyObject *GitError;
|
||||||
|
|
||||||
extern PyTypeObject RepositoryType;
|
extern PyTypeObject RepositoryType;
|
||||||
@@ -187,21 +177,25 @@ PyDoc_STRVAR(discover_repository__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
discover_repository(PyObject *self, PyObject *args)
|
discover_repository(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
git_buf repo_path = {NULL};
|
||||||
const char *path;
|
const char *path;
|
||||||
|
PyObject *py_repo_path;
|
||||||
int across_fs = 0;
|
int across_fs = 0;
|
||||||
const char *ceiling_dirs = NULL;
|
const char *ceiling_dirs = NULL;
|
||||||
char repo_path[MAXPATHLEN];
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s|Is", &path, &across_fs, &ceiling_dirs))
|
if (!PyArg_ParseTuple(args, "s|Is", &path, &across_fs, &ceiling_dirs))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_repository_discover(repo_path, sizeof(repo_path),
|
memset(&repo_path, 0, sizeof(git_buf));
|
||||||
path, across_fs, ceiling_dirs);
|
err = git_repository_discover(&repo_path, path, across_fs, ceiling_dirs);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return Error_set_str(err, path);
|
return Error_set_str(err, path);
|
||||||
|
|
||||||
return to_path(repo_path);
|
py_repo_path = to_path(repo_path.ptr);
|
||||||
|
git_buf_free(&repo_path);
|
||||||
|
|
||||||
|
return py_repo_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
PyDoc_STRVAR(hashfile__doc__,
|
PyDoc_STRVAR(hashfile__doc__,
|
||||||
|
@@ -155,35 +155,24 @@ PyDoc_STRVAR(Refspec_transform__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_transform(Refspec *self, PyObject *py_str)
|
Refspec_transform(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
|
git_buf trans = {NULL};
|
||||||
const char *str;
|
const char *str;
|
||||||
char *trans;
|
int err;
|
||||||
int err, len, alen;
|
|
||||||
PyObject *py_trans, *tstr;
|
PyObject *py_trans, *tstr;
|
||||||
|
|
||||||
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
alen = len = strlen(str);
|
|
||||||
|
|
||||||
do {
|
err = git_refspec_transform(&trans, self->refspec, str);
|
||||||
alen *= alen;
|
|
||||||
trans = malloc(alen);
|
|
||||||
if (!trans) {
|
|
||||||
Py_DECREF(tstr);
|
|
||||||
return PyErr_NoMemory();
|
|
||||||
}
|
|
||||||
|
|
||||||
err = git_refspec_transform(trans, alen, self->refspec, str);
|
|
||||||
} while(err == GIT_EBUFS);
|
|
||||||
Py_DECREF(tstr);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
free(trans);
|
|
||||||
Error_set(err);
|
Error_set(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
py_trans = to_unicode(trans, NULL, NULL);
|
py_trans = to_unicode(trans.ptr, NULL, NULL);
|
||||||
|
|
||||||
free(trans);
|
git_buf_free(&trans);
|
||||||
|
|
||||||
return py_trans;
|
return py_trans;
|
||||||
}
|
}
|
||||||
@@ -196,35 +185,24 @@ PyDoc_STRVAR(Refspec_rtransform__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_rtransform(Refspec *self, PyObject *py_str)
|
Refspec_rtransform(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
|
git_buf trans = {NULL};
|
||||||
const char *str;
|
const char *str;
|
||||||
char *trans;
|
int err;
|
||||||
int err, len, alen;
|
|
||||||
PyObject *py_trans, *tstr;
|
PyObject *py_trans, *tstr;
|
||||||
|
|
||||||
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
alen = len = strlen(str);
|
|
||||||
|
|
||||||
do {
|
err = git_refspec_rtransform(&trans, self->refspec, str);
|
||||||
alen *= alen;
|
|
||||||
trans = malloc(alen);
|
|
||||||
if (!trans) {
|
|
||||||
Py_DECREF(tstr);
|
|
||||||
return PyErr_NoMemory();
|
|
||||||
}
|
|
||||||
|
|
||||||
err = git_refspec_rtransform(trans, alen, self->refspec, str);
|
|
||||||
} while(err == GIT_EBUFS);
|
|
||||||
Py_DECREF(tstr);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
free(trans);
|
|
||||||
Error_set(err);
|
Error_set(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
py_trans = to_unicode(trans, NULL, NULL);
|
py_trans = to_unicode(trans.ptr, NULL, NULL);
|
||||||
|
|
||||||
free(trans);
|
git_buf_free(&trans);
|
||||||
|
|
||||||
return py_trans;
|
return py_trans;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user