@@ -5,9 +5,6 @@ var version = require("../package.json").libgit2.version;
55var descriptor = require ( "./descriptor.json" ) ;
66var libgit2 = require ( "./v" + version + ".json" ) ;
77
8- // This file was generated by @nkallen.
9- var legacy = require ( "./nkallen.json" ) ;
10-
118// Extracted types.
129var typeMap = require ( "./types.json" ) ;
1310
@@ -30,7 +27,8 @@ typeMap.__proto__ = {
3027 "git_buf *" : { cpp : "Buf" , js : "Buf" } ,
3128 "git_branch_iterator *" : { cpp : "BranchIterator" , js : "Iterator" } ,
3229 "git_branch_iterator **" : { cpp : "BranchIterator" , js : "Iterator" } ,
33- "git_branch_t *" : { cpp : "GitBranch" , js : "Branch" }
30+ "git_branch_t *" : { cpp : "GitBranch" , js : "Branch" } ,
31+ "const git_commit *[]" : { cpp : "Array" , js : "Array" }
3432} ;
3533
3634var files = [ ] ;
@@ -55,7 +53,9 @@ function camelCase(str) {
5553 } ) . join ( "" ) ;
5654}
5755
58- Object . keys ( descriptor ) . forEach ( function ( fileName , index ) {
56+ var fileNames = Object . keys ( descriptor ) ;
57+
58+ fileNames . forEach ( function ( fileName , index ) {
5959 var file = descriptor [ fileName ] ;
6060
6161 // Constants.
@@ -84,14 +84,10 @@ Object.keys(descriptor).forEach(function(fileName, index) {
8484 file . freeFunctionName = "git_" + fileName + "_free" ;
8585 }
8686
87- if ( ( ! cFile || ! cFile . functions ) && ! file . isStruct ) {
88- return ;
89- }
90-
9187 // TODO Obsolete this.
9288 if ( file . isStruct ) {
9389 // No functions.
94- cFile = file ;
90+ cFile = Object . create ( file ) ;
9591 cFile . functions = [ ] ;
9692 }
9793
@@ -101,9 +97,7 @@ Object.keys(descriptor).forEach(function(fileName, index) {
10197 }
10298
10399
104- var legacyFile = legacy . filter ( function ( currentFile ) {
105- return currentFile . filename === file . filename ;
106- } ) [ 0 ] || { } ;
100+ var legacyFile = { } ;
107101
108102 if ( file . jsClassName . indexOf ( "Git" ) === 0 ) {
109103 file . jsClassName = file . jsClassName . slice ( 3 ) ;
@@ -138,7 +132,7 @@ Object.keys(descriptor).forEach(function(fileName, index) {
138132 } ) ;
139133
140134 if ( deps ) {
141- file . dependencies . push . apply ( file . dependencies , deps ) ;
135+ file . dependencies . unshift . apply ( file . dependencies , deps ) ;
142136 }
143137
144138 // Add to the type's list if it's new.
@@ -170,19 +164,23 @@ Object.keys(descriptor).forEach(function(fileName, index) {
170164 // Used to identify a missing function descriptor later on.
171165 var ident = { } ;
172166
173- //Object.keys(file.functions || {}).forEach(function(functionName) {
174- // if (cFile.functions.indexOf(functionName) === -1 && functionName) {
175- // cFile.functions.push(functionName);
176- // }
177- //});
167+ // Cache the existing object, before overwriting.
168+ var functions = file . functions ;
169+ var iterateFunctions = Object . keys ( file . functions || { } ) ;
170+
171+ file . functions = [ ] ;
172+
173+ ( cFile . functions . length ? cFile . functions : iterateFunctions ) . forEach ( function ( functionName , index ) {
174+ if ( iterateFunctions . indexOf ( functionName ) === - 1 ) {
175+ return ;
176+ }
178177
179- file . functions = cFile . functions . map ( function ( functionName , index ) {
180178 var funcDescriptor = libgit2 . functions [ functionName ] ;
181- var descriptor = legacyFile . functions ? legacyFile . functions [ index ] || { } : { } ;
179+ var descriptor = { } ;
182180 var cType = file . cType || "git" ;
183181
184182 // From the hand maintained file.
185- var functionDescriptor = file . functions ? file . functions [ functionName ] || ident : ident ;
183+ var functionDescriptor = functions ? functions [ functionName ] || ident : ident ;
186184
187185 if ( ! functionName || ! funcDescriptor ) { return ; }
188186
@@ -195,10 +193,6 @@ Object.keys(descriptor).forEach(function(fileName, index) {
195193
196194 var trimmedName = functionName . slice ( cType . length + 1 ) ;
197195
198- if ( trimmedName === "new" ) {
199- trimmedName = "new2" ;
200- }
201-
202196 descriptor . cppFunctionName = functionDescriptor . cppFunctionName || titleCase ( trimmedName ) ;
203197 descriptor . jsFunctionName = functionDescriptor . jsFunctionName || camelCase ( trimmedName ) ;
204198
@@ -273,20 +267,33 @@ Object.keys(descriptor).forEach(function(fileName, index) {
273267 } ;
274268
275269 if ( typeMap [ arg . type ] ) {
276- return {
270+ var retVal = {
277271 name : arg . name ,
278272 cType : arg . type ,
279273 cppClassName : typeMap [ arg . type ] . cpp ,
280274 jsClassName : typeMap [ arg . type ] . js ,
281275 comment : arg . comment ,
282- isOptional : isOptional ( ) || true ,
283276 isReturn : isReturn ( ) || false ,
284277 isSelf : isSelf ( ) || false ,
285278 shouldAlloc : manualArgs [ index ] ? manualArgs [ index ] . shouldAlloc || false : false
286279 } ;
280+
281+ if ( manualArgs [ index ] && manualArgs [ index ] . arrayElementCppClassName ) {
282+ retVal . arrayElementCppClassName = manualArgs [ index ] . arrayElementCppClassName ;
283+ }
284+
285+ if ( manualArgs [ index ] && manualArgs [ index ] . cType ) {
286+ retVal . cType = manualArgs [ index ] . cType ;
287+ }
288+
289+ if ( isOptional ( ) ) {
290+ retVal . isOptional = true ;
291+ }
292+
293+ return retVal ;
287294 }
288295
289- return { } ;
296+ throw new Error ( "Missing typedef for " + arg . type ) ;
290297 } ) ;
291298
292299 // By default all methods are synchronous.
@@ -302,7 +309,9 @@ Object.keys(descriptor).forEach(function(fileName, index) {
302309 descriptor . isAsync = functionDescriptor . isAsync ;
303310 }
304311
305- return descriptor ;
312+ if ( Object . keys ( functions || { } ) . indexOf ( descriptor . cFunctionName ) > - 1 ) {
313+ file . functions . push ( descriptor ) ;
314+ }
306315 } ) ;
307316
308317 files . push ( file ) ;
0 commit comments