Skip to content

Commit 458d871

Browse files
committed
Repo is now code-gen'd
1 parent 42c7fa7 commit 458d871

File tree

15 files changed

+331
-315
lines changed

15 files changed

+331
-315
lines changed

gen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var idefs = JSON.parse(fs.readFileSync('v0.18.0.json')),
88

99
for (var i in idefs) {
1010
var idef = idefs[i];
11-
if (["Oid", "Blob"].indexOf(idef.jsClassName) > -1) {
11+
if (["Oid", "Blob", "Repo"].indexOf(idef.jsClassName) > -1) {
1212
fs.writeFileSync(
1313
path.resolve("./include/" + idef.filename), headerTemplate(idef));
1414
fs.writeFileSync(

include/repo.h

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
/*
2-
* Copyright 2013, Tim Branyen @tbranyen <tim@tabdeveloper.com>
3-
* @author Michael Robinson @codeofinterest <mike@pagesofinterest.net>
4-
*
5-
* Dual licensed under the MIT and GPL licenses.
6-
*/
1+
/**
2+
* This code is auto-generated; unless you know what you're doing, do not modify!
3+
**/
74

8-
#ifndef REPO_H
9-
#define REPO_H
5+
#ifndef GITREPO_H
6+
#define GITREPO_H
107

118
#include <v8.h>
129
#include <node.h>
@@ -19,55 +16,44 @@ using namespace v8;
1916

2017
class GitRepo : public ObjectWrap {
2118
public:
19+
2220
static Persistent<Function> constructor_template;
23-
static void Initialize(Handle<v8::Object> target);
21+
static void Initialize (Handle<v8::Object> target);
2422

25-
git_repository* GetValue();
26-
void SetValue(git_repository* repo);
23+
git_repository *GetValue();
2724

28-
void Free();
25+
private:
26+
GitRepo(git_repository *raw);
27+
~GitRepo();
2928

30-
protected:
31-
GitRepo() {}
32-
~GitRepo() {}
3329
static Handle<Value> New(const Arguments& args);
3430

3531
static Handle<Value> Open(const Arguments& args);
3632
static void OpenWork(uv_work_t* req);
3733
static void OpenAfterWork(uv_work_t* req);
3834

39-
static Handle<Value> Free(const Arguments& args);
40-
41-
static Handle<Value> Init(const Arguments& args);
42-
static void InitWork(uv_work_t* req);
43-
static void InitAfterWork(uv_work_t* req);
44-
45-
private:
46-
git_repository* repo;
47-
4835
struct OpenBaton {
4936
uv_work_t request;
5037
const git_error* error;
51-
52-
git_repository* rawRepo;
53-
GitRepo *repo;
54-
55-
std::string path;
56-
38+
git_repository *out;
39+
const char * path;
5740
Persistent<Function> callback;
5841
};
42+
static Handle<Value> Init(const Arguments& args);
43+
static void InitWork(uv_work_t* req);
44+
static void InitAfterWork(uv_work_t* req);
5945

6046
struct InitBaton {
6147
uv_work_t request;
6248
const git_error* error;
63-
64-
GitRepo* repo;
65-
git_repository* rawRepo;
66-
std::string path;
67-
bool isBare;
68-
49+
git_repository *out;
50+
const char * path;
51+
unsigned is_bare;
6952
Persistent<Function> callback;
7053
};
54+
static Handle<Value> Path(const Arguments& args);
55+
static Handle<Value> Workdir(const Arguments& args);
56+
git_repository *raw;
7157
};
7258

7359
#endif

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) {
1212
// Import libraries
1313
exports.blob = require('./blob.js').blob;
1414
exports.repo = require('./repo.js').repo;
15+
exports.init = require('./repo.js').init;
1516
exports.signature = require('./signature.js').signature;
1617
exports.oid = require('./oid.js').oid;
1718
exports.reference = require('./reference.js').reference;

lib/repo.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var git = require('../'),
66
*
77
* @constructor
88
*/
9-
var Repo = function() {
10-
this.rawRepo = new git.raw.Repo();
9+
var Repo = function(rawRepo) {
10+
this.rawRepo = rawRepo;
1111
};
1212

1313
/**
@@ -19,7 +19,7 @@ var Repo = function() {
1919
* @param {String} directory The .git directory for the repository to open.
2020
* @param {Repo~openCallback} callback
2121
*/
22-
Repo.prototype.open = function(directory, callback) {
22+
Repo.open = function(directory, callback) {
2323
/**
2424
* @callback Repo~openCallback Callback executed when repository is opened.
2525
* @param {GitError|null} error An Error or null if successful.
@@ -28,11 +28,9 @@ Repo.prototype.open = function(directory, callback) {
2828
if (typeof callback !== 'function') {
2929
throw new git.error('Callback is required and must be a Function');
3030
}
31-
var self = this;
32-
self.rawRepo.open(directory, function openRepository(error, rawRepo) {
31+
git.raw.Repo.open(directory, function openRepository(error, rawRepo) {
3332
if (success(error, callback)) {
34-
self.rawRepo = rawRepo;
35-
callback(null, self);
33+
callback(null, new Repo(rawRepo));
3634
}
3735
});
3836
};
@@ -94,17 +92,15 @@ Repo.prototype.commit = function(sha, callback) {
9492
* @param {Boolean} isBare True if the repository is to be bare, false otherwise.
9593
* @param {Repo~initCallback} callback
9694
*/
97-
Repo.prototype.init = function(directory, isBare, callback) {
95+
exports.init = function(directory, isBare, callback) {
9896
/**
9997
* @callback Repo~initCallback Callback executed when repository is initialized.
10098
* @param {GitError|null} error An Error or null if successful.
10199
* @param {Repo|null} repo Initialized repository.
102100
*/
103-
var self = this;
104-
self.rawRepo.init(directory, isBare, function(error, rawRepo) {
101+
git.raw.Repo.init(directory, isBare, function(error, rawRepo) {
105102
if (success(error, callback)) {
106-
self.rawRepo = rawRepo;
107-
callback(null, self);
103+
callback(null, new Repo(rawRepo));
108104
}
109105
});
110106
};
@@ -124,9 +120,8 @@ exports.repo = function(directory, callback) {
124120
* @param {GitError|null} error An Error or null if successful.
125121
* @param {Repo|null} repo Opened repository.
126122
*/
127-
var repo = new Repo();
128123
if (typeof directory === 'undefined') {
129124
return repo;
130125
}
131-
repo.open(directory, callback);
126+
Repo.open(directory, callback);
132127
};

src/blob.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void GitBlob::LookupAfterWork(uv_work_t *req) {
108108
LookupBaton *baton = static_cast<LookupBaton *>(req->data);
109109

110110
TryCatch try_catch;
111-
if (success(baton->error, baton->callback)) {
111+
if (!baton->error) {
112112
Handle<Value> argv[1] = { External::New(baton->out) };
113113
Handle<Object> object = constructor_template->NewInstance(1, argv);
114114
Handle<Value> argv2[2] = {
@@ -117,11 +117,10 @@ void GitBlob::LookupAfterWork(uv_work_t *req) {
117117
};
118118
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
119119
} else {
120-
Handle<Value> argv2[2] = {
121-
Exception::Error(String::New(baton->error->message)),
122-
Local<Value>::New(Null())
120+
Handle<Value> argv2[1] = {
121+
GitError::WrapError(baton->error)
123122
};
124-
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
123+
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv2);
125124
}
126125

127126
if (try_catch.HasCaught()) {
@@ -197,7 +196,8 @@ Handle<Value> GitBlob::CreateFromFile(const Arguments& args) {
197196
baton->id = ObjectWrap::Unwrap<GitOid>(args[0]->ToObject())->GetValue();
198197
baton->repo = ObjectWrap::Unwrap<GitRepo>(args[1]->ToObject())->GetValue();
199198

200-
baton->path = stringArgToString(args[2]->ToString()).c_str();
199+
String::Utf8Value str2(args[2]->ToString());
200+
baton->path = strdup(*str2);
201201
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[3]));
202202

203203
uv_queue_work(uv_default_loop(), &baton->request, CreateFromFileWork, (uv_after_work_cb)CreateFromFileAfterWork);
@@ -222,7 +222,7 @@ void GitBlob::CreateFromFileAfterWork(uv_work_t *req) {
222222
CreateFromFileBaton *baton = static_cast<CreateFromFileBaton *>(req->data);
223223

224224
TryCatch try_catch;
225-
if (success(baton->error, baton->callback)) {
225+
if (!baton->error) {
226226
Handle<Value> argv[1] = { External::New(baton->id) };
227227
Handle<Object> object = GitOid::constructor_template->NewInstance(1, argv);
228228
Handle<Value> argv2[2] = {
@@ -231,18 +231,19 @@ void GitBlob::CreateFromFileAfterWork(uv_work_t *req) {
231231
};
232232
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
233233
} else {
234-
Handle<Value> argv2[2] = {
235-
Exception::Error(String::New(baton->error->message)),
236-
Local<Value>::New(Null())
234+
Handle<Value> argv2[1] = {
235+
GitError::WrapError(baton->error)
237236
};
238-
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
237+
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv2);
239238
}
240239

241240
if (try_catch.HasCaught()) {
242241
node::FatalException(try_catch);
243242
}
244243

245244
baton->callback.Dispose();
245+
246+
delete baton->path;
246247
delete baton;
247248
}
248249

@@ -271,7 +272,7 @@ Handle<Value> GitBlob::CreateFromBuffer(const Arguments& args) {
271272
baton->oid = ObjectWrap::Unwrap<GitOid>(args[0]->ToObject())->GetValue();
272273
baton->repo = ObjectWrap::Unwrap<GitRepo>(args[1]->ToObject())->GetValue();
273274
baton->buffer = Buffer::Data(ObjectWrap::Unwrap<Buffer>(args[2]->ToObject()));
274-
baton->len = ObjectWrap::Unwrap<Number>(args[3]->ToObject())->Value();
275+
baton->len = args[3]->ToNumber()->Value();
275276
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[4]));
276277

277278
uv_queue_work(uv_default_loop(), &baton->request, CreateFromBufferWork, (uv_after_work_cb)CreateFromBufferAfterWork);
@@ -297,7 +298,7 @@ void GitBlob::CreateFromBufferAfterWork(uv_work_t *req) {
297298
CreateFromBufferBaton *baton = static_cast<CreateFromBufferBaton *>(req->data);
298299

299300
TryCatch try_catch;
300-
if (success(baton->error, baton->callback)) {
301+
if (!baton->error) {
301302
Handle<Value> argv[1] = { External::New(baton->oid) };
302303
Handle<Object> object = GitOid::constructor_template->NewInstance(1, argv);
303304
Handle<Value> argv2[2] = {
@@ -306,11 +307,10 @@ void GitBlob::CreateFromBufferAfterWork(uv_work_t *req) {
306307
};
307308
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
308309
} else {
309-
Handle<Value> argv2[2] = {
310-
Exception::Error(String::New(baton->error->message)),
311-
Local<Value>::New(Null())
310+
Handle<Value> argv2[1] = {
311+
GitError::WrapError(baton->error)
312312
};
313-
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv2);
313+
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv2);
314314
}
315315

316316
if (try_catch.HasCaught()) {

0 commit comments

Comments
 (0)