Commit fbdd0921 authored by Tim Branyen's avatar Tim Branyen

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

parent 0a0896b3
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
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.
......
......@@ -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
......
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() );
exports.Repo = require('./repo').Repo
exports.Commit = require('./commit').Commit
exports.RevWalk = require('./revwalk').RevWalk
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()
}
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;
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;
......@@ -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;
......@@ -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;
......
......@@ -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);
......
var git = require( '../lib' ),
rimraf = require( '../vendor/rimraf'),
fs = require( 'fs' );
// Helper functions
var helper = {
// Test if obj is a true function
testFunction: function( test, obj, label ) {
// The object reports itself as a function
test( typeof obj, 'function', label +' reports as a function.' );
// This ensures the repo is actually a derivative of the Function [[Class]]
test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' );
},
// Test code and handle exception thrown
testException: function( test, fun, label ) {
try {
fun();
test( false, label );
}
catch (ex) {
test( true, label );
}
}
};
// Repo
exports.constructor = function( test ){
test.expect( 6 );
// Test for function
helper.testFunction( test.equals, git.repo, 'Repo' );
// Test callback argument existence
helper.testException( test.ok, function() {
git.repo( 'some/path' );
}, 'Throw an exception if no callback' );
// Test invalid repository
git.repo( '/etc/hosts', function( err, path ) {
test.equals( -8, err, 'Invalid repository error code' );
// Test valid repository
git.repo( './.git', function( err, path ) {
test.equals( 0, err, 'Valid repository error code' );
// Test path returned is correct
test.equals( './.git', path, 'Path return matches sent' );
test.done();
});
});
};
// Repo::Init
exports.init = function( test ) {
test.expect( 7 );
// Test for function
helper.testFunction( test.equals, git.repo().init, 'Repo::Init' );
// Test path argument existence
helper.testException( test.ok, function() {
git.repo().init();
}, 'Throw an exception if no path' );
// Test is_bare argument existence
helper.testException( test.ok, function() {
git.repo().init( 'some/path' );
}, 'Throw an exception if no is_bare' );
// Cleanup, remove test repo directory - if it exists
rimraf( './test.git', function() {
// Create bare repo and test for creation
git.repo().init( './test.git', true, function( err, path, is_bare ) {
test.equals( 0, err, 'Successfully created bare repository' );
// Verify repo exists
git.repo('./test.git', function(err, path) {
test.equals( 0, err, 'Valid repository created' );
test.equals( true, is_bare, 'Returns valid is_bare value' );
// Cleanup, remove test repo directory
rimraf( './test.git', function() {
test.done();
});
});
});
});
};
......@@ -10,8 +10,8 @@ catch(e) {
sys.puts( 'Cannot find nodeunit module.' );
sys.puts( 'You can download submodules for this project by doing:' );
sys.puts( '' );
sys.puts( ' git submodule init' );
sys.puts( ' git submodule update' );
sys.puts( ' git submodule init vendor/nodeunit' );
sys.puts( ' git submodule update vendor/nodeunit' );
sys.puts( '' );
process.exit();
}
......@@ -24,8 +24,8 @@ catch(e) {
sys.puts( 'Cannot find rimraf module.' );
sys.puts( 'You can download submodules for this project by doing:' );
sys.puts( '' );
sys.puts( ' git submodule init' );
sys.puts( ' git submodule update' );
sys.puts( ' git submodule init vendor/rimraf' );
sys.puts( ' git submodule update vendor/rimraf' );
sys.puts( '' );
process.exit();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment