Skip to content

Commit

Permalink
Merge branch 'index'
Browse files Browse the repository at this point in the history
Conflicts:
	binding.gyp
	coffee/gitteh.coffee
	src/gitteh.cc
	src/repository.cc
  • Loading branch information
Sam Day committed Jun 2, 2012
2 parents 121fa7e + 451bf4d commit b92b820
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion binding.gyp
Expand Up @@ -12,9 +12,9 @@
'src/blob.cc',
'src/tag.cc',
'src/remote.cc',
'src/index.cc',
],
'todosources': [
'src/index.cc',
'src/index_entry.cc',
'src/tag.cc',
'src/rev_walker.cc',
Expand Down
16 changes: 15 additions & 1 deletion coffee/gitteh.coffee
Expand Up @@ -23,6 +23,17 @@ remoteDirs = ["push", "fetch"]
args.validators.remoteDir = (val) ->
return remoteDirs.indexOf val > -1

checkOid = (str, allowLookup = true) ->
throw new TypeError "OID should be a string" if typeof str isnt "string"
throw new TypeError "Invalid OID" if not oidRegex.test str
throw new Error "OID is too short" if str.length < Gitteh.minOidLength
throw new TypeError "Invalid OID" if not allowLookup and str.length isnt 40

wrapCallback = (orig, cb) ->
return (err) ->
return orig err if err?
cb.apply null, Array.prototype.slice.call arguments, 1

immutable = (obj, src) ->
return o = {
set: (name, target = name) ->
Expand Down Expand Up @@ -119,6 +130,7 @@ Gitteh.Tag = Tag = (@repository, obj) ->
@repository.object @targetId, @type, cb
return @

<<<<<<< HEAD
Gitteh.Remote = Remote = (@repository, nativeRemote) ->
if nativeRemote not instanceof NativeRemote
throw new Error "Don't construct me, see Repository.remote()"
Expand Down Expand Up @@ -186,7 +198,9 @@ wrapCallback = (orig, cb) ->
return orig err if err?
cb.apply null, Array.prototype.slice.call arguments, 1

module.exports.Repository = Repository = (nativeRepo) ->
Gitteh.Index = Index = (nativeIndex) ->

Gitteh.Repository = Repository = (nativeRepo) ->
if nativeRepo not instanceof NativeRepository
throw new Error "Don't construct me, see gitteh.(open|init)Repository"

Expand Down
7 changes: 5 additions & 2 deletions src/gitteh.cc
Expand Up @@ -30,6 +30,7 @@
#include "blob.h"
#include "tag.h"
#include "remote.h"
#include "index.h"

namespace gitteh {

Expand Down Expand Up @@ -59,15 +60,17 @@ init(Handle<Object> target) {
Tree::Init(target);
Blob::Init(target);
Tag::Init(target);
Index::Init(target);

Remote::Init(target);

ImmutableSet(target, String::NewSymbol("minOidLength"), Integer::New(GIT_OID_MINPREFIXLEN));
ImmutableSet(target, String::NewSymbol("types"), CreateTypeObject());

NODE_DEFINE_CONSTANT(target, GIT_DIR_PUSH);
NODE_DEFINE_CONSTANT(target, GIT_DIR_FETCH);
/*Index::Init(target);

/*
IndexEntry::Init(target);
RevWalker::Init(target);
Expand Down
40 changes: 40 additions & 0 deletions src/index.cc
@@ -0,0 +1,40 @@
#include "index.h"

namespace gitteh {
static Persistent<String> class_symbol;

Persistent<FunctionTemplate> Index::constructor_template;

Index::Index(git_index *index) : index_(index) {

}

Index::~Index() {

}

void Index::Init(Handle<Object> module) {
HandleScope scope;

class_symbol = NODE_PSYMBOL("NativeIndex");

Local<FunctionTemplate> t = FunctionTemplate::New(New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->SetClassName(class_symbol);
t->InstanceTemplate()->SetInternalFieldCount(1);

module->Set(class_symbol, constructor_template->GetFunction());
}

Handle<Value> Index::New(const Arguments &args) {
HandleScope scope;
REQ_EXT_ARG(0, indexArg);
Handle<Object> me = args.This();

git_index *rawIndex = static_cast<git_index*>(indexArg->Value());
Index *index = new Index(rawIndex);
index->Wrap(me);

return scope.Close(me);
}
}; // namespace gitteh
25 changes: 25 additions & 0 deletions src/index.h
@@ -0,0 +1,25 @@
#ifndef GITTEH_INDEX_H
#define GITTEH_INDEX_H

#include "gitteh.h"

namespace gitteh {
class IndexBaton;
class Index : public ObjectWrap {
public:
static Persistent<FunctionTemplate> constructor_template;

friend class IndexBaton;

Index(git_index*);
~Index();
static void Init(Handle<Object>);
protected:
static Handle<Value> New(const Arguments&);
private:
git_index *index_;
};

} // namespace gitteh

#endif // GITTEH_INDEX_H
16 changes: 16 additions & 0 deletions src/repository.cc
Expand Up @@ -28,13 +28,15 @@
#include "blob.h"
#include "tag.h"
#include "remote.h"
#include "index.h"

using std::list;

namespace gitteh {
static Persistent<String> repo_class_symbol;
static Persistent<String> path_symbol;
static Persistent<String> bare_symbol;
static Persistent<String> index_symbol;

static Persistent<String> object_dir_symbol;
static Persistent<String> index_file_symbol;
Expand Down Expand Up @@ -163,6 +165,7 @@ void Repository::Init(Handle<Object> target) {
index_file_symbol = NODE_PSYMBOL("indexFile");
work_dir_symbol = NODE_PSYMBOL("workDir");
remotes_symbol = NODE_PSYMBOL("remotes");
index_symbol = NODE_PSYMBOL("index");
references_symbol = NODE_PSYMBOL("references");

// Reference symbols
Expand Down Expand Up @@ -202,15 +205,20 @@ Handle<Value> Repository::New(const Arguments& args) {

git_repository *repo = static_cast<git_repository*>(repoArg->Value());
git_odb *odb;
git_index *index;
if(git_repository_odb(&odb, repo) != GIT_OK) {
return scope.Close(ThrowGitError());
}
if(git_repository_index(&index, repo) != GIT_OK) {
return scope.Close(ThrowGitError());
}

// Initialize our wrapped Repository class, which will then be wrapped in JS
Repository *repoObj = new Repository();
repoObj->Wrap(me);
repoObj->repo_ = repo;
repoObj->odb_ = odb;
repoObj->index_ = index;

bool bare = git_repository_is_bare(repo);
ImmutableSet(me, path_symbol, CastToJS(git_repository_path(repo)));
Expand All @@ -234,6 +242,14 @@ Handle<Value> Repository::New(const Arguments& args) {
me->Set(references_symbol, Array::New());
}

Handle<Value> constructorArgs[] = {
External::New(index)
};
Local<Object> indexObj = Index::constructor_template->GetFunction()
->NewInstance(1, constructorArgs);

me->Set(index_symbol, indexObj);

return args.This();
}

Expand Down
1 change: 1 addition & 0 deletions src/repository.h
Expand Up @@ -26,6 +26,7 @@ class Repository : public ObjectWrap {

git_repository *repo_;
git_odb *odb_;
git_index *index_;

protected:
static Handle<Value> OpenRepository(const Arguments&);
Expand Down

0 comments on commit b92b820

Please sign in to comment.