parrot-libgit2 report

Saurabh Kumar saurabhgeek92 at gmail.com
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();
repo.init_repo("/path/to/repository");
...
repo.free();

Dealing with the index:

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

Dealing with objects(specifically commits):

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

var repo = new Git2.Repository();
repo.init_repo(".");

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

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

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

repo.free()

Dealing with git configuration:

using Git2.Config;
var config = new Git2.Config;
config.get_config("path/to/repo/config");
int cfg_val = config.get_int32("help.autocorrect");
print(cfg_val);

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.
[1]: https://github.com/letolabs/parrot-libgit2/blob/master/README.md
[2]: https://github.com/letolabs/parrot-libgit2/blob/master/src/parrotgit.c
[3]: https://github.com/letolabs/parrot-libgit2/tree/master/src/Git2


More information about the parrot-dev mailing list