Permalink
Browse files

API updates

  • Loading branch information...
1 parent 9ce0596 commit bc6b3dac8776ab270d28e311a0a95e64750ecbd0 @sa1 sa1 committed Sep 7, 2013
Showing with 238 additions and 60 deletions.
  1. +16 −11 README.md
  2. +4 −0 src/Git2/Blob.winxed
  3. +52 −4 src/Git2/Commit.winxed
  4. +74 −2 src/Git2/Repository.winxed
  5. +36 −17 src/parrotgit.c
  6. +2 −0 src/parrotgit.nci
  7. +4 −0 src/parrotgit.pir
  8. +50 −26 t/winxed/001_load.t
View
@@ -82,19 +82,24 @@ NCI defs are automatically generated during setup.
Opening a repository:
using Git2.Repository;
- var repo = new Git2.Repository();
- repo.init_repo("/path/to/repository");
+ var repo = new Git2.Repository("/path/to/repository");
+ ...
+ repo.free();
+
+Creating a repository:
+ using Git2.Repository;
+ var repo = new Git2.Repository;
+ repo.init("/path/to/repository");
repo.free();
Using the index:
using Git2.Repository;
using Git2.Index;
- var repo = new Git2.Repository();
+ var repo = new Git2.Repository("/path/to/repository");
var git_index = new Git2.Index();
- repo.init("/path/to/repository");
git_index.set_index(repo.ptr);
int ecount = git_index.get_entrycount();
@@ -128,8 +133,7 @@ Getting Commit Data:
using Git2.Repository;
using Git2.Oid;
- var repo = new Git2.Repository();
- repo.init_repo(".");
+ var repo = new Git2.Repository(".");
var hex = "e1380b1f60babf677921c4a9b5e92acda0b15e18";
var git_oid = new Git2.Oid();
@@ -141,6 +145,7 @@ Getting Commit Data:
int ctime = commit1.commit_time();
int parentcount = commit1.parentcount();
+ commit1.free();
repo.free()
Revision Walking:
@@ -151,9 +156,8 @@ You can traverse the DAG(Directed Acyclic Graph) created by the parent pointers.
using Git2.Oid;
using Git2.Commit;
- var repo = new Git2.Repository();
- repo.init_repo(".");
-
+ var repo = new Git2.Repository(".");
+
var hex = "e1380b1f60babf677921c4a9b5e92acda0b15e18";
var git_oid = new Git2.Oid();
git_oid.oid_from_str(hex);
@@ -167,6 +171,7 @@ You can traverse the DAG(Directed Acyclic Graph) created by the parent pointers.
commit1.commit_lookup(repo, rev_walk.oid);
int parentcount = commit1.parentcount();
print(parentcount + " ");
+ commit1.free();
}
rev_walk.free();
repo.free();
@@ -177,8 +182,7 @@ Blobs:
using Git2.Oid;
using Git2.Blob;
- var repo = new Git2.Repository();
- repo.init_repo(".");
+ var repo = new Git2.Repository(".");
var hex = "a556bfd051e6cd09844eda9ccb372f37629f5385";
var git_oid = new Git2.Oid();
@@ -189,6 +193,7 @@ Blobs:
var size = blob.raw_size();
print(size);
+ blob.free();
repo.free();
## Contributing
View
@@ -20,5 +20,9 @@ namespace Git2 {
int rawsize = git_blob_rawsize(self.ptr);
return rawsize;
}
+ function free(){
+ using Git2.Raw.git_blob_free;
+ git_blob_free(self.ptr);
+ }
}
}
View
@@ -2,15 +2,31 @@ $include_const 'datatypes.pasm';
$include_const "iglobals.pasm";
namespace Git2 {
+ class Oid;
+}
+
+namespace Git2 {
class Commit {
var ptr;
function Commit() {
}
+ function Commit(repo, hex){
+ using Git2.Oid;
+ using Git2.Git.commit_lookup;
+ var git_oid = new Git2.Oid();
+ git_oid.oid_from_str(hex);
+ self.ptr = commit_lookup(repo.ptr, git_oid.ptr);
+ }
+ /*
+ * Look up commit by oid
+ */
function commit_lookup(repo, oid){
- using Git2.Git.commit_lookup;
-
+ using Git2.Git.commit_lookup;
self.ptr = commit_lookup(repo.ptr, oid.ptr);
}
+ /*
+ * return commit_time
+ */
function commit_time(){
using Git2.Raw.git_commit_time;
int ctime = git_commit_time(self.ptr);
@@ -22,28 +38,60 @@ namespace Git2 {
var message = git_commit_message(self.ptr);
return message;
}
+ /*
+ * Return author of commit
+ */
function author(){
using Git2.Raw.git_commit_author;
var author = git_commit_author(self.ptr);
return author;
}
+ /*
+ * Return commiter of commit
+ */
function commiter(){
using Git2.Raw.git_commit_committer;
var commiter = git_commit_committer(self.ptr);
- return commiter;
+ return commiter;
}
+ /*
+ * Return number of parents of commit
+ */
function parentcount(){
using Git2.Raw.git_commit_parentcount;
int parentcount = git_commit_parentcount(self.ptr);
return parentcount;
}
+ /*
+ * Return pth parent of commit
+ */
function parent(p){
using Git2.Raw.git_commit_parent;
- using Git2.Git2.parent;
+ using Git2.Git.parent;
var parent_commit = new Git2.Commit();
var parent_ptr = parent(self.ptr, p);
parent_commit.ptr = parent_ptr;
return parent_commit;
}
+ /*
+ * Returns positive or negative time offset from UTC
+ */
+ function commit_time_offset(){
+ using Git2.Raw.git_commit_time_offset;
+ int offset = git_commit_time_offset(self.ptr);
+ return offset;
+ }
+ /*
+ * Return Commit Message encoding
+ */
+ function encoding(){
+ using Git2.Raw.git_commit_message_encoding;
+ var encoding = git_commit_message_encoding(self.ptr);
+ return encoding;
+ }
+ function free(){
+ using Git2.Raw.git_commit_free;
+ git_commit_free(self.ptr);
+ }
}
}
View
@@ -65,12 +65,49 @@ namespace Git2 {
function Repository() {
self.ptr = self.get_sv().alloc();
}
+ function Repository(x){
+ using Git2.Git.open_repo;
+ self.ptr = open_repo(cstring(x));
+ }
/*
* Initialize repo with path
*/
function init_repo(x) {
- using Git2.Git.open_repo;
- self.ptr = open_repo(cstring(x));
+ using Git2.Raw.git_repository_init;
+ using Git2.Git.init_repository;
+ self.ptr = init_repository(cstring(x));
+ }
+ function init_repo(x, bare) {
+ using Git2.Raw.git_repository_init;
+ using Git2.Git.init_repository2;
+ self.ptr = init_repository2(cstring(x), bare);
+ }
+ function clone(path, url){
+ //TODO
+ }
+ /*
+ * Check if shallow - 1 if shallow, 0 otherwise
+ */
+ function is_shallow() {
+ using Git2.Raw.git_repository_is_shallow;
+ int x = git_repository_is_shallow(self.ptr);
+ return x;
+ }
+ /*
+ * Check if bare - 1 if bare, 0 otherwise
+ */
+ function is_bare() {
+ using Git2.Raw.git_repository_is_bare;
+ int x = git_repository_is_bare(self.ptr);
+ return x;
+ }
+ /*
+ * Check if empty - 1 if empty, 0 if it isn't, error code on corrupt repos
+ */
+ function is_empty() {
+ using Git2.Raw.git_repository_is_empty;
+ int x = git_repository_is_empty(self.ptr);
+ return x;
}
/*
* Free repo
@@ -80,6 +117,41 @@ namespace Git2 {
var bool = git_repository_free(self.ptr);
return bool;
}
+ /*
+ * Get Path.
+ * TODO: convert to parrot string
+ */
+ function path(){
+ using Git2.Raw.git_repository_path;
+ var path = git_repository_path(self.ptr);
+ return path;
+ }
+ /*
+ * Set head - 0 on success, error code otherwise
+ */
+ function set_head(refname){
+ using cstring;
+ using Git2.Raw.git_repository_set_head;
+ using Git2.Raw.git_reference_is_valid_name;
+ int rc = git_reference_is_valid_name(cstring(refname));
+ if (rc == 0) {
+ print("Invalid Reference Name\n");
+ return -1;
+ }
+ rc = git_repository_set_head(self.ptr, cstring(refname));
+ return rc;
+ }
+ /*
+ * 1 if head is detached, 0 if its not, error code otherwise
+ */
+ function is_detached(){
+ using Git2.Raw.git_repository_head_detached;
+ int rc = git_repository_head_detached(self.ptr);
+ return rc;
+ }
+ /*
+ * Get pointer
+ */
function get_pointer(){
return self.ptr;
}
View
@@ -2,15 +2,34 @@
#include <stdio.h>
#include <string.h>
-git_repository * open_repo(char * dir)
-{
- git_repository *repo = NULL;
- int ret;
- ret = git_repository_open_ext(&repo, dir, 0, NULL);
- if (ret < 0){
- fprintf(stderr, "Error opening repository\n");
- }
- return repo;
+git_repository * open_repo(char * dir){
+ git_repository *repo = NULL;
+ int ret;
+ ret = git_repository_open_ext(&repo, dir, 0, NULL);
+ if (ret < 0){
+ fprintf(stderr, "Error opening repository\n");
+ }
+ return repo;
+}
+
+git_repository * init_repository(char * dir){
+ git_repository *repo;
+ int ret;
+ ret = git_repository_init(&repo, dir, 0);
+ if (ret < 0){
+ fprintf(stderr, "Error initializing repository\n");
+ }
+ return repo;
+}
+
+git_repository * init_repository2(char * dir, unsigned bare){
+ git_repository *repo;
+ int ret;
+ ret = git_repository_init(&repo, dir, bare);
+ if (ret < 0){
+ fprintf(stderr, "Error initializing repository\n");
+ }
+ return repo;
}
git_index * repo_index(git_repository * repo){
@@ -35,20 +54,20 @@ git_reference * repo_head(git_repository * repo){
git_config * get_config(char * config_path){
git_config * config;
- int error = 0;
- error = git_config_open_ondisk(&config, config_path);
- if (error < 0){
- fprintf(stderr, "Error getting config file");
+ int ret = 0;
+ ret = git_config_open_ondisk(&config, config_path);
+ if (ret < 0){
+ fprintf(stderr, "Error getting config file\n");
}
return config;
}
git_commit * commit_lookup(git_repository * repo, git_oid * oid){
- int err;
+ int ret;
git_commit * commit;
- err = git_commit_lookup(&commit, repo, oid);
- if (err < 0){
- fprintf(stderr, "Error looking up commit");
+ ret = git_commit_lookup(&commit, repo, oid);
+ if (ret < 0){
+ fprintf(stderr, "Error looking up commit\n");
}
return commit;
}
View
@@ -7,6 +7,8 @@ libparrotgit.so
[defs]
p open_repo p
+p init_repository p
+p init_repository2 pi
p repo_index p
p repo_head p
p branchname p
View
@@ -3,6 +3,10 @@
loadlib lib, 'libparrotgit.so'
dlfunc nci, lib, 'open_repo', 'pp'
set_global ['Git2';'Git'], 'open_repo', nci
+ dlfunc nci, lib, 'init_repository', 'pp'
+ set_global ['Git2';'Git'], 'init_repository', nci
+ dlfunc nci, lib, 'init_repository2', 'ppi'
+ set_global ['Git2';'Git'], 'init_repository2', nci
dlfunc nci, lib, 'repo_index', 'pp'
set_global ['Git2';'Git'], 'repo_index', nci
dlfunc nci, lib, 'repo_head', 'pp'
Oops, something went wrong.

0 comments on commit bc6b3da

Please sign in to comment.