-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.c
More file actions
68 lines (61 loc) · 1.27 KB
/
call.c
File metadata and controls
68 lines (61 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <git2.h>
#include <Python.h>
static int
calculate_commits (char* path, int (*cb)(void *dptr,
time_t), void *dptr)
{
git_repository* rp;
if (git_repository_open (&rp, path))
return 1;
do {
git_revwalk *revwalk = 0;
git_revwalk_new (&revwalk, rp);
git_revwalk_push_head (revwalk);
while (1)
{
git_oid oid;
git_commit* cmt;
int
ret = git_revwalk_next (&oid, revwalk);
if (ret==GIT_ITEROVER) break;
if (!git_commit_lookup (&cmt, rp, &oid))
{
if (cb && dptr)
cb(dptr, git_commit_time (cmt));
git_commit_free (cmt);
}
}
git_revwalk_free (revwalk);
} while (0);
git_repository_free (rp);
return 0;
}
int
fill_table_cb_ins (void *dptr, time_t t)
{
PyList_Append ( (PyObject*)dptr,
PyLong_FromUnsignedLong(t));
return 0;
}
int
main(int argsc, char **args)
{
Py_InitializeEx (0);
git_libgit2_init ();
PyConfig conf;
PyConfig_InitPythonConfig (&conf);
PyConfig_SetBytesArgv (&conf, argsc, args);
PyObject* obj=PyList_New(0);
calculate_commits (args[2], fill_table_cb_ins, obj);
Py_XINCREF (obj);
PySys_SetObject ("history", obj);
FILE *fp=fopen (args[1], "r");
if (fp)
{
PyRun_AnyFile (fp, args[1]);
fclose (fp);
}
git_libgit2_shutdown ();
Py_Finalize ();
return 0;
}