Skip to content

Commit fd2b66a

Browse files
committed
Merge pull request nodegit#458 from nodegit/template-proto-functions
Template proto functions
2 parents 2542c04 + 1906fea commit fd2b66a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+234
-236
lines changed

generate/scripts/helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ var Helpers = {
324324
}
325325
}).value();
326326

327+
if ("git_" + typeDef.typeName == fnDef.cFunctionName) {
328+
fnDef.useAsOnRootProto = true;
329+
}
327330
_.merge(fnDef, _.omit(fnOverrides, "args", "return"));
328331
},
329332

generate/templates/templates/enums.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ NodeGit.Enums = {};
44
{% each . as enumerable %}
55
{% if not enumerable.ignore %}
66
{% if enumerable.type == "enum" %}
7-
NodeGit.{{ enumerable.owner }}.{{ enumerable.JsName }} = {
7+
NodeGit.{{ enumerable.owner }}.{{ enumerable.JsName }} =
8+
NodeGit.{{ enumerable.owner }}.__proto__.{{ enumerable.JsName }} = {
89
{% each enumerable.values as value %}
910
{{ value.JsName }}: {{ value.value }},
1011
{% endeach %}

generate/templates/templates/nodegit.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,54 @@ exports.__proto__ = rawApi;
5353
var importExtension = function(name) {
5454
try {
5555
require("./" + name);
56-
} catch (unhandledException) {}
56+
}
57+
catch (unhandledException) {
58+
if (unhandledException.code != "MODULE_NOT_FOUND") {
59+
throw unhandledException;
60+
}
61+
}
5762
};
5863

64+
// Load up utils
65+
rawApi.Utils = {};
66+
require("./utils/lookup_wrapper");
67+
require("./utils/normalize_options");
68+
69+
// Load up extra types;
70+
require("./convenient_hunk");
71+
require("./convenient_patch");
72+
require("./status_file");
73+
require("./enums.js");
74+
5975
// Import extensions
6076
{% each %}
6177
{% if type != "enum" %}
6278
importExtension("{{ filename }}");
6379
{% endif %}
6480
{% endeach %}
81+
/* jshint ignore:start */
82+
{% each . as idef %}
83+
{% if idef.type != "enum" %}
84+
{% each idef.functions as fn %}
85+
{% if fn.useAsOnRootProto %}
86+
87+
// Inherit directly from the original {{idef.jsClassName}} object.
88+
_{{ idef.jsClassName }}.{{ fn.jsFunctionName }}.__proto__ =
89+
_{{ idef.jsClassName }};
6590

66-
//must go last!
67-
require("./enums");
91+
// Ensure we're using the correct prototype.
92+
_{{ idef.jsClassName }}.{{ fn.jsFunctionName }}.prototype =
93+
_{{ idef.jsClassName }}.prototype;
94+
95+
// Assign the function as the root
96+
rawApi.{{idef.jsClassName}} =
97+
_{{ idef.jsClassName }}.{{ fn.jsFunctionName }};
98+
99+
{% endif %}
100+
{% endeach %}
101+
{% endif %}
102+
{% endeach %}
103+
/* jshint ignore:end */
68104

69105
// Wrap asynchronous methods to return promises.
70106
promisify(exports);

lib/attr.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/blob.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var NodeGit = require("../");
2-
var TreeEntry = require("./tree_entry");
3-
var LookupWrapper = require("./util/lookupWrapper");
4-
52
var Blob = NodeGit.Blob;
3+
var LookupWrapper = NodeGit.Utils.lookupWrapper;
4+
var TreeEntry = NodeGit.TreeEntry;
5+
66

77
/**
88
* Retrieves the blob pointed to by the oid
@@ -41,5 +41,3 @@ Blob.prototype.filemode = function() {
4141

4242
return this.isBinary() ? FileMode.EXECUTABLE : FileMode.BLOB;
4343
};
44-
45-
module.exports = Blob;

lib/branch.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/checkout.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var NodeGit = require("../");
2-
var normalizeOptions = require("./util/normalize_options");
2+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
33

44
var Checkout = NodeGit.Checkout;
55
var head = Checkout.head;
@@ -33,5 +33,3 @@ Checkout.tree = function(repo, treeish, options) {
3333

3434
return tree.call(this, repo, treeish, options);
3535
};
36-
37-
module.exports = Checkout;

lib/clone.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var NodeGit = require("../");
2-
var normalizeOptions = require("./util/normalize_options");
2+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
33

44
var Clone = NodeGit.Clone;
55
var clone = Clone.clone;
@@ -44,11 +44,3 @@ Clone.clone = function(url, local_path, options) {
4444
.then(freeRepository)
4545
.then(openRepository);
4646
};
47-
48-
// Inherit directly from the original clone object.
49-
Clone.clone.__proto__ = Clone;
50-
51-
// Ensure we're using the correct prototype.
52-
Clone.clone.prototype = Clone.prototype;
53-
54-
module.exports = Clone.clone;

lib/commit.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var events = require("events");
22
var Promise = require("nodegit-promise");
33
var NodeGit = require("../");
4-
var LookupWrapper = require("./util/lookupWrapper");
5-
64
var Commit = NodeGit.Commit;
5+
var LookupWrapper = NodeGit.Utils.lookupWrapper;
76

87
/**
98
* Retrieves the commit pointed to by the oid
@@ -207,5 +206,3 @@ Commit.prototype.getDiff = function(callback) {
207206
Commit.prototype.toString = function() {
208207
return this.sha();
209208
};
210-
211-
module.exports = Commit;

lib/convenient_hunk.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var NodeGit = require("../");
2+
13
function ConvenientHunk(raw, i) {
24
this.raw = raw;
35
this.i = i;
@@ -32,4 +34,4 @@ ConvenientHunk.prototype.lines = function() {
3234
return result;
3335
};
3436

35-
module.exports = ConvenientHunk;
37+
NodeGit.ConvenientHunk = ConvenientHunk;

0 commit comments

Comments
 (0)