A basic Branch type (subtype of Reference)

This commit is contained in:
Daniel Rodríguez Troitiño 2013-05-17 21:39:51 +02:00
parent 0c86307eb5
commit f2b1644510
4 changed files with 141 additions and 0 deletions

97
src/branch.c Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright 2010-2013 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.
*/
#include "types.h"
#include "reference.h"
PyMethodDef Branch_methods[] = {
{NULL}
};
PyGetSetDef Branch_getseters[] = {
{NULL}
};
PyDoc_STRVAR(Branch__doc__, "Branch.");
PyTypeObject BranchType = {
PyVarObject_HEAD_INIT(NULL, 0)
"_pygit2.Branch", /* tp_name */
sizeof(Branch), /* tp_basicsize */
0, /* tp_itemsize */
0, /* 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, /* tp_flags */
Branch__doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
Branch_methods, /* tp_methods */
0, /* tp_members */
Branch_getseters, /* 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 */
};
PyObject *
wrap_branch(git_reference *c_reference, Repository *repo)
{
Branch *py_branch=NULL;
py_branch = PyObject_New(Branch, &BranchType);
if (py_branch) {
py_branch->reference = c_reference;
if (repo) {
py_branch->repo = repo;
Py_INCREF(repo);
}
}
return (PyObject *)py_branch;
}

35
src/branch.h Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright 2010-2013 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_branch_h
#define INCLUDE_pygit2_branch_h
#include <git2.h>
PyObject* wrap_branch(git_reference *c_reference, Repository *repo);
#endif

View File

@ -59,6 +59,7 @@ extern PyTypeObject ConfigType;
extern PyTypeObject ReferenceType;
extern PyTypeObject RefLogIterType;
extern PyTypeObject RefLogEntryType;
extern PyTypeObject BranchType;
extern PyTypeObject SignatureType;
extern PyTypeObject RemoteType;
extern PyTypeObject NoteType;
@ -331,6 +332,12 @@ moduleinit(PyObject* m)
ADD_CONSTANT_INT(m, GIT_REF_SYMBOLIC)
ADD_CONSTANT_INT(m, GIT_REF_LISTALL)
/*
* Branches
*/
INIT_TYPE(BranchType, &ReferenceType, PyType_GenericNew);
ADD_TYPE(m, Branch)
/*
* Index & Working copy
*/

View File

@ -160,6 +160,8 @@ SIMPLE_TYPE(Walker, git_revwalk, walk)
SIMPLE_TYPE(Reference, git_reference, reference)
typedef Reference Branch;
typedef struct {
PyObject_HEAD
git_signature *signature;