2 #include "structmember.h"
4 #include <libgit-thin.h>
6 #define UNUSED(x) (x = x)
8 PyMODINIT_FUNC
initpygit(void);
10 static int repository_open
;
17 pygit_repo_read_commit(GitRepoObject
*self
, PyObject
*args
)
22 unsigned char sha1
[GIT_SHA1_SIZE
];
29 if (!PyArg_ParseTuple(args
, "s", &hex
))
32 err
= git_hex_to_sha1(hex
, sha1
);
36 err
= git_repo_commit_read(sha1
, &buf
, NULL
);
40 printf("%s", (char *) buf
);
45 static PyMethodDef git_repo_methods
[] = {
46 {"read_commit", (PyCFunction
) pygit_repo_read_commit
,
52 git_repo_getattr(GitRepoObject
*self
, char *name
)
56 res
= Py_FindMethod(git_repo_methods
, (PyObject
*) self
, name
);
64 git_repo_dealloc(GitRepoObject
*self
)
69 static PyTypeObject Git_Repo_Type
= {
70 PyObject_HEAD_INIT(NULL
)
72 "pygit.repo", /* tp_name */
73 sizeof(GitRepoObject
), /* tp_basicsize */
75 (destructor
)git_repo_dealloc
, /* tp_dealloc */
77 (getattrfunc
)git_repo_getattr
, /* tp_getattr */
82 0, /* tp_as_sequence */
83 0, /* tp_as_mapping */
90 Py_TPFLAGS_DEFAULT
, /* tp_flags */
94 0, /* tp_richcompare */
98 pygit_open(PyObject
*self
, PyObject
*args
)
105 if (!PyArg_ParseTuple(args
, "s", &dir
))
108 if (git_repo_open(dir
)) {
109 PyErr_SetFromErrno(PyExc_IOError
);
113 m
= PyObject_New(GitRepoObject
, &Git_Repo_Type
);
118 return (PyObject
*) m
;
121 static PyMethodDef pygit_methods
[] = {
122 { "open", pygit_open
, METH_VARARGS
, "Open a GIT repository" },
123 { NULL
, NULL
, 0, NULL
}
129 /* Patch object types */
130 Git_Repo_Type
.ob_type
= &PyType_Type
;
132 (void) Py_InitModule("pygit", pygit_methods
);