Skip to content

Commit cde854b

Browse files
committed
change "createX" methods to "create"
also blocks instantiation of types from JS
1 parent f7a1903 commit cde854b

8 files changed

Lines changed: 35 additions & 22 deletions

File tree

example/add-and-commit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var git = require('../'),
66
;
77

88
/**
9-
* This example creates a certain file `newfile.txt`, adds it to the git index and
9+
* This example creates a certain file `newfile.txt`, adds it to the git index and
1010
* commits it to head. Similar to a `git add newfile.txt` followed by a `git commit`
1111
**/
1212

@@ -56,4 +56,4 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(openReporError, repo)
5656
});
5757
});
5858
});
59-
});
59+
});

generate/descriptor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@
196196
"functions": {
197197
"git_commit_create": {
198198
"ignore": false,
199-
"jsFunctionName": "createCommit",
200-
"cppFunctionName": "CreateCommit",
199+
"jsFunctionName": "create",
200+
"cppFunctionName": "Create",
201201
"isConstructorMethod": true,
202202
"isAsync": true,
203203
"return": {

generate/nkallen.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12344,8 +12344,8 @@
1234412344
"isAsync": true,
1234512345
"isConstructorMethod": false,
1234612346
"isPrototypeMethod": true,
12347-
"jsFunctionName": "createCommit",
12348-
"cppFunctionName": "CreateCommit",
12347+
"jsFunctionName": "create",
12348+
"cppFunctionName": "Create",
1234912349
"return": {
1235012350
"cType": "int",
1235112351
"cppClassName": "Int32",

generate/setup.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fileNames.forEach(function(fileName, index) {
114114
}
115115

116116
file.freeFunctionName = "git_" + fileName + "_free";
117+
file.createFunctionName = "git_" + fileName + "_create";
117118
}
118119

119120
// TODO Obsolete this.
@@ -136,12 +137,14 @@ fileNames.forEach(function(fileName, index) {
136137
return fnName === initFnName;
137138
});
138139

139-
// Doesn't actually exist.
140+
// Free function doesn't actually exist.
140141
if (cFile.functions.indexOf(file.freeFunctionName) === -1) {
141142
delete file.freeFunctionName;
142143
}
143144

144-
145+
if (cFile.functions.indexOf(file.createFunctionName) === -1) {
146+
delete file.createFunctionName;
147+
}
145148
var legacyFile = {};
146149

147150
if (file.jsClassName.indexOf("Git") === 0) {
@@ -394,6 +397,12 @@ fileNames.forEach(function(fileName, index) {
394397
}
395398
});
396399

400+
if (file.createFunctionName) {
401+
file.cppCreateFunctionName = typeMap[file.createFunctionName].cpp;
402+
file.jsCreateFunctionName = typeMap[file.createFunctionName].js;
403+
delete file.createFunctionName;
404+
}
405+
397406
files.push(file);
398407
});
399408

generate/templates/class_content.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ NAN_METHOD({{ cppClassName }}::New) {
6363
NanScope();
6464

6565
if (args.Length() == 0 || !args[0]->IsExternal()) {
66-
return NanThrowError("{{ cType }} is required.");
66+
{%if createFunctionName%}
67+
return NanThrowError("A new {{ cppClassName }} cannot be instantiated. Use {{ jsCreateFunctionName }} instead.");
68+
{%else%}
69+
return NanThrowError("A new {{ cppClassName }} cannot be instantiated.");
70+
{%endif%}
6771
}
6872

6973
{{ cppClassName }}* object = new {{ cppClassName }}(static_cast<{{ cType }} *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());

generate/types.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,8 +1877,8 @@
18771877
"js": "lookup"
18781878
},
18791879
"git_commit_create": {
1880-
"cpp": "CreateCommit",
1881-
"js": "createCommit"
1880+
"cpp": "Create",
1881+
"js": "create"
18821882
},
18831883
"const git_commit **": {
18841884
"cpp": "GitCommit",
@@ -3301,12 +3301,12 @@
33013301
"js": "nthGenAncestor"
33023302
},
33033303
"git_commit_create *": {
3304-
"cpp": "CreateCommit",
3305-
"js": "createCommit"
3304+
"cpp": "Create",
3305+
"js": "create"
33063306
},
33073307
"const git_commit_create *": {
3308-
"cpp": "CreateCommit",
3309-
"js": "createCommit"
3308+
"cpp": "Create",
3309+
"js": "create"
33103310
},
33113311
"git_commit_create_v *": {
33123312
"cpp": "CreateV",

lib/repository.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Repository.prototype.getRemotes = function(callback) {
4848
callback(null, remotes);
4949
}
5050

51-
return remotes;
51+
return remotes;
5252
}, callback);
5353
};
5454

@@ -218,7 +218,7 @@ Repository.prototype.createCommit = function(
218218
var commit = this;
219219

220220
if (tree instanceof Tree) {
221-
commit = Commit.createCommit.call(
221+
commit = Commit.create.call(
222222
this,
223223
updateRef,
224224
author,
@@ -231,7 +231,7 @@ Repository.prototype.createCommit = function(
231231
);
232232
} else {
233233
createCommit = this.getTree(tree).then(function(tree) {
234-
return Commit.createCommit.call(
234+
return Commit.create.call(
235235
commit,
236236
updateRef,
237237
author,

test/tests/commit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ describe("Commit", function() {
9191
history.on("commit", function(commit) {
9292
historyCount++;
9393
});
94-
94+
9595
history.on("end", function(commits) {
9696
assert.equal(historyCount, expectedHistoryCount);
9797
assert.equal(commits.length, expectedHistoryCount);
9898

9999
done();
100100
});
101-
101+
102102
history.on("error", function(err) {
103103
assert.ok(false);
104104
});
105-
105+
106106
history.start();
107107
});
108108

@@ -143,7 +143,7 @@ describe("Commit", function() {
143143
treeWalker.on("error", function() {
144144
assert.ok(false);
145145
});
146-
146+
147147
treeWalker.on("end", function(entries) {
148148
assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount);
149149
done();

0 commit comments

Comments
 (0)