Permalink
Browse files

Add basic rev-parsing

Finds an object by parsing revision string;
  • Loading branch information...
1 parent 9e39a10 commit 0b9222613fe83e1111dbcd48952b20a5a9dcf176 @sa1 sa1 committed Sep 7, 2013
Showing with 51 additions and 3 deletions.
  1. +1 −0 setup.winxed
  2. +15 −0 src/Git2/RevParse.winxed
  3. +20 −2 src/parrotgit.c
  4. +2 −1 src/parrotgit.nci
  5. +2 −0 src/parrotgit.pir
  6. +11 −0 t/winxed/001_load.t
View
@@ -55,6 +55,7 @@ function setup_stable_libraries(var parrot_libgit2) {
'AttrCache',
'Repository',
'Remote',
+ 'RevParse',
'RevWalk'
];
View
@@ -0,0 +1,15 @@
+$include_const 'datatypes.pasm';
+$include_const "iglobals.pasm";
+
+namespace Git2{
+ class Common;
+}
+
+namespace Git2{
+ function rev_parse_single(repo, spec){
+ //TODO: depends on revparse_single to deal with errors
+ using Git2.Git.revparse_single;
+ var object = revparse_single(repo.ptr, cstring(spec));
+ return object;
+ }
+}
View
@@ -112,10 +112,28 @@ git_remote * remote_create(git_repository *repo, char *name, char * url){
fprintf(stderr, "Invalid spec\n");
}
else if (ret == GIT_EEXISTS){
- fprintf(stderr, "Remote Exists");
+ fprintf(stderr, "Remote Exists.\n");
}
else if (ret < 0){
- fprintf(stderr, "Error creating remote");
+ fprintf(stderr, "Error creating remote.\n");
}
return remote;
}
+
+git_object * revparse_single(git_repository * repo, char * spec){
+ git_object * object;
+ int ret = git_revparse_single(&object, repo, spec);
+ if (ret == GIT_ENOTFOUND){
+ fprintf(stderr, "Not found.\n");
+ }
+ else if(ret == GIT_EAMBIGUOUS){
+ fprintf(stderr, "Ambiguous.\n");
+ }
+ else if(ret == GIT_EINVALIDSPEC){
+ fprintf(stderr, "Invalid Spec.\n");
+ }
+ else if(ret < 0){
+ fprintf(stderr, "Error finding object.\n");
+ }
+ return object;
+}
View
@@ -18,4 +18,5 @@ p commit_lookup pp
p parent pi
p new_revwalk p
p blob_lookup pp
-p remote_create ppp
+p remote_create ppp
+p revparse_single pp
View
@@ -27,4 +27,6 @@
set_global ['Git2';'Git'], 'blob_lookup', nci
dlfunc nci, lib, 'remote_create', 'pppp'
set_global ['Git2';'Git'], 'remote_create', nci
+ dlfunc nci, lib, 'revparse_single', 'ppp'
+ set_global ['Git2';'Git'], 'revparse_single', nci
.end
View
@@ -15,6 +15,7 @@ $load "./src/Git2/Odb.pbc";
$load "./src/Git2/AttrCache.pbc";
$load "./src/Git2/Blob.pbc";
$load "./src/Git2/Remote.pbc";
+$load "./src/Git2/RevParse.pbc";
$load "dumper.pbc";
$include_const 'datatypes.pasm';
@@ -223,6 +224,16 @@ class Test_git2_repository_open {
repo.free();
}
+ function rev_parse(){
+ using Git2.RevParse.rev_parse_single;
+
+ var repo = new Git2.Repository(".");
+ var spec = "HEAD^";
+
+ var obj = Git2.rev_parse_single(repo, spec);
+ self.assert.defined(obj);
+ }
+
function remote(){
using Git2.Remote;
using Git2.Repository;

0 comments on commit 0b92226

Please sign in to comment.