-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrapper.cpp
More file actions
127 lines (109 loc) · 2.52 KB
/
wrapper.cpp
File metadata and controls
127 lines (109 loc) · 2.52 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include "wrapper.h"
using namespace std;
/**
* Initialize libgit2
*/
wrapper::wrapper()
{
git_libgit2_init();
}
/**
* Open a repository at a certain directory
*/
git_repository* openRepository(const char* directory)
{
git_repository* repository;
if(git_repository_open(&repository, directory) == 0) return repository;
return NULL;
}
/**
* Get the total number of commits in the repository
*/
int wrapper::getCommitCount(git_repository *repository)
{
//Repository does not exist; commit count is 0
if(repository == NULL)
{
return 0;
}
//Walker for traversal
git_revwalk *walker;
git_revwalk_new(&walker, repository);
git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL | GIT_SORT_TIME);
git_revwalk_push_head(walker);
int i = 0;
git_oid oid;
//Iterate through the commits
while(git_revwalk_next(&oid, walker) == 0)
{
git_commit *c;
git_commit_lookup(&c, repository, &oid);
i++;
git_commit_free(c);
}
//Free the repository, return the value
git_repository_free(repository);
return i;
}
/**
* Get the total number of commits in the repository,
* given an author/email
*/
int wrapper::getCommitCount(git_repository *repository, const char* id)
{
//Repository does not exist; commit count is 0
if(!repository)
{
return 0;
}
//Walker for traversal
git_revwalk *walker;
git_revwalk_new(&walker, repository);
git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL | GIT_SORT_TIME);
git_revwalk_push_head(walker);
int i = 0;
git_oid oid;
//Iterate through the commits
while(git_revwalk_next(&oid, walker) == 0)
{
git_commit *c;
git_commit_lookup(&c, repository, &oid);
const git_signature *sig = git_commit_author(c);
char *name = sig -> name;
char *email = sig -> email;
if(name == id || email == id) i++;
git_commit_free(c);
}
//Free the repository, return the value
git_repository_free(repository);
return i;
}
/**
* Get the total number of lines committed to the repository
*/
int wrapper::getLinesCommitted(git_repository *repository)
{
return 0;
}
/**
* Get the total number of lines committed to the repository,
* given an author/email
*/
int wrapper::getLinesCommitted(git_repository *repository, const char* id)
{
return 0;
}
/**
* Main file purely used to compile the code
*/
int main()
{
const char *directory = "/home/bpearson/csci221/final-project/gitrekt";
wrapper *w = new wrapper();
const char* author = "bpearson";
git_repository* repo = w->openRepository(directory);
cout << w->getCommitCount(repo, author);
delete w;
return 0;
}