Permalink
Browse files

Added contributors, moved lib to _old, worked on more oid methods

  • Loading branch information...
1 parent 0a0896b commit fbdd09210eb32de54cdd65c691468364016974ca @tbranyen tbranyen committed Feb 19, 2011
View
@@ -1 +0,0 @@
-Tim Branyen
View
@@ -0,0 +1,13 @@
+nodegit2 contributors (sorted alphabeticaly)
+============================================
+
+* **[Tim Branyen](https://github.com/tbranyen)**
+
+ * Project creation
+ * Native code development
+ * Testing
+
+* **[Timothy J Fontaine](https://github.com/tjfontaine)**
+
+ * Created influencial base project
+ * Provided numerous tips and suggestions
View
@@ -1,3 +1,5 @@
+Copyright (c) 2011 Tim Branyen
+
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2,
as published by the Free Software Foundation.
View
@@ -8,7 +8,7 @@ all:
node-waf configure build
unittest:
- $(NODEJS) ./test/index.js test
+ $(NODEJS) $(BASE)/test/index.js test
clean:
rm -rf ./build
@@ -0,0 +1,5 @@
+var git = require('../lib');
+
+git.repo( '.git', function( err, path ) {
+ console.log( err, path );
+});
@@ -5,3 +5,6 @@ var oid = new git2.Oid();
console.log( oid.mkstr('1810DFF58D8A660512D4832E740F692884338CCD') );
// Invalid
console.log( oid.mkstr('1838CCD') );
+
+// Test formatting
+console.log( oid.fmt() );
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,3 @@
+exports.Repo = require('./repo').Repo
+exports.Commit = require('./commit').Commit
+exports.RevWalk = require('./revwalk').RevWalk
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,81 @@
+var FFI = require('node-ffi');
+var libgit2 = new FFI.Library('libgit2', {
+ 'git_repository_open' : ['int32', ['pointer', 'string']],
+ 'git_repository_lookup' : ['int32', ['pointer', 'pointer', 'pointer', 'int32']],
+ 'git_repository_database' : ['pointer', ['pointer']],
+ 'git_repository_index' : ['pointer', ['pointer']],
+ 'git_repository_newobject': ['int32', ['pointer', 'pointer', 'int32']],
+ 'git_repository_free' : ['void', ['pointer']],
+ 'git_repository_init' : ['int32', ['pointer', 'string', 'uchar']],
+ 'git_repository_lookup_ref' : ['int32', ['pointer', 'pointer', 'string']],
+});
+var fs = require('fs');
+var path = require('path');
+
+var Oid = require('./oid').Oid;
+var Commit = require('./commit').Commit;
+var RevWalk = require('./revwalk').RevWalk;
+var Ref = require('./refs').Ref;
+
+var git_raise_error = require('./error').git_raise_error;
+
+var Repo = exports.Repo = function(repo_path) {
+ var _repo_path = repo_path
+ var _repo_tmp = new FFI.Pointer(FFI.Bindings.POINTER_SIZE);
+
+ var ret = libgit2.git_repository_open(_repo_tmp, _repo_path)
+
+ git_raise_error(ret);
+
+ var _repo = _repo_tmp.getPointer();
+
+ Object.defineProperty(this, "crepo", { get: function() { return _repo; }, enumerable: true});
+ Object.defineProperty(this, "path", { get: function() { return _repo_path; }, enumerable: true});;
+}
+
+Repo.prototype.close = function() {
+ libgit2.git_repository_free(this.crepo);
+}
+
+Repo.prototype.refs = function(arg, callback) {
+ var _ref = new FFI.Pointer(FFI.Bindings.POINTER_SIZE)
+ var ret = libgit2.git_repository_lookup_ref(_ref, this.crepo, arg)
+ git_raise_error(ret)
+ callback(new Ref(_ref.getPointer()));
+}
+
+Repo.prototype.lookup = function(arg) {
+ var oid = null;
+ if(arg instanceof String || typeof arg == "string") {
+ oid = new Oid(arg);
+ var tmp = oid.toString()
+ if(arg != tmp) {
+ throw("OID Failed roundtrip: "+ arg +" != "+tmp)
+ }
+ } else if (arg instanceof Oid) {
+ oid = arg;
+ } else if (arg instanceof Ref) {
+ oid = arg.oid;
+ } else {
+ console.log('not a string: ', typeof arg, arg)
+ }
+
+ var _commit = new FFI.Pointer(FFI.Bindings.POINTER_SIZE);
+ var ret = libgit2.git_repository_lookup(_commit,
+ this.crepo, oid.coid, Oid.GIT_OBJ_COMMIT);
+ git_raise_error(ret);
+ return new Commit(_commit.getPointer());
+}
+
+Repo.prototype.walk = function(head, callback) {
+ var revwalk = new RevWalk(this)
+ var head_commit = this.lookup(head)
+ revwalk.sorting(RevWalk.SORT_TOPOLOGICAL)
+ revwalk.push(head_commit)
+ var commit = revwalk.next()
+ while(commit) {
+ callback(commit);
+ commit = revwalk.next()
+ }
+ revwalk.close()
+}
File renamed without changes.
File renamed without changes.
View
@@ -1,3 +1,4 @@
-exports.Repo = require('./repo').Repo
-exports.Commit = require('./commit').Commit
-exports.RevWalk = require('./revwalk').RevWalk
+var repo = require('./repo.js');
+
+exports.git2 = require('../build/default/git2');
+exports.repo = repo.repo;
View
@@ -1,81 +1,30 @@
-var FFI = require('node-ffi');
-var libgit2 = new FFI.Library('libgit2', {
- 'git_repository_open' : ['int32', ['pointer', 'string']],
- 'git_repository_lookup' : ['int32', ['pointer', 'pointer', 'pointer', 'int32']],
- 'git_repository_database' : ['pointer', ['pointer']],
- 'git_repository_index' : ['pointer', ['pointer']],
- 'git_repository_newobject': ['int32', ['pointer', 'pointer', 'int32']],
- 'git_repository_free' : ['void', ['pointer']],
- 'git_repository_init' : ['int32', ['pointer', 'string', 'uchar']],
- 'git_repository_lookup_ref' : ['int32', ['pointer', 'pointer', 'string']],
-});
-var fs = require('fs');
-var path = require('path');
+var git2 = require('../build/default/git2');
-var Oid = require('./oid').Oid;
-var Commit = require('./commit').Commit;
-var RevWalk = require('./revwalk').RevWalk;
-var Ref = require('./refs').Ref;
+var Repo = function( path, callback ) {
+ var self = {};
-var git_raise_error = require('./error').git_raise_error;
+ // Properties
+ self.repo = new git2.Repo();
-var Repo = exports.Repo = function(repo_path) {
- var _repo_path = repo_path
- var _repo_tmp = new FFI.Pointer(FFI.Bindings.POINTER_SIZE);
+ self.init = function( path, is_bare, callback ) {
+ self.repo.init( path, is_bare, function() {
+ callback && callback.apply( self, arguments );
+ });
+ };
- var ret = libgit2.git_repository_open(_repo_tmp, _repo_path)
+ self.free = function() { };
- git_raise_error(ret);
-
- var _repo = _repo_tmp.getPointer();
-
- Object.defineProperty(this, "crepo", { get: function() { return _repo; }, enumerable: true});
- Object.defineProperty(this, "path", { get: function() { return _repo_path; }, enumerable: true});;
-}
-
-Repo.prototype.close = function() {
- libgit2.git_repository_free(this.crepo);
-}
-
-Repo.prototype.refs = function(arg, callback) {
- var _ref = new FFI.Pointer(FFI.Bindings.POINTER_SIZE)
- var ret = libgit2.git_repository_lookup_ref(_ref, this.crepo, arg)
- git_raise_error(ret)
- callback(new Ref(_ref.getPointer()));
-}
-
-Repo.prototype.lookup = function(arg) {
- var oid = null;
- if(arg instanceof String || typeof arg == "string") {
- oid = new Oid(arg);
- var tmp = oid.toString()
- if(arg != tmp) {
- throw("OID Failed roundtrip: "+ arg +" != "+tmp)
- }
- } else if (arg instanceof Oid) {
- oid = arg;
- } else if (arg instanceof Ref) {
- oid = arg.oid;
- } else {
- console.log('not a string: ', typeof arg, arg)
+ // Constructor use
+ if( path && callback ) {
+ self.repo.open( path, function() {
+ callback && callback.apply( self, arguments );
+ });
}
-
- var _commit = new FFI.Pointer(FFI.Bindings.POINTER_SIZE);
- var ret = libgit2.git_repository_lookup(_commit,
- this.crepo, oid.coid, Oid.GIT_OBJ_COMMIT);
- git_raise_error(ret);
- return new Commit(_commit.getPointer());
-}
-
-Repo.prototype.walk = function(head, callback) {
- var revwalk = new RevWalk(this)
- var head_commit = this.lookup(head)
- revwalk.sorting(RevWalk.SORT_TOPOLOGICAL)
- revwalk.push(head_commit)
- var commit = revwalk.next()
- while(commit) {
- callback(commit);
- commit = revwalk.next()
+ else if( path ) {
+ self.repo.open( path );
}
- revwalk.close()
-}
+
+ return self;
+};
+
+exports.repo = Repo;
View
@@ -21,6 +21,8 @@ void Oid::Initialize(Handle<Object> target) {
constructor_template->SetClassName(String::NewSymbol("Oid"));
NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkstr", Mkstr);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkraw", Mkraw);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "fmt", Fmt);
target->Set(String::NewSymbol("Oid"), constructor_template->GetFunction());
}
@@ -29,6 +31,16 @@ int Oid::Mkstr(const char* id) {
return git_oid_mkstr(&this->oid, id);
}
+void Oid::Mkraw(const unsigned char *raw) {
+ git_oid_mkraw(&this->oid, raw);
+}
+
+char* Oid::Fmt() {
+ char* raw;
+ git_oid_fmt(raw, &this->oid);
+ return raw;
+}
+
Handle<Value> Oid::New(const Arguments& args) {
HandleScope scope;
@@ -52,4 +64,26 @@ Handle<Value> Oid::Mkstr(const Arguments& args) {
return Local<Value>::New( Integer::New(oid->Mkstr(*id)) );
}
+Handle<Value> Oid::Mkraw(const Arguments& args) {
+ Oid *oid = ObjectWrap::Unwrap<Oid>(args.This());
+
+ HandleScope scope;
+
+ if(args.Length() == 0 || !args[0]->IsString()) {
+ return ThrowException(Exception::Error(String::New("Raw object id is required.")));
+ }
+
+ String::Utf8Value raw(Local<Value>::New(args[0]));
+ oid->Mkraw((const unsigned char*)*raw);
+ return Local<Value>::New(args.This());
+}
+
+Handle<Value> Oid::Fmt(const Arguments& args) {
+ Oid *oid = ObjectWrap::Unwrap<Oid>(args.This());
+
+ HandleScope scope;
+
+ return String::New(oid->Fmt());
+}
+
Persistent<FunctionTemplate> Oid::constructor_template;
View
@@ -19,8 +19,8 @@ class Oid : public EventEmitter {
static Persistent<FunctionTemplate> constructor_template;
static void Initialize (Handle<v8::Object> target);
int Mkstr(const char *str);
- //void mkraw(git_oid *out, const unsigned char *raw)
- //void fmt(char *str, const git_oid *oid)
+ void Mkraw(const unsigned char *raw);
+ char* Fmt();
//void pathfmt(char *str, const git_oid *oid)
//char* allocfmt(const git_oid *oid)
//char* to_string(char *out, size_t n, const git_oid *oid)
@@ -32,6 +32,8 @@ class Oid : public EventEmitter {
~Oid() {}
static Handle<Value> New(const Arguments& args);
static Handle<Value> Mkstr(const Arguments& args);
+ static Handle<Value> Mkraw(const Arguments& args);
+ static Handle<Value> Fmt(const Arguments& args);
private:
git_oid oid;
View
@@ -141,7 +141,7 @@ Handle<Value> Repo::Init(const Arguments& args) {
}
if(args.Length() == 1 || !args[1]->IsBoolean()) {
- return ThrowException(Exception::Error(String::New("is_bare is required and must be a String.")));
+ return ThrowException(Exception::Error(String::New("is_bare is required and must be a Boolean.")));
}
if(args.Length() == 2 || !args[2]->IsFunction()) {
@@ -186,7 +186,6 @@ int Repo::EIO_AfterInit(eio_req *req) {
argv[1] = String::Cast(*ar->path);
argv[2] = *ar->is_bare;
-
TryCatch try_catch;
ar->callback->Call(Context::GetCurrent()->Global(), 3, argv);
Oops, something went wrong.

0 comments on commit fbdd092

Please sign in to comment.