Skip to content

Commit bd4bf7e

Browse files
committed
automatically rename functions with weird two-word words
Conflicts: generate/descriptor.json generate/utils.js
1 parent 1ed1c4f commit bd4bf7e

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

generate/descriptor.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,6 @@
554554
"git_index_add_all": {
555555
"ignore": true
556556
},
557-
"git_index_add_bypath": {
558-
"jsFunctionName": "addByPath"
559-
},
560557
"git_index_conflict_get": {
561558
"ignore": true
562559
},
@@ -584,13 +581,13 @@
584581
"git_index_new": {
585582
"ignore": true
586583
},
587-
"git_index_read": {
588-
"args": {
589-
"force": {
590-
"isOptional": true
591-
}
592-
}
593-
},
584+
"git_index_read": {
585+
"args": {
586+
"force": {
587+
"isOptional": true
588+
}
589+
}
590+
},
594591
"git_index_remove_all": {
595592
"ignore": true
596593
},
@@ -599,7 +596,7 @@
599596
},
600597
"git_index_update_all": {
601598
"ignore": true
602-
},
599+
},
603600
"git_index_write": {
604601
"args": {
605602
"force": {
@@ -827,7 +824,6 @@
827824
"ignore": true
828825
},
829826
"git_oid_fromstr": {
830-
"jsFunctionName": "fromString",
831827
"isAsync": false
832828
},
833829
"git_oid_fromstrn": {
@@ -852,8 +848,7 @@
852848
"ignore": true
853849
},
854850
"git_oid_tostr": {
855-
"ignore": true,
856-
"jsFunctionName": "toString"
851+
"ignore": true
857852
}
858853
},
859854
"fields": {

generate/utils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ var Utils = {
7575
},
7676

7777
cTypeToJsName: function(cType, ownerType) {
78-
return Utils.camelCase(Utils.cTypeToCppName(cType, ownerType).replace("Git", ""));
78+
var output = Utils.camelCase(Utils.cTypeToCppName(cType, ownerType).replace(/^Git/, ""));
79+
var mergedPrefixes = ["from", "by"];
80+
81+
mergedPrefixes.forEach(function(prefix) {
82+
var reg = new RegExp("(^" + prefix + "|" + Utils.titleCase(prefix) + ")([a-z]+)$");
83+
output = output.replace(reg, function(all, prefixMatch, otherWord) {
84+
return prefixMatch + Utils.titleCase(otherWord);
85+
});
86+
});
87+
88+
output = output.replace(/([a-z])Str$/, "$1String")
89+
return output;
7990
},
8091

8192
isConstructorFunction: function(cType, fnName) {
@@ -287,7 +298,6 @@ var Utils = {
287298
fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + typeDef.typeName);
288299
//fnDef.isAsync = false; // until proven otherwise
289300

290-
291301
if (fnDef.cppFunctionName == typeDef.cppClassName) {
292302
fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", "");
293303
}

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Index.prototype.entries = function() {
1111
var result = [];
1212

1313
for (var i = 0; i < size; i++) {
14-
result.push(this.entry(i));
14+
result.push(this.getByIndex(i));
1515
}
1616

1717
return result;

lib/tree.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Treebuilder = git.Treebuilder;
44
var Diff = git.Diff;
55
var events = require("events");
66

7+
var oldEntryByIndex = Tree.prototype.entryByIndex;
78
// Backwards compatibility.
89
Object.defineProperties(Tree.prototype, {
910
"size": {
@@ -34,8 +35,9 @@ Tree.prototype.diff = function(tree, callback) {
3435
* @param {Number} i
3536
* @return {TreeEntry}
3637
*/
38+
3739
Tree.prototype.entryByIndex = function(i) {
38-
var entry = this.entryByindex(i);
40+
var entry = oldEntryByIndex.call(this, i);
3941
entry.parent = this;
4042
return entry;
4143
};
@@ -62,7 +64,7 @@ Tree.prototype.entryByName = function(name) {
6264
Tree.prototype.getEntry = function(path, callback) {
6365
var tree = this;
6466

65-
return this.entryBypath(path).then(function(entry) {
67+
return this.entryByPath(path).then(function(entry) {
6668
entry.parent = tree;
6769

6870
if (typeof callback === "function") {

0 commit comments

Comments
 (0)