Skip to content

Commit 707675a

Browse files
committed
Reference is now code-gen'd
1 parent 458d871 commit 707675a

16 files changed

Lines changed: 1126 additions & 683 deletions

File tree

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", "Repo"].indexOf(idef.jsClassName) > -1) {
11+
if (["Oid", "Blob", "Repo", "Reference"].indexOf(idef.jsClassName) > -1) {
1212
fs.writeFileSync(
1313
path.resolve("./include/" + idef.filename), headerTemplate(idef));
1414
fs.writeFileSync(

include/blob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GitBlob : public ObjectWrap {
3535
struct LookupBaton {
3636
uv_work_t request;
3737
const git_error* error;
38-
git_blob *out;
38+
git_blob * blob;
3939
git_repository * repo;
4040
const git_oid * id;
4141
Persistent<Function> callback;

include/reference.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
/**
2-
* Copyright (c) 2011, 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-
*/
2+
* This code is auto-generated; unless you know what you're doing, do not modify!
3+
**/
74

8-
#ifndef REF_H
9-
#define REF_H
5+
#ifndef GITREFERENCE_H
6+
#define GITREFERENCE_H
107

118
#include <v8.h>
129
#include <node.h>
1310
#include <string>
1411

1512
#include "git2.h"
1613

17-
#include "repo.h"
18-
#include "oid.h"
19-
2014
using namespace node;
2115
using namespace v8;
2216

2317
class GitReference : public ObjectWrap {
2418
public:
25-
const git_oid* Oid();
19+
2620
static Persistent<Function> constructor_template;
27-
static void Initialize(Handle<v8::Object> target);
21+
static void Initialize (Handle<v8::Object> target);
2822

29-
git_reference* GetValue();
30-
void SetValue(git_reference* ref);
23+
git_reference *GetValue();
3124

32-
protected:
33-
GitReference() {}
34-
~GitReference() {}
35-
static Handle<Value> New(const Arguments& args);
25+
private:
26+
GitReference(git_reference *raw);
27+
~GitReference();
3628

37-
static Handle<Value> Oid(const Arguments& args);
38-
static void OidWork(uv_work_t* req);
39-
static void OidAfterWork(uv_work_t* req);
29+
static Handle<Value> New(const Arguments& args);
4030

4131
static Handle<Value> Lookup(const Arguments& args);
4232
static void LookupWork(uv_work_t* req);
4333
static void LookupAfterWork(uv_work_t* req);
4434

45-
46-
private:
47-
git_reference *ref;
48-
4935
struct LookupBaton {
5036
uv_work_t request;
5137
const git_error* error;
52-
53-
GitReference* ref;
54-
git_reference* rawRef;
55-
git_repository* rawRepo;
56-
std::string name;
57-
38+
git_reference * out;
39+
git_repository * repo;
40+
const char * name;
5841
Persistent<Function> callback;
5942
};
43+
static Handle<Value> OidForName(const Arguments& args);
44+
static void OidForNameWork(uv_work_t* req);
45+
static void OidForNameAfterWork(uv_work_t* req);
6046

61-
struct OidBaton {
47+
struct OidForNameBaton {
6248
uv_work_t request;
6349
const git_error* error;
50+
git_oid * out;
51+
git_repository * repo;
52+
const char * name;
53+
Persistent<Function> callback;
54+
};
55+
static Handle<Value> Oid(const Arguments& args);
56+
static Handle<Value> Name(const Arguments& args);
57+
static Handle<Value> Type(const Arguments& args);
58+
static Handle<Value> Resolve(const Arguments& args);
59+
static void ResolveWork(uv_work_t* req);
60+
static void ResolveAfterWork(uv_work_t* req);
6461

65-
const git_oid* rawOid;
66-
git_reference* rawRef;
67-
62+
struct ResolveBaton {
63+
uv_work_t request;
64+
const git_error* error;
65+
git_reference * out;
66+
const git_reference * ref;
6867
Persistent<Function> callback;
6968
};
69+
git_reference *raw;
7070
};
7171

7272
#endif

include/repo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GitRepo : public ObjectWrap {
3535
struct OpenBaton {
3636
uv_work_t request;
3737
const git_error* error;
38-
git_repository *out;
38+
git_repository * out;
3939
const char * path;
4040
Persistent<Function> callback;
4141
};
@@ -46,7 +46,7 @@ class GitRepo : public ObjectWrap {
4646
struct InitBaton {
4747
uv_work_t request;
4848
const git_error* error;
49-
git_repository *out;
49+
git_repository * out;
5050
const char * path;
5151
unsigned is_bare;
5252
Persistent<Function> callback;

lib/reference.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ var git = require('../'),
88
* @param {git.raw.Repo} rawRepo
99
* @param {git.raw.Reference} [rawReference = new git.raw.Reference()]
1010
*/
11-
var Reference = function(rawRepo, rawReference) {
12-
if (!(rawRepo instanceof git.raw.Repo)) {
13-
throw new git.error('First parameter for Reference must be a raw repo');
11+
var Reference = function(rawReference) {
12+
if (!(rawReference instanceof git.raw.Reference)) {
13+
throw new git.error('First parameter for Reference must be a raw reference');
1414
}
15-
this.rawRepo = rawRepo;
15+
this.rawReference = rawReference;
16+
};
1617

17-
if (rawReference instanceof git.raw.Reference) {
18-
this.rawReference = rawReference;
19-
} else {
20-
this.rawReference = new git.raw.Reference(this.rawRepo);
21-
}
18+
Reference.Type = {
19+
Oid: 0,
20+
Symbolic: 1
2221
};
2322

2423
/**
@@ -27,38 +26,31 @@ var Reference = function(rawRepo, rawReference) {
2726
* @param {String} name
2827
* @param {Reference~lookupCallback} callback
2928
*/
30-
Reference.prototype.lookup = function(name, callback) {
29+
Reference.lookup = function(rawRepo, name, callback) {
3130
/**
3231
* @callback Reference~lookupCallback Callback executed on lookup completion.
3332
* @param {GitError|null} error An Error or null if successful.
3433
* @param {Reference|null} reference Retrieved reference object or null.
3534
*/
3635
var self = this;
37-
self.rawReference.lookup(self.rawRepo, name, function referenceLookup(error, rawReference) {
38-
if (!success(error, callback)) {
39-
return;
36+
git.raw.Reference.lookup(rawRepo, name, function referenceLookup(error, rawReference) {
37+
if (rawReference.type() == Reference.Type.Symbolic) {
38+
rawReference.resolve(function referenceResolve(error, rawReference) {
39+
if (!success(error, callback)) return;
40+
callback(null, new Reference(rawReference));
41+
});
42+
} else {
43+
if (!success(error, callback)) return;
44+
callback(null, new Reference(rawReference));
4045
}
41-
self.rawReference = rawReference;
42-
callback(null, self);
4346
});
4447
};
4548

4649
/**
4750
* Get the Oid representing this reference.
48-
*
49-
* @param {Reference~oidCallback} callback
5051
*/
51-
Reference.prototype.oid = function(callback) {
52-
/**
53-
* @callback Reference~oidCallback Callback executed on oid retrieval.
54-
* @param {GitError|null} error An Error or null if successful.
55-
* @param {Oid|null} oid Retrieved Oid object or null.
56-
*/
57-
this.rawReference.oid(function referenceOid(error, rawOid) {
58-
if (success(error, callback)) {
59-
callback(null, new git.oid(rawOid));
60-
}
61-
});
52+
Reference.prototype.oid = function() {
53+
return this.rawReference.oid();
6254
};
6355

6456
exports.reference = Reference;

lib/repo.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,14 @@ Repo.prototype.branch = function(name, callback) {
4848
* @param {Commit|null} repo HEAD commit for the branch.
4949
*/
5050
var self = this;
51-
(new git.reference(self.rawRepo)).lookup('refs/heads/' + name, function referenceLookupCallback(error, reference) {
52-
if (!success(error, callback)) {
53-
return;
54-
}
55-
reference.oid(function oidCallback(error, oid) {
56-
if (!success(error, callback)) {
57-
return;
58-
}
59-
self.commit(oid, function commitLookupCallback(error, commit) {
60-
if (!success(error, callback)) {
61-
return;
62-
}
63-
callback(null, commit);
64-
});
51+
git.reference.lookup(this.rawRepo, 'refs/heads/' + name, function referenceLookupCallback(error, reference) {
52+
if (!success(error, callback)) return;
53+
54+
var oid = reference.oid();
55+
self.commit(oid, function commitLookupCallback(error, commit) {
56+
if (!success(error, callback)) return;
57+
58+
callback(null, commit);
6559
});
6660
});
6761
};

munge.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,15 @@ var fs = require('fs'),
22
_ = require('underscore'),
33
path = require('path');
44

5-
var DOUBLE_POINTER_RE = /\*\*$/;
6-
var OUT_VAR_RE = /_out$/;
7-
function isConstructorMethod(cType, functionInfo) {
8-
if (!functionInfo.args.length) return false;
9-
var firstArg = functionInfo.args[0];
10-
return RegExp(cType + " \\*\\*$").test(firstArg.cType) && !isPrototypeMethod(cType, functionInfo) && !/_free$/.test(functionInfo.cFunctionName);
11-
}
12-
13-
function isPrototypeMethod(cType, functionInfo) {
14-
if (!functionInfo.args.length) return false;
15-
16-
var firstArg = functionInfo.args[0];
17-
return RegExp(cType + " \\*$").test(firstArg.cType) && !/_free$/.test(functionInfo.cFunctionName);
18-
}
19-
205
var idefs = JSON.parse(fs.readFileSync('v0.18.0.json'));
216

227
for (var i in idefs) {
238
var idef = idefs[i];
249

2510
for (var j in idef.functions) {
2611
var fn = idef.functions[j];
27-
var old1 = fn.isPrototypeMethod;
28-
var old2 = fn.isConstructorMethod;
29-
fn.isPrototypeMethod = isPrototypeMethod(idef.cType, fn);
30-
fn.isConstructorMethod = isConstructorMethod(idef.cType, fn);
31-
fn.isFree = /_free$/.test(fn.cFunctionName);
32-
12+
if (!fn.isConstructorMethod) continue;
13+
fn.args[0].isReturn = true;
3314
}
3415
}
3516
console.log(JSON.stringify(idefs, null, 2));

0 commit comments

Comments
 (0)