Split treebuilder.c from tree.c
This commit is contained in:
@@ -43,8 +43,4 @@ TreeEntry* Tree_getitem_by_index(Tree *self, PyObject *py_index);
|
|||||||
TreeEntry* Tree_getitem(Tree *self, PyObject *value);
|
TreeEntry* Tree_getitem(Tree *self, PyObject *value);
|
||||||
PyObject* Tree_diff_tree(Tree *self, PyObject *args);
|
PyObject* Tree_diff_tree(Tree *self, PyObject *args);
|
||||||
|
|
||||||
PyObject* TreeBuilder_insert(TreeBuilder *self, PyObject *args);
|
|
||||||
PyObject* TreeBuilder_write(TreeBuilder *self);
|
|
||||||
PyObject* TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename);
|
|
||||||
PyObject* TreeBuilder_clear(TreeBuilder *self);
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
41
include/pygit2/treebuilder.h
Normal file
41
include/pygit2/treebuilder.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 The pygit2 contributors
|
||||||
|
*
|
||||||
|
* This file is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License, version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* In addition to the permissions in the GNU General Public License,
|
||||||
|
* the authors give you unlimited permission to link the compiled
|
||||||
|
* version of this file into combinations with other programs,
|
||||||
|
* and to distribute those combinations without any restriction
|
||||||
|
* coming from the use of this file. (The General Public License
|
||||||
|
* restrictions do apply in other respects; for example, they cover
|
||||||
|
* modification of the file, and distribution when not linked into
|
||||||
|
* a combined executable.)
|
||||||
|
*
|
||||||
|
* This file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDE_pygit2_treebuilder_h
|
||||||
|
#define INCLUDE_pygit2_treebuilder_h
|
||||||
|
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#include <Python.h>
|
||||||
|
#include <git2.h>
|
||||||
|
#include <pygit2/types.h>
|
||||||
|
|
||||||
|
PyObject* TreeBuilder_insert(TreeBuilder *self, PyObject *args);
|
||||||
|
PyObject* TreeBuilder_write(TreeBuilder *self);
|
||||||
|
PyObject* TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename);
|
||||||
|
PyObject* TreeBuilder_clear(TreeBuilder *self);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -101,7 +101,7 @@ PyMethodDef TreeEntry_methods[] = {
|
|||||||
|
|
||||||
PyTypeObject TreeEntryType = {
|
PyTypeObject TreeEntryType = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
"_pygit2.TreeEntry", /* tp_name */
|
"_pygit2.TreeEntry", /* tp_name */
|
||||||
sizeof(TreeEntry), /* tp_basicsize */
|
sizeof(TreeEntry), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
(destructor)TreeEntry_dealloc, /* tp_dealloc */
|
(destructor)TreeEntry_dealloc, /* tp_dealloc */
|
||||||
@@ -348,7 +348,7 @@ PyMethodDef Tree_methods[] = {
|
|||||||
|
|
||||||
PyTypeObject TreeType = {
|
PyTypeObject TreeType = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
"_pygit2.Tree", /* tp_name */
|
"_pygit2.Tree", /* tp_name */
|
||||||
sizeof(Tree), /* tp_basicsize */
|
sizeof(Tree), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
0, /* tp_dealloc */
|
0, /* tp_dealloc */
|
||||||
@@ -388,131 +388,6 @@ PyTypeObject TreeType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TreeBuilder_dealloc(TreeBuilder* self)
|
|
||||||
{
|
|
||||||
Py_XDECREF(self->repo);
|
|
||||||
git_treebuilder_free(self->bld);
|
|
||||||
PyObject_Del(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
TreeBuilder_insert(TreeBuilder *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *py_oid;
|
|
||||||
int len, err, attr;
|
|
||||||
git_oid oid;
|
|
||||||
const char *fname;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sOi", &fname, &py_oid, &attr)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = py_str_to_git_oid(py_oid, &oid);
|
|
||||||
if (len < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = git_treebuilder_insert(NULL, self->bld, fname, &oid, attr);
|
|
||||||
if (err < 0) {
|
|
||||||
Error_set(err);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
TreeBuilder_write(TreeBuilder *self)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
git_oid oid;
|
|
||||||
|
|
||||||
err = git_treebuilder_write(&oid, self->repo->repo, self->bld);
|
|
||||||
if (err < 0)
|
|
||||||
return Error_set(err);
|
|
||||||
|
|
||||||
return git_oid_to_python(&oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename)
|
|
||||||
{
|
|
||||||
char *filename = py_path_to_c_str(py_filename);
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (filename == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
err = git_treebuilder_remove(self->bld, filename);
|
|
||||||
free(filename);
|
|
||||||
if (err < 0)
|
|
||||||
return Error_set(err);
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
TreeBuilder_clear(TreeBuilder *self)
|
|
||||||
{
|
|
||||||
git_treebuilder_clear(self->bld);
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyMethodDef TreeBuilder_methods[] = {
|
|
||||||
{"insert", (PyCFunction)TreeBuilder_insert, METH_VARARGS,
|
|
||||||
"Insert or replace an entry in the treebuilder"},
|
|
||||||
{"write", (PyCFunction)TreeBuilder_write, METH_NOARGS,
|
|
||||||
"Write the tree to the given repository"},
|
|
||||||
{"remove", (PyCFunction)TreeBuilder_remove, METH_O,
|
|
||||||
"Remove an entry from the builder"},
|
|
||||||
{"clear", (PyCFunction)TreeBuilder_clear, METH_NOARGS,
|
|
||||||
"Clear all the entries in the builder"},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject TreeBuilderType = {
|
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
|
||||||
"_pygit2.TreeBuilder", /* tp_name */
|
|
||||||
sizeof(TreeBuilder), /* tp_basicsize */
|
|
||||||
0, /* tp_itemsize */
|
|
||||||
(destructor)TreeBuilder_dealloc, /* tp_dealloc */
|
|
||||||
0, /* tp_print */
|
|
||||||
0, /* tp_getattr */
|
|
||||||
0, /* tp_setattr */
|
|
||||||
0, /* tp_compare */
|
|
||||||
0, /* tp_repr */
|
|
||||||
0, /* tp_as_number */
|
|
||||||
0, /* tp_as_sequence */
|
|
||||||
0, /* tp_as_mapping */
|
|
||||||
0, /* tp_hash */
|
|
||||||
0, /* tp_call */
|
|
||||||
0, /* tp_str */
|
|
||||||
0, /* tp_getattro */
|
|
||||||
0, /* tp_setattro */
|
|
||||||
0, /* tp_as_buffer */
|
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
||||||
"TreeBuilder objects", /* tp_doc */
|
|
||||||
0, /* tp_traverse */
|
|
||||||
0, /* tp_clear */
|
|
||||||
0, /* tp_richcompare */
|
|
||||||
0, /* tp_weaklistoffset */
|
|
||||||
0, /* tp_iter */
|
|
||||||
0, /* tp_iternext */
|
|
||||||
TreeBuilder_methods, /* tp_methods */
|
|
||||||
0, /* tp_members */
|
|
||||||
0, /* tp_getset */
|
|
||||||
0, /* tp_base */
|
|
||||||
0, /* tp_dict */
|
|
||||||
0, /* tp_descr_get */
|
|
||||||
0, /* tp_descr_set */
|
|
||||||
0, /* tp_dictoffset */
|
|
||||||
0, /* tp_init */
|
|
||||||
0, /* tp_alloc */
|
|
||||||
0, /* tp_new */
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TreeIter_dealloc(TreeIter *self)
|
TreeIter_dealloc(TreeIter *self)
|
||||||
{
|
{
|
||||||
@@ -535,7 +410,7 @@ TreeIter_iternext(TreeIter *self)
|
|||||||
|
|
||||||
PyTypeObject TreeIterType = {
|
PyTypeObject TreeIterType = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
"_pygit2.TreeIter", /* tp_name */
|
"_pygit2.TreeIter", /* tp_name */
|
||||||
sizeof(TreeIter), /* tp_basicsize */
|
sizeof(TreeIter), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
(destructor)TreeIter_dealloc , /* tp_dealloc */
|
(destructor)TreeIter_dealloc , /* tp_dealloc */
|
||||||
|
|||||||
159
src/pygit2/treebuilder.c
Normal file
159
src/pygit2/treebuilder.c
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 The pygit2 contributors
|
||||||
|
*
|
||||||
|
* This file is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License, version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* In addition to the permissions in the GNU General Public License,
|
||||||
|
* the authors give you unlimited permission to link the compiled
|
||||||
|
* version of this file into combinations with other programs,
|
||||||
|
* and to distribute those combinations without any restriction
|
||||||
|
* coming from the use of this file. (The General Public License
|
||||||
|
* restrictions do apply in other respects; for example, they cover
|
||||||
|
* modification of the file, and distribution when not linked into
|
||||||
|
* a combined executable.)
|
||||||
|
*
|
||||||
|
* This file is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#include <Python.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pygit2/error.h>
|
||||||
|
#include <pygit2/utils.h>
|
||||||
|
#include <pygit2/oid.h>
|
||||||
|
#include <pygit2/treebuilder.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TreeBuilder_dealloc(TreeBuilder *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->repo);
|
||||||
|
git_treebuilder_free(self->bld);
|
||||||
|
PyObject_Del(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
TreeBuilder_insert(TreeBuilder *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *py_oid;
|
||||||
|
int len, err, attr;
|
||||||
|
git_oid oid;
|
||||||
|
const char *fname;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "sOi", &fname, &py_oid, &attr)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = py_str_to_git_oid(py_oid, &oid);
|
||||||
|
if (len < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = git_treebuilder_insert(NULL, self->bld, fname, &oid, attr);
|
||||||
|
if (err < 0) {
|
||||||
|
Error_set(err);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
TreeBuilder_write(TreeBuilder *self)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
git_oid oid;
|
||||||
|
|
||||||
|
err = git_treebuilder_write(&oid, self->repo->repo, self->bld);
|
||||||
|
if (err < 0)
|
||||||
|
return Error_set(err);
|
||||||
|
|
||||||
|
return git_oid_to_python(&oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename)
|
||||||
|
{
|
||||||
|
char *filename = py_path_to_c_str(py_filename);
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (filename == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
err = git_treebuilder_remove(self->bld, filename);
|
||||||
|
free(filename);
|
||||||
|
if (err < 0)
|
||||||
|
return Error_set(err);
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
TreeBuilder_clear(TreeBuilder *self)
|
||||||
|
{
|
||||||
|
git_treebuilder_clear(self->bld);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyMethodDef TreeBuilder_methods[] = {
|
||||||
|
{"insert", (PyCFunction)TreeBuilder_insert, METH_VARARGS,
|
||||||
|
"Insert or replace an entry in the treebuilder"},
|
||||||
|
{"write", (PyCFunction)TreeBuilder_write, METH_NOARGS,
|
||||||
|
"Write the tree to the given repository"},
|
||||||
|
{"remove", (PyCFunction)TreeBuilder_remove, METH_O,
|
||||||
|
"Remove an entry from the builder"},
|
||||||
|
{"clear", (PyCFunction)TreeBuilder_clear, METH_NOARGS,
|
||||||
|
"Clear all the entries in the builder"},
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
PyTypeObject TreeBuilderType = {
|
||||||
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
|
"_pygit2.TreeBuilder", /* tp_name */
|
||||||
|
sizeof(TreeBuilder), /* tp_basicsize */
|
||||||
|
0, /* tp_itemsize */
|
||||||
|
(destructor)TreeBuilder_dealloc, /* tp_dealloc */
|
||||||
|
0, /* tp_print */
|
||||||
|
0, /* tp_getattr */
|
||||||
|
0, /* tp_setattr */
|
||||||
|
0, /* tp_compare */
|
||||||
|
0, /* tp_repr */
|
||||||
|
0, /* tp_as_number */
|
||||||
|
0, /* tp_as_sequence */
|
||||||
|
0, /* tp_as_mapping */
|
||||||
|
0, /* tp_hash */
|
||||||
|
0, /* tp_call */
|
||||||
|
0, /* tp_str */
|
||||||
|
0, /* tp_getattro */
|
||||||
|
0, /* tp_setattro */
|
||||||
|
0, /* tp_as_buffer */
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
|
"TreeBuilder objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
TreeBuilder_methods, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
0, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
0, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
0, /* tp_new */
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user