Skip to content

Commit 09c72e6

Browse files
Tim Branyentbranyen
authored andcommitted
Added blobs
1 parent e422b1b commit 09c72e6

File tree

6 files changed

+111
-5
lines changed

6 files changed

+111
-5
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44
[submodule "vendor/rimraf"]
55
path = vendor/rimraf
66
url = git://github.com/isaacs/rimraf.git
7-
[submodule "vendor/libgit2"]
8-
path = vendor/libgit2
9-
url = git://github.com/libgit2/libgit2.git

src/blob.cc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
3+
*/
4+
5+
#include <v8.h>
6+
#include <node.h>
7+
#include <node_events.h>
8+
9+
#include <git2.h>
10+
11+
#include "repo.h"
12+
#include "blob.h"
13+
14+
using namespace v8;
15+
using namespace node;
16+
17+
void Blob::Initialize (Handle<v8::Object> target) {
18+
HandleScope scope;
19+
20+
Local<FunctionTemplate> t = FunctionTemplate::New(New);
21+
22+
constructor_template = Persistent<FunctionTemplate>::New(t);
23+
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
24+
constructor_template->SetClassName(String::NewSymbol("Blob"));
25+
26+
target->Set(String::NewSymbol("Blob"), constructor_template->GetFunction());
27+
}
28+
29+
git_blob* Blob::GetValue() {
30+
return this->blob;
31+
}
32+
33+
void Blob::SetValue(git_blob* blob) {
34+
this->blob = blob;
35+
}
36+
37+
int Blob::New(git_repository* repo) {
38+
return git_blob_new(&this->blob, repo);
39+
}
40+
41+
Handle<Value> Blob::New(const Arguments& args) {
42+
HandleScope scope;
43+
44+
Blob *blob = new Blob();
45+
46+
if(args.Length() == 0 || !args[0]->IsObject()) {
47+
return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
48+
}
49+
50+
Repo *repo = ObjectWrapper::Unwrap<Repo>(args[0]);
51+
int err = blob->New(repo);
52+
53+
blob->Wrap(args.This());
54+
55+
return args.This();
56+
}
57+
Persistent<FunctionTemplate> Blob::constructor_template;

src/blob.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
3+
*/
4+
5+
#ifndef BLOB_H
6+
#define BLOB_H
7+
8+
#include <v8.h>
9+
#include <node.h>
10+
#include <node_events.h>
11+
12+
#include <git2.h>
13+
14+
#include "repo.h"
15+
16+
using namespace v8;
17+
using namespace node;
18+
19+
class Blob : public EventEmitter {
20+
public:
21+
static Persistent<FunctionTemplate> constructor_template;
22+
static void Initialize(Handle<v8::Object> target);
23+
// Synchronous
24+
int New(git_blob **blob, git_repository *repo)
25+
git_blob* GetValue();
26+
void SetValue(git_blob* blob);
27+
28+
protected:
29+
Blob() {};
30+
~Blob() {};
31+
32+
static Handle<Value> New(const Arguments& args);
33+
34+
private:
35+
git_blob *blob;
36+
};
37+
38+
#endif

src/commit.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ git_commit* Commit::GetValue() {
3434
return this->commit;
3535
}
3636

37+
void Commit::SetValue(git_commit* commit) {
38+
this->commit = commit;
39+
}
40+
3741
int Commit::Lookup(Repo *repo, Oid *oid) {
3842
return git_commit_lookup(&this->commit, repo->GetValue(), oid->GetValue());
3943
}

src/commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Commit : public EventEmitter {
2626
int Lookup(Repo *repo, Oid *oid);
2727
// Synchronous
2828
git_commit* GetValue();
29+
void SetValue(git_commit* commit);
2930

3031
protected:
3132
Commit() {}

wscript

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import Options, Utils
22
from os import system
33
from os.path import exists, abspath
44

5+
VERSION = '0.0.1'
6+
APPNAME = 'nodegit2'
7+
srcdir = '.'
8+
blddir = 'build'
9+
510
def set_options(opt):
11+
opt.tool_options('gcc')
612
opt.tool_options('compiler_cxx')
713

814
def configure(conf):
15+
conf.check_tool('gcc')
916
conf.check_tool('compiler_cxx')
1017
conf.check_tool('node_addon')
1118

@@ -19,9 +26,11 @@ def configure(conf):
1926
#Popen('python waf configure build-static', shell=True).wait()
2027

2128
def build(bld):
22-
system('cd vendor/libgit2/; python waf configure build-static')
29+
#libgit2 = bld.new_task_gen('wafadmin')
30+
#libgit2.features = 'waf configure build-static'
31+
#libgit2.target = 'libgit2'
2332

2433
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
2534
obj.target = 'nodegit2'
2635
obj.source = 'src/base.cc src/error.cc src/reference.cc src/repo.cc src/commit.cc src/oid.cc src/revwalk.cc'
27-
obj.uselib = 'GIT2'
36+
#obj.uselib_local = 'libgit2'

0 commit comments

Comments
 (0)