parrot-libgit2 report

Saurabh Kumar saurabhgeek92 at
Sat Sep 7 13:36:42 UTC 2013

Now that a minimal API is ready, its time that I document how to use it:

Its possible to now use the library to deal with repositories, the
repository index, low-level object access, commits, revision walking,
blobs, git configs and more. Major things that are still not done are
dealing with references and trees, which are only waiting on a few
issues(mentioned below).

These are rough examples of how to use the major classes.

Opening repositories:

using Git2.Repository;
var repo = new Git2.Repository();

Dealing with the index:

var git_index = new Git2.Index();
int ecount = git_index.get_entrycount();
print("Index entry count" + ecount + "\n");;

Dealing with objects(specifically commits):

using Git2.Commit
using Git2.Repository;
using Git2.Oid;

var repo = new Git2.Repository();

var hex = "e1380b1f60babf677921c4a9b5e92acda0b15e18";
var git_oid = new Git2.Oid();

var commit1 = new Git2.Commit();
commit1.commit_lookup(repo, git_oid);

int ctime = commit1.commit_time();
int parentcount = commit1.parentcount();

Dealing with git configuration:

using Git2.Config;
var config = new Git2.Config;
int cfg_val = config.get_int32("help.autocorrect");

Revision walking:
Its possible to walk through the DAG(Directed Acyclic Graph) created
by parent commits.
I'll point you here to the README[1] for this and other code and examples.

For many problems that I was facing, I have managed to get around by
using UnManaged structs and some C wrapper code, which is not very
elegant. e.g it breaks error propagation. I have not yet figured out
how to get data out of a UnManaged struct using winxed or how to
convert a C string into a Parrot String in winxed. There are many API
functions that are waiting on this very issue. Once this is dealt
with, I'll align the current API very closely with pygit2, and add
more documentation. Till then the source[3] is very easy to read.

Till now, only I have been dealing with my code, so please point out
any setup issues that you have.

More information about the parrot-dev mailing list