From 93633030df421a202263d1f9ce61b6bb8d90ec99 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 11:07:26 -0700 Subject: [PATCH 1/5] add DSSTORE and generated js to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index afac9533a..d3c4d70cf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ /test/repos/ /src/ /include/ +/lib/enums.js + /vendor/Release /vendor/*.vcxproj @@ -17,4 +19,6 @@ /generate/missing-tests.json /binding.gyp + *.log +.DS_STORE From 9c2d6f005f4b418edbb4ca14a289d265d4987a00 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 11:08:17 -0700 Subject: [PATCH 2/5] build template for enum js file --- generate/templates/enums.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 generate/templates/enums.js diff --git a/generate/templates/enums.js b/generate/templates/enums.js new file mode 100644 index 000000000..d70904e95 --- /dev/null +++ b/generate/templates/enums.js @@ -0,0 +1,19 @@ +var NodeGit = require("../"); +NodeGit.Enums = {}; + +/* jshint ignore:start */ +{% each %} +var {{ owner }} = NodeGit.{{ owner }}; + + {% each enums as enumerable %} + {% if enumerable.type == "enum" %} +{{ owner }}.{{ enumerable.JsName }} = { + {% each enumerable.values as value %} + {{ value.JsName }}: {{ value.value }}, + {% endeach %} +}; + {% endif %} + {% endeach %} + +{% endeach %} +/* jshint ignore:end */ From 58b7f3566c34043a91c0548f3d193c7c77037d9d Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 11:14:27 -0700 Subject: [PATCH 3/5] ignore enums in the idefs when not needed --- generate/templates/binding.gyp | 2 ++ generate/templates/nodegit.cc | 8 ++++++-- lib/nodegit.js | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/generate/templates/binding.gyp b/generate/templates/binding.gyp index dc2de328b..10f292de3 100644 --- a/generate/templates/binding.gyp +++ b/generate/templates/binding.gyp @@ -13,7 +13,9 @@ "src/wrapper.cc", "src/functions/copy.cc", {%each%} + {% if type != "enum" %} "src/{{ name }}.cc", + {% endif %} {%endeach%} ], diff --git a/generate/templates/nodegit.cc b/generate/templates/nodegit.cc index 4d6147899..5431d753b 100644 --- a/generate/templates/nodegit.cc +++ b/generate/templates/nodegit.cc @@ -5,16 +5,20 @@ #include "../include/wrapper.h" #include "../include/functions/copy.h" -{%each%} +{% each %} + {% if type != "enum" %} #include "../include/{{ filename }}.h" -{%endeach%} + {% endif %} +{% endeach %} extern "C" void init(Handle target) { NanScope(); Wrapper::InitializeComponent(target); {%each%} + {% if type != "enum" %} {{ cppClassName }}::InitializeComponent(target); + {% endif %} {%endeach%} } diff --git a/lib/nodegit.js b/lib/nodegit.js index 117fbf11d..0468cee47 100644 --- a/lib/nodegit.js +++ b/lib/nodegit.js @@ -15,6 +15,9 @@ catch (e) { // Native methods do not return an identifiable function, so this function will // filter down the function identity to match the libgit2 descriptor. descriptors.forEach(function(descriptor) { + if (descriptor.type == "enum") { + return; + } var Ctor = rawApi[descriptor.jsClassName]; // Iterate over each function in the file. From 7b032bee7276381d66e4f4bdc9ef46e92931bb24 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 11:15:33 -0700 Subject: [PATCH 4/5] generate enums in json --- generate/descriptor.json | 2214 +++++++++++++++++++------------------- generate/index.js | 41 +- generate/setup.js | 128 ++- generate/utils.js | 92 +- lib/nodegit.js | 3 + 5 files changed, 1296 insertions(+), 1182 deletions(-) diff --git a/generate/descriptor.json b/generate/descriptor.json index e57e45234..426c6e63c 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -1,1178 +1,1218 @@ { - "attr": { - "functions": { - "git_attr_foreach": { - "ignore": true - }, - "git_attr_get": { - "isAsync": true, - "args": { - "value_out": { - "isReturn": true - } + "enums": { + "branch": { + "JsName": "BRANCH", + "isMask": false + }, + "clone_local": { + "isMask": false, + "values": { + "GIT_CLONE_LOCAL": { + "JsName": "LOCAL" } } - } - }, - "blame": { - "cType": "git_blame" - }, - "blame_hunk": { - "fields": { - "boundary": { - "ignore": true + }, + "error": { + "JsName": "ERROR", + "isMask": false + }, + "error_code": { + "values": { + "GIT_ERROR": { + "JsName": "ERROR" + } } + }, + "status": { + "JsName": "STATUS", + "isMask": false } }, - "blob": { - "functions": { - "git_blob_create_frombuffer": { - "args": { - "buffer": { - "cppClassName": "Buffer", - "jsClassName": "Buffer" + "types": + { + "attr": { + "functions": { + "git_attr_foreach": { + "ignore": true + }, + "git_attr_get": { + "isAsync": true, + "args": { + "value_out": { + "isReturn": true + } } } - }, - "git_blob_create_fromchunks": { - "ignore": true - }, - "git_blob_filtered_content": { - "ignore": true - }, - "git_blob_rawcontent": { - "return": { - "cppClassName": "Wrapper", - "jsClassName": "Buffer" - } } }, - "dependencies": [ - "../include/wrapper.h", - "node_buffer.h" - ] - }, - "branch": { - "functions": { - "git_branch_next": { - "ignore": true + "blame": { + "cType": "git_blame" + }, + "blame_hunk": { + "fields": { + "boundary": { + "ignore": true + } } - } - }, - "buf": { - "functions": { - "git_buf_grow": { - "cppFunctionName": "Grow", - "jsFunctionName": "grow", - "args": { - "buffer": { - "isReturn": true, - "isSelf": false, - "shouldAlloc": true + }, + "blob": { + "functions": { + "git_blob_create_frombuffer": { + "args": { + "buffer": { + "cppClassName": "Buffer", + "jsClassName": "Buffer" + } } }, - "return": { - "cppClassName": "Number", - "jsClassName": "Number", - "isErrorCode": true - }, - "isAsync": true - }, - "git_buf_set": { - "cppFunctionName": "Set", - "jsFunctionName": "set", - "args": { - "buffer": { - "isReturn": true, - "isSelf": false, - "shouldAlloc": true - }, - "data": { - "cppClassName": "Buffer", - "jsClassName": "Buffer" - } + "git_blob_create_fromchunks": { + "ignore": true }, - "return": { - "cppClassName": "Number", - "jsClassName": "Number", - "isErrorCode": true + "git_blob_filtered_content": { + "ignore": true }, - "isAsync": true - } - } - }, - "clone": { - "functions": { - "git_clone": { - "args": { - "options": { - "isOptional": true + "git_blob_rawcontent": { + "return": { + "cppClassName": "Wrapper", + "jsClassName": "Buffer" } } + }, + "dependencies": [ + "../include/wrapper.h", + "node_buffer.h" + ] + }, + "branch": { + "functions": { + "git_branch_next": { + "ignore": true + } } - } - }, - "commit": { - "functions": { - "git_commit_create": { - "args": { - "id": { - "isReturn": true + }, + "buf": { + "functions": { + "git_buf_grow": { + "cppFunctionName": "Grow", + "jsFunctionName": "grow", + "args": { + "buffer": { + "isReturn": true, + "isSelf": false, + "shouldAlloc": true + } + }, + "return": { + "cppClassName": "Number", + "jsClassName": "Number", + "isErrorCode": true }, - "message_encoding": { - "isOptional": true + "isAsync": true + }, + "git_buf_set": { + "cppFunctionName": "Set", + "jsFunctionName": "set", + "args": { + "buffer": { + "isReturn": true, + "isSelf": false, + "shouldAlloc": true + }, + "data": { + "cppClassName": "Buffer", + "jsClassName": "Buffer" + } }, - "parents": { - "cType": "const git_commit **", - "cppClassName": "Array", - "jsClassName": "Array", - "arrayElementCppClassName": "GitCommit" + "return": { + "cppClassName": "Number", + "jsClassName": "Number", + "isErrorCode": true }, - "update_ref": { - "isOptional": true + "isAsync": true + } + } + }, + "clone": { + "functions": { + "git_clone": { + "args": { + "options": { + "isOptional": true + } } } - }, - "git_commit_create_from_callback": { - "ignore": true - }, - "git_commit_create_from_ids": { - "ignore": true } - } - }, - "config": { - "functions": { - "git_config_add_backend": { - "ignore": true - }, - "git_config_add_file_ondisk": { - "ignore": true - }, - "git_config_backend_foreach_match": { - "ignore": true - }, - "git_config_delete_entry": { - "ignore": true - }, - "git_config_delete_multivar": { - "ignore": true - }, - "git_config_find_global": { - "ignore": true - }, - "git_config_find_system": { - "ignore": true - }, - "git_config_find_xdg": { - "ignore": true - }, - "git_config_foreach": { - "ignore": true - }, - "git_config_foreach_match": { - "ignore": true - }, - "git_config_free": { - "ignore": true - }, - "git_config_get_bool": { - "ignore": true - }, - "git_config_get_entry": { - "ignore": true - }, - "git_config_get_int32": { - "ignore": true - }, - "git_config_get_int64": { - "ignore": true - }, - "git_config_get_mapped": { - "ignore": true - }, - "git_config_get_multivar_foreach": { - "ignore": true - }, - "git_config_get_string": { - "ignore": true - }, - "git_config_iterator_free": { - "ignore": true - }, - "git_config_iterator_glob_new": { - "ignore": true - }, - "git_config_iterator_new": { - "ignore": true - }, - "git_config_init_backend": { - "ignore": true - }, - "git_config_lookup_map_value": { - "ignore": true - }, - "git_config_multivar_iterator_new": { - "ignore": true - }, - "git_config_new": { - "ignore": true - }, - "git_config_next": { - "ignore": true - }, - "git_config_open_default": { - "ignore": true - }, - "git_config_open_global": { - "ignore": true - }, - "git_config_open_level": { - "ignore": true - }, - "git_config_open_ondisk": { - "ignore": true - }, - "git_config_parse_bool": { - "ignore": true - }, - "git_config_parse_int32": { - "ignore": true - }, - "git_config_parse_int64": { - "ignore": true - }, - "git_config_refresh": { - "ignore": true - }, - "git_config_set_bool": { - "ignore": true - }, - "git_config_set_int32": { - "ignore": true + }, + "commit": { + "functions": { + "git_commit_create": { + "args": { + "id": { + "isReturn": true + }, + "message_encoding": { + "isOptional": true + }, + "parents": { + "cType": "const git_commit **", + "cppClassName": "Array", + "jsClassName": "Array", + "arrayElementCppClassName": "GitCommit" + }, + "update_ref": { + "isOptional": true + } + } + }, + "git_commit_create_from_callback": { + "ignore": true + }, + "git_commit_create_from_ids": { + "ignore": true + } } - } - }, - "config_backend": { - "ignore": true - }, - "config_iterator": { - "ignore": true - }, - "cred": { - "cType": "git_cred", - "functions": { - "git_cred_ssh_custom_new": { - "ignore": true - }, - "git_cred_ssh_interactive_new": { - "ignore": true - }, - "git_cred_ssh_key_from_agent":{ - "isAsync": false - }, - "git_cred_userpass": { - "ignore": true + }, + "config": { + "functions": { + "git_config_add_backend": { + "ignore": true + }, + "git_config_add_file_ondisk": { + "ignore": true + }, + "git_config_backend_foreach_match": { + "ignore": true + }, + "git_config_delete_entry": { + "ignore": true + }, + "git_config_delete_multivar": { + "ignore": true + }, + "git_config_find_global": { + "ignore": true + }, + "git_config_find_system": { + "ignore": true + }, + "git_config_find_xdg": { + "ignore": true + }, + "git_config_foreach": { + "ignore": true + }, + "git_config_foreach_match": { + "ignore": true + }, + "git_config_free": { + "ignore": true + }, + "git_config_get_bool": { + "ignore": true + }, + "git_config_get_entry": { + "ignore": true + }, + "git_config_get_int32": { + "ignore": true + }, + "git_config_get_int64": { + "ignore": true + }, + "git_config_get_mapped": { + "ignore": true + }, + "git_config_get_multivar_foreach": { + "ignore": true + }, + "git_config_get_string": { + "ignore": true + }, + "git_config_iterator_free": { + "ignore": true + }, + "git_config_iterator_glob_new": { + "ignore": true + }, + "git_config_iterator_new": { + "ignore": true + }, + "git_config_init_backend": { + "ignore": true + }, + "git_config_lookup_map_value": { + "ignore": true + }, + "git_config_multivar_iterator_new": { + "ignore": true + }, + "git_config_new": { + "ignore": true + }, + "git_config_next": { + "ignore": true + }, + "git_config_open_default": { + "ignore": true + }, + "git_config_open_global": { + "ignore": true + }, + "git_config_open_level": { + "ignore": true + }, + "git_config_open_ondisk": { + "ignore": true + }, + "git_config_parse_bool": { + "ignore": true + }, + "git_config_parse_int32": { + "ignore": true + }, + "git_config_parse_int64": { + "ignore": true + }, + "git_config_refresh": { + "ignore": true + }, + "git_config_set_bool": { + "ignore": true + }, + "git_config_set_int32": { + "ignore": true + } } - } - }, - "cred_ssh_custom": { - "ignore": true - }, - "cred_ssh_interactive": { - "ignore": true - }, - "cred_ssh_key": { - "ignore": true - }, - "cred_userpass_payload": { - "cDependencies": [ - "git2/cred_helpers.h" - ] - }, - "cred_userpass_plaintext": { - "ignore": true - }, - "diff": { - "cDependencies": [ - "git2/sys/diff.h" - ], - "functions": { - "git_diff_blob_to_buffer": { - "ignore": true - }, - "git_diff_blobs": { - "ignore": true - }, - "git_diff_buffers": { - "ignore": true - }, - "git_diff_commit_as_email": { - "ignore": true - }, - "git_diff_find_init_options": { - "ignore": true - }, - "git_diff_find_similar": { - "ignore": true - }, - "git_diff_foreach": { - "ignore": true - }, - "git_diff_format_email": { - "ignore": true - }, - "git_diff_format_email_init_options": { - "ignore": true - }, - "git_diff_free": { - "ignore": true - }, - "git_diff_get_stats": { - "ignore": true - }, - "git_diff_index_to_workdir": { - "ignore": true - }, - "git_diff_init_options": { - "ignore": true - }, - "git_diff_is_sorted_icase": { - "ignore": true - }, - "git_diff_merge": { - "ignore": true - }, - "git_diff_num_deltas_of_type": { - "ignore": true - }, - "git_diff_print": { - "ignore": true - }, - "git_diff_print_callback__to_buf": { - "ignore": true - }, - "git_diff_print_callback__to_file_handle": { - "ignore": true - }, - "git_diff_stats_deletions": { - "ignore": true - }, - "git_diff_stats_files_changed": { - "ignore": true - }, - "git_diff_stats_free": { - "ignore": true - }, - "git_diff_stats_insertions": { - "ignore": true - }, - "git_diff_stats_to_buf": { - "ignore": true - }, - "git_diff_status_char": { - "ignore": true - }, - "git_diff_tree_to_index": { - "ignore": true - }, - "git_diff_tree_to_tree": { - "args": { - "opts": { - "isOptional": true - } + }, + "config_backend": { + "ignore": true + }, + "config_iterator": { + "ignore": true + }, + "cred": { + "cType": "git_cred", + "functions": { + "git_cred_ssh_custom_new": { + "ignore": true + }, + "git_cred_ssh_interactive_new": { + "ignore": true + }, + "git_cred_ssh_key_from_agent":{ + "isAsync": false + }, + "git_cred_userpass": { + "ignore": true } - }, - "git_diff_tree_to_workdir": { - "ignore": true - }, - "git_diff_tree_to_workdir_with_index": { - "ignore": true } - } - }, - "diff_find_options": { - "fields": { - "git_diff_similarity_metric": { - "ignore": true + }, + "cred_ssh_custom": { + "ignore": true + }, + "cred_ssh_interactive": { + "ignore": true + }, + "cred_ssh_key": { + "ignore": true + }, + "cred_userpass_payload": { + "cDependencies": [ + "git2/cred_helpers.h" + ] + }, + "cred_userpass_plaintext": { + "ignore": true + }, + "diff": { + "cDependencies": [ + "git2/sys/diff.h" + ], + "functions": { + "git_diff_blob_to_buffer": { + "ignore": true + }, + "git_diff_blobs": { + "ignore": true + }, + "git_diff_buffers": { + "ignore": true + }, + "git_diff_commit_as_email": { + "ignore": true + }, + "git_diff_find_init_options": { + "ignore": true + }, + "git_diff_find_similar": { + "ignore": true + }, + "git_diff_foreach": { + "ignore": true + }, + "git_diff_format_email": { + "ignore": true + }, + "git_diff_format_email_init_options": { + "ignore": true + }, + "git_diff_free": { + "ignore": true + }, + "git_diff_get_stats": { + "ignore": true + }, + "git_diff_index_to_workdir": { + "ignore": true + }, + "git_diff_init_options": { + "ignore": true + }, + "git_diff_is_sorted_icase": { + "ignore": true + }, + "git_diff_merge": { + "ignore": true + }, + "git_diff_num_deltas_of_type": { + "ignore": true + }, + "git_diff_print": { + "ignore": true + }, + "git_diff_print_callback__to_buf": { + "ignore": true + }, + "git_diff_print_callback__to_file_handle": { + "ignore": true + }, + "git_diff_stats_deletions": { + "ignore": true + }, + "git_diff_stats_files_changed": { + "ignore": true + }, + "git_diff_stats_free": { + "ignore": true + }, + "git_diff_stats_insertions": { + "ignore": true + }, + "git_diff_stats_to_buf": { + "ignore": true + }, + "git_diff_status_char": { + "ignore": true + }, + "git_diff_tree_to_index": { + "ignore": true + }, + "git_diff_tree_to_tree": { + "args": { + "opts": { + "isOptional": true + } + } + }, + "git_diff_tree_to_workdir": { + "ignore": true + }, + "git_diff_tree_to_workdir_with_index": { + "ignore": true + } } }, - "ignore": true - }, - "diff_format_email_options": { - "ignore": true - }, - "diff_perfdata": { - "cDependencies": [ - "git2/sys/diff.h" - ] - }, - "diff_similarity_metric": { - "ignore": true - }, - "filter": { - "functions": { - "git_filter_list_apply_to_blob": { - "ignore": true - }, - "git_filter_list_apply_to_data": { - "ignore": true - }, - "git_filter_list_apply_to_file": { - "ignore": true - }, - "git_filter_list_free": { - "ignore": true - }, - "git_filter_list_load": { - "ignore": true - }, - "git_filter_list_push": { - "ignore": true - }, - "git_filter_source_filemode": { - "ignore": true - }, - "git_filter_source_id": { - "ignore": true - }, - "git_filter_source_mode": { - "ignore": true - }, - "git_filter_source_options": { - "ignore": true - }, - "git_filter_source_path": { - "ignore": true + "diff_find_options": { + "fields": { + "git_diff_similarity_metric": { + "ignore": true + } }, - "git_filter_source_repo": { - "ignore": true + "ignore": true + }, + "diff_format_email_options": { + "ignore": true + }, + "diff_perfdata": { + "cDependencies": [ + "git2/sys/diff.h" + ] + }, + "diff_similarity_metric": { + "ignore": true + }, + "error_code": { + "values": { + "GIT_ERROR": { + "JsName": "ERROR" + } } }, - "fields": { - "initialize": { - "ignore": true - }, - "shutdown": { - "ignore": true - }, - "check": { - "ignore": true + "filter": { + "functions": { + "git_filter_list_apply_to_blob": { + "ignore": true + }, + "git_filter_list_apply_to_data": { + "ignore": true + }, + "git_filter_list_apply_to_file": { + "ignore": true + }, + "git_filter_list_free": { + "ignore": true + }, + "git_filter_list_load": { + "ignore": true + }, + "git_filter_list_push": { + "ignore": true + }, + "git_filter_source_filemode": { + "ignore": true + }, + "git_filter_source_id": { + "ignore": true + }, + "git_filter_source_mode": { + "ignore": true + }, + "git_filter_source_options": { + "ignore": true + }, + "git_filter_source_path": { + "ignore": true + }, + "git_filter_source_repo": { + "ignore": true + } }, - "apply": { - "ignore": true + "fields": { + "initialize": { + "ignore": true + }, + "shutdown": { + "ignore": true + }, + "check": { + "ignore": true + }, + "apply": { + "ignore": true + }, + "cleanup": { + "ignore": true + } }, - "cleanup": { - "ignore": true - } + "cDependencies": [ + "git2/sys/filter.h" + ] }, - "cDependencies": [ - "git2/sys/filter.h" - ] - }, - "filter_source": { - "ignore": true - }, - "graph": { - "functions": { - "git_graph_ahead_behind": { - "ignore": true - } - } - }, - "ignore": { - "functions": { - "git_ignore_path_is_ignored": { - "ignore": true + "filter_source": { + "ignore": true + }, + "graph": { + "functions": { + "git_graph_ahead_behind": { + "ignore": true + } } - } - }, - "index": { - "functions": { - "git_index_add_all": { - "ignore": true - }, - "git_index_add_bypath": { - "jsFunctionName": "addByPath" - }, - "git_index_conflict_get": { - "ignore": true - }, - "git_index_conflict_iterator_free": { - "ignore": true - }, - "git_index_conflict_iterator_new": { - "ignore": true - }, - "git_index_conflict_next": { - "ignore": true - }, - "git_index_entrycount": { - "jsFunctionName": "size" - }, - "git_index_find": { - "ignore": true - }, - "git_index_free": { - "ignore": true - }, - "git_index_get_byindex": { - "jsFunctionName": "entry" - }, - "git_index_new": { - "ignore": true - }, - "git_index_read": { - "args": { - "force": { - "isOptional": true - } + }, + "ignore": { + "functions": { + "git_ignore_path_is_ignored": { + "ignore": true } - }, - "git_index_remove_all": { - "ignore": true - }, - "git_index_remove_bypath": { - "jsFunctionName": "removeByPath" - }, - "git_index_update_all": { - "ignore": true - }, - "git_index_write": { - "args": { - "force": { - "isOptional": true - } + } + }, + "index": { + "functions": { + "git_index_add_all": { + "ignore": true + }, + "git_index_add_bypath": { + "jsFunctionName": "addByPath" + }, + "git_index_conflict_get": { + "ignore": true + }, + "git_index_conflict_iterator_free": { + "ignore": true + }, + "git_index_conflict_iterator_new": { + "ignore": true + }, + "git_index_conflict_next": { + "ignore": true + }, + "git_index_entrycount": { + "jsFunctionName": "size" + }, + "git_index_find": { + "ignore": true + }, + "git_index_free": { + "ignore": true + }, + "git_index_get_byindex": { + "jsFunctionName": "entry" + }, + "git_index_new": { + "ignore": true + }, + "git_index_read": { + "args": { + "force": { + "isOptional": true + } + } + }, + "git_index_remove_all": { + "ignore": true + }, + "git_index_remove_bypath": { + "jsFunctionName": "removeByPath" + }, + "git_index_update_all": { + "ignore": true + }, + "git_index_write": { + "args": { + "force": { + "isOptional": true + } + } + }, + "git_index_write_tree_to": { + "ignore": true } - }, - "git_index_write_tree_to": { - "ignore": true } - } - }, - "index_entry": { - "ignore": false - }, - "indexer": { - "cType": "git_indexer", - "functions": { - "git_indexer_append": { - "ignore": true - }, - "git_indexer_new": { - "ignore": true + }, + "index_entry": { + "ignore": false + }, + "indexer": { + "cType": "git_indexer", + "functions": { + "git_indexer_append": { + "ignore": true + }, + "git_indexer_new": { + "ignore": true + } } - } - }, - "mempack": { - "functions": { - "git_mempack_new": { - "ignore": true - }, - "git_mempack_reset": { - "ignore": true + }, + "mempack": { + "functions": { + "git_mempack_new": { + "ignore": true + }, + "git_mempack_reset": { + "ignore": true + } } - } - }, - "merge": { - "functions": { - "git_merge": { - "ignore": true - }, - "git_merge_analysis": { - "ignore": true - }, - "git_merge_base": { - "ignore": true - }, - "git_merge_base_many": { - "ignore": true - }, - "git_merge_base_octopus": { - "ignore": true - }, - "git_merge_file": { - "ignore": true - }, - "git_merge_file_from_index": { - "ignore": true - }, - "git_merge_file_init_options": { - "ignore": true - }, - "git_merge_file_result_free": { - "ignore": true + }, + "merge": { + "functions": { + "git_merge": { + "ignore": true + }, + "git_merge_analysis": { + "ignore": true + }, + "git_merge_base": { + "ignore": true + }, + "git_merge_base_many": { + "ignore": true + }, + "git_merge_base_octopus": { + "ignore": true + }, + "git_merge_file": { + "ignore": true + }, + "git_merge_file_from_index": { + "ignore": true + }, + "git_merge_file_init_options": { + "ignore": true + }, + "git_merge_file_result_free": { + "ignore": true + } } - } - }, - "message": { - "functions": { - "git_message_prettify": { - "ignore": true + }, + "message": { + "functions": { + "git_message_prettify": { + "ignore": true + } } - } - }, - "note": { - "functions": { - "git_note_create": { - "args": { - "out": { - "shouldAlloc": true + }, + "note": { + "functions": { + "git_note_create": { + "args": { + "out": { + "shouldAlloc": true + } } + }, + "git_note_foreach": { + "ignore": true } - }, - "git_note_foreach": { - "ignore": true } - } - }, - "object": { - "functions": { - "git_object_short_id": { - "args": { - "out": { - "shouldAlloc": true + }, + "object": { + "functions": { + "git_object_short_id": { + "args": { + "out": { + "shouldAlloc": true + } } } } - } - }, - "odb": { - "functions": { - "git_odb_add_alternate": { - "ignore": true - }, - "git_odb_add_backend": { - "ignore": true - }, - "git_odb_backend_loose": { - "ignore": true - }, - "git_odb_backend_one_pack": { - "ignore": true - }, - "git_odb_backend_pack": { - "ignore": true - }, - "git_odb_exists": { - "ignore": true - }, - "git_odb_exists_prefix": { - "ignore": true - }, - "git_odb_foreach": { - "ignore": true - }, - "git_odb_get_backend": { - "ignore": true - }, - "git_odb_hash": { - "ignore": true - }, - "git_odb_hashfile": { - "ignore": true - }, - "git_odb_init_backend": { - "ignore": true - }, - "git_odb_new": { - "ignore": true - }, - "git_odb_num_backends": { - "ignore": true - }, - "git_odb_open_rstream": { - "ignore": true - }, - "git_odb_open_wstream": { - "ignore": true - }, - "git_odb_read_header": { - "ignore": true - }, - "git_odb_read_prefix": { - "ignore": true - }, - "git_odb_refresh": { - "ignore": true - }, - "git_odb_stream_finalize_write": { - "ignore": true - }, - "git_odb_stream_free": { - "ignore": true - }, - "git_odb_stream_read": { - "ignore": true - }, - "git_odb_stream_write": { - "ignore": true + }, + "odb": { + "functions": { + "git_odb_add_alternate": { + "ignore": true + }, + "git_odb_add_backend": { + "ignore": true + }, + "git_odb_backend_loose": { + "ignore": true + }, + "git_odb_backend_one_pack": { + "ignore": true + }, + "git_odb_backend_pack": { + "ignore": true + }, + "git_odb_exists": { + "ignore": true + }, + "git_odb_exists_prefix": { + "ignore": true + }, + "git_odb_foreach": { + "ignore": true + }, + "git_odb_get_backend": { + "ignore": true + }, + "git_odb_hash": { + "ignore": true + }, + "git_odb_hashfile": { + "ignore": true + }, + "git_odb_init_backend": { + "ignore": true + }, + "git_odb_new": { + "ignore": true + }, + "git_odb_num_backends": { + "ignore": true + }, + "git_odb_open_rstream": { + "ignore": true + }, + "git_odb_open_wstream": { + "ignore": true + }, + "git_odb_read_header": { + "ignore": true + }, + "git_odb_read_prefix": { + "ignore": true + }, + "git_odb_refresh": { + "ignore": true + }, + "git_odb_stream_finalize_write": { + "ignore": true + }, + "git_odb_stream_free": { + "ignore": true + }, + "git_odb_stream_read": { + "ignore": true + }, + "git_odb_stream_write": { + "ignore": true + }, + "git_odb_write": { + "args": { + "data": { + "cppClassName": "Wrapper", + "jsClassName": "Buffer" + } + } + }, + "git_odb_write_pack": { + "ignore": true + } + } + }, + "odb_backend": { + "fields": { + "foreach": { + "ignore": true + }, + "writepack": { + "ignore": true + } }, - "git_odb_write": { - "args": { - "data": { + "ignore": true + }, + "odb_object": { + "functions": { + "git_odb_object_data": { + "return": { "cppClassName": "Wrapper", "jsClassName": "Buffer" } } }, - "git_odb_write_pack": { - "ignore": true - } - } - }, - "odb_backend": { - "fields": { - "foreach": { - "ignore": true - }, - "writepack": { - "ignore": true - } + "dependencies": [ + "../include/wrapper.h", + "node_buffer.h" + ] }, - "ignore": true - }, - "odb_object": { - "functions": { - "git_odb_object_data": { - "return": { - "cppClassName": "Wrapper", - "jsClassName": "Buffer" - } - } + "odb_stream": { + "ignore": true }, - "dependencies": [ - "../include/wrapper.h", - "node_buffer.h" - ] - }, - "odb_stream": { - "ignore": true - }, - "odb_writepack": { - "ignore": true - }, - "oid": { - "shouldAlloc": true, - "functions": { - "git_oid_cpy": { - "ignore": true - }, - "git_oid_fmt": { - "ignore": true - }, - "git_oid_fromraw": { - "ignore": true - }, - "git_oid_fromstr": { - "jsFunctionName": "fromString", - "isAsync": false - }, - "git_oid_fromstrn": { - "ignore": true - }, - "git_oid_fromstrp": { - "ignore": true - }, - "git_oid_nfmt": { - "ignore": true - }, - "git_oid_pathfmt": { - "ignore": true - }, - "git_oid_shorten_add": { - "ignore": true - }, - "git_oid_shorten_free": { - "ignore": true - }, - "git_oid_shorten_new": { - "ignore": true + "odb_writepack": { + "ignore": true + }, + "oid": { + "shouldAlloc": true, + "functions": { + "git_oid_cpy": { + "ignore": true + }, + "git_oid_fmt": { + "ignore": true + }, + "git_oid_fromraw": { + "ignore": true + }, + "git_oid_fromstr": { + "jsFunctionName": "fromString", + "isAsync": false + }, + "git_oid_fromstrn": { + "ignore": true + }, + "git_oid_fromstrp": { + "ignore": true + }, + "git_oid_nfmt": { + "ignore": true + }, + "git_oid_pathfmt": { + "ignore": true + }, + "git_oid_shorten_add": { + "ignore": true + }, + "git_oid_shorten_free": { + "ignore": true + }, + "git_oid_shorten_new": { + "ignore": true + }, + "git_oid_tostr": { + "ignore": true, + "jsFunctionName": "toString" + } }, - "git_oid_tostr": { - "ignore": true, - "jsFunctionName": "toString" + "fields": { + "id": { + "ignore": true + } } }, - "fields": { - "id": { - "ignore": true - } - } - }, - "packbuilder": { - "functions": { - "git_packbuilder_foreach": { - "ignore": true - }, - "git_packbuilder_new": { - "ignore": true - }, - "git_packbuilder_set_callbacks": { - "ignore": true - }, - "git_packbuilder_write": { - "ignore": true + "packbuilder": { + "functions": { + "git_packbuilder_foreach": { + "ignore": true + }, + "git_packbuilder_new": { + "ignore": true + }, + "git_packbuilder_set_callbacks": { + "ignore": true + }, + "git_packbuilder_write": { + "ignore": true + } } - } - }, - "patch": { - "functions": { - "git_patch_free": { - "ignore": true - }, - "git_patch_from_buffers": { - "ignore": true - }, - "git_patch_from_diff": { - "isAsync": false - }, - "git_patch_get_hunk": { - "args": { - "out": { - "returnName": "hunk" + }, + "patch": { + "functions": { + "git_patch_free": { + "ignore": true + }, + "git_patch_from_buffers": { + "ignore": true + }, + "git_patch_from_diff": { + "isAsync": false + }, + "git_patch_get_hunk": { + "args": { + "out": { + "returnName": "hunk" + }, + "lines_in_hunk": { + "isReturn": true + } }, - "lines_in_hunk": { - "isReturn": true - } + "isAsync": false }, - "isAsync": false - }, - "git_patch_get_line_in_hunk": { - "isAsync": false - }, - "git_patch_line_stats": { - "ignore": true - }, - "git_patch_print": { - "ignore": true - }, - "git_patch_to_buf": { - "ignore": true + "git_patch_get_line_in_hunk": { + "isAsync": false + }, + "git_patch_line_stats": { + "ignore": true + }, + "git_patch_print": { + "ignore": true + }, + "git_patch_to_buf": { + "ignore": true + } } - } - }, - "pathspec": { - "functions": { - "git_pathspec_new": { - "ignore": true + }, + "pathspec": { + "functions": { + "git_pathspec_new": { + "ignore": true + } } - } - }, - "push": { - "cType": "git_push", - "functions": { - "git_push_new": { - "ignore": true - }, - "git_push_set_callbacks": { - "ignore": true - }, - "git_push_status_foreach": { - "ignore": true + }, + "push": { + "cType": "git_push", + "functions": { + "git_push_new": { + "ignore": true + }, + "git_push_set_callbacks": { + "ignore": true + }, + "git_push_status_foreach": { + "ignore": true + } } - } - }, - "refdb": { - "functions": { - "git_refdb_backend_fs": { - "ignore": true - }, - "git_refdb_init_backend": { - "ignore": true - }, - "git_refdb_set_backend": { - "ignore": true - }, - "git_refdb_new": { - "ignore": true + }, + "refdb": { + "functions": { + "git_refdb_backend_fs": { + "ignore": true + }, + "git_refdb_init_backend": { + "ignore": true + }, + "git_refdb_set_backend": { + "ignore": true + }, + "git_refdb_new": { + "ignore": true + } } - } - }, - "refdb_backend": { - "ignore": true - }, - "reference": { - "cppClassName": "GitRefs", - "jsClassName": "Refs", - "functions": { - "git_reference__alloc": { - "ignore": true - }, - "git_reference__alloc_symbolic": { - "ignore": true - }, - "git_reference_foreach": { - "ignore": true - }, - "git_reference_foreach_glob": { - "ignore": true - }, - "git_reference_foreach_name": { - "ignore": true - }, - "git_reference_free": { - "ignore": true - }, - "git_reference_iterator_free": { - "ignore": true - }, - "git_reference_iterator_glob_new": { - "ignore": true - }, - "git_reference_iterator_new": { - "ignore": true - }, - "git_reference_list": { - "args": { - "array": { - "isReturn": true, - "shouldAlloc": true, - "cppClassName": "Array", - "jsClassName": "Array", - "size": "count", - "key": "strings" - } + }, + "refdb_backend": { + "ignore": true + }, + "reference": { + "cppClassName": "GitRefs", + "jsClassName": "Refs", + "functions": { + "git_reference__alloc": { + "ignore": true }, - "isAsync": true - }, - "git_reference_next": { - "ignore": true - }, - "git_reference_next_name": { - "ignore": true + "git_reference__alloc_symbolic": { + "ignore": true + }, + "git_reference_foreach": { + "ignore": true + }, + "git_reference_foreach_glob": { + "ignore": true + }, + "git_reference_foreach_name": { + "ignore": true + }, + "git_reference_free": { + "ignore": true + }, + "git_reference_iterator_free": { + "ignore": true + }, + "git_reference_iterator_glob_new": { + "ignore": true + }, + "git_reference_iterator_new": { + "ignore": true + }, + "git_reference_list": { + "args": { + "array": { + "isReturn": true, + "shouldAlloc": true, + "cppClassName": "Array", + "jsClassName": "Array", + "size": "count", + "key": "strings" + } + }, + "isAsync": true + }, + "git_reference_next": { + "ignore": true + }, + "git_reference_next_name": { + "ignore": true + } } - } - }, - "reference_iterator": { - "cDependencies": [ - "git2/sys/refdb_backend.h" - ], - "needsForwardDeclaration": false, - "ignore": true - }, - "refspec": { - "cType": "git_refspec", - "functions": { - "git_refspec_rtransform": { - "ignore": true - }, - "git_refspec_string": { - "ignore": true - }, - "git_refspec_transform": { - "ignore": true + }, + "reference_iterator": { + "cDependencies": [ + "git2/sys/refdb_backend.h" + ], + "needsForwardDeclaration": false, + "ignore": true + }, + "refspec": { + "cType": "git_refspec", + "functions": { + "git_refspec_rtransform": { + "ignore": true + }, + "git_refspec_string": { + "ignore": true + }, + "git_refspec_transform": { + "ignore": true + } } - } - }, - "remote": { - "cType": "git_remote", - "functions": { - "git_remote_default_branch": { - "ignore": true - }, - "git_remote_get_callbacks": { - "ignore": true - }, - "git_remote_get_fetch_refspecs": { - "ignore": true - }, - "git_remote_get_push_refspecs": { - "ignore": true - }, - "git_remote_list": { - "args": { - "out": { - "shouldAlloc": true + }, + "remote": { + "cType": "git_remote", + "functions": { + "git_remote_default_branch": { + "ignore": true + }, + "git_remote_get_callbacks": { + "ignore": true + }, + "git_remote_get_fetch_refspecs": { + "ignore": true + }, + "git_remote_get_push_refspecs": { + "ignore": true + }, + "git_remote_list": { + "args": { + "out": { + "shouldAlloc": true + } } + }, + "git_remote_ls": { + "ignore": true + }, + "git_remote_rename": { + "ignore": true } - }, - "git_remote_ls": { - "ignore": true - }, - "git_remote_rename": { - "ignore": true } - } - }, - "remote_callbacks": { - "fields": { - "completion": { - "ignore": true - }, - "sideband_progress": { - "ignore": true - }, - "transfer_progress": { - "ignore": true - }, - "update_tips": { - "ignore": true - } - } - }, - "remote_head": { - "ignore": true - }, - "repository": { - "functions": { - "git_repository_discover": { - "ignore": true - }, - "git_repository_fetchhead_foreach": { - "ignore": true - }, - "git_repository_free": { - "ignore": true - }, - "git_repository_hashfile": { - "ignore": true - }, - "git_repository_mergehead_foreach": { - "ignore": true - }, - "git_repository_message": { - "ignore": true + }, + "remote_callbacks": { + "fields": { + "completion": { + "ignore": true + }, + "sideband_progress": { + "ignore": true + }, + "transfer_progress": { + "ignore": true + }, + "update_tips": { + "ignore": true + } } - } - }, - "revparse": { - "functions": { - "git_revparse": { - "ignore": true + }, + "remote_head": { + "ignore": true + }, + "repository": { + "functions": { + "git_repository_discover": { + "ignore": true + }, + "git_repository_fetchhead_foreach": { + "ignore": true + }, + "git_repository_free": { + "ignore": true + }, + "git_repository_hashfile": { + "ignore": true + }, + "git_repository_mergehead_foreach": { + "ignore": true + }, + "git_repository_message": { + "ignore": true + } } - } - }, - "revspec": { - "ignore": true - }, - "revwalk": { - "functions": { - "git_revwalk_add_hide_cb": { - "ignore": true - }, - "git_revwalk_free": { - "ignore": true - }, - "git_revwalk_new": { - "isAsync": false + }, + "revparse": { + "functions": { + "git_revparse": { + "ignore": true + } } - } - }, - "signature": { - "functions": { - "git_signature_new": { - "isAsync": false + }, + "revspec": { + "ignore": true + }, + "revwalk": { + "functions": { + "git_revwalk_add_hide_cb": { + "ignore": true + }, + "git_revwalk_free": { + "ignore": true + }, + "git_revwalk_new": { + "isAsync": false + } } - } - }, - "smart": { - "functions": { - "git_smart_subtransport_git": { - "ignore": true - }, - "git_smart_subtransport_http": { - "ignore": true - }, - "git_smart_subtransport_ssh": { - "ignore": true + + }, + "signature": { + "functions": { + "git_signature_new": { + "isAsync": false + } + } + }, + "smart": { + "functions": { + "git_smart_subtransport_git": { + "ignore": true + }, + "git_smart_subtransport_http": { + "ignore": true + }, + "git_smart_subtransport_ssh": { + "ignore": true + } } - } - }, - "stash": { - "functions": { - "git_stash_foreach": { - "ignore": true + }, + "stash": { + "functions": { + "git_stash_foreach": { + "ignore": true + } } - } - }, - "status": { - "cDependencies": [ - "git2/sys/diff.h" - ], - "functions": { - "git_status_byindex": { - "ignore": true - }, - "git_status_foreach": { - "ignore": true - }, - "git_status_foreach_ext": { - "ignore": true - }, - "git_status_init_options": { - "ignore": true - }, - "git_status_list_new": { - "ignore": true + }, + "status": { + "cDependencies": [ + "git2/sys/diff.h" + ], + "functions": { + "git_status_byindex": { + "ignore": true + }, + "git_status_foreach": { + "ignore": true + }, + "git_status_foreach_ext": { + "ignore": true + }, + "git_status_init_options": { + "ignore": true + }, + "git_status_list_new": { + "ignore": true + } } - } - }, - "submodule": { - "functions": { - "git_submodule_foreach": { - "ignore": true - }, - "git_submodule_location": { - "ignore": true - }, - "git_submodule_status": { - "ignore": true + }, + "submodule": { + "functions": { + "git_submodule_foreach": { + "ignore": true + }, + "git_submodule_location": { + "ignore": true + }, + "git_submodule_status": { + "ignore": true + } } - } - }, - "tag": { - "functions": { - "git_tag_foreach": { - "ignore": true - }, - "git_tag_target": { - "args": { - "target_out": { - "isReturn": true + }, + "tag": { + "functions": { + "git_tag_foreach": { + "ignore": true + }, + "git_tag_target": { + "args": { + "target_out": { + "isReturn": true + } } } } - } - }, - "trace": { - "functions": { - "git_trace_set": { - "ignore": true + }, + "trace": { + "functions": { + "git_trace_set": { + "ignore": true + } } - } - }, - "transport": { - "cType": "git_transport", - "functions": { - "git_transport_dummy": { - "ignore": true - }, - "git_transport_local": { - "ignore": true - }, - "git_transport_new": { - "ignore": true - }, - "git_transport_register": { - "ignore": true - }, - "git_transport_smart": { - "ignore": true + }, + "transport": { + "cType": "git_transport", + "functions": { + "git_transport_dummy": { + "ignore": true + }, + "git_transport_local": { + "ignore": true + }, + "git_transport_new": { + "ignore": true + }, + "git_transport_register": { + "ignore": true + }, + "git_transport_smart": { + "ignore": true + } } - } - }, - "tree": { - "functions": { - "git_tree_walk": { - "ignore": true + }, + "tree": { + "functions": { + "git_tree_walk": { + "ignore": true + } } - } - }, - "treebuilder": { - "functions": { - "git_treebuilder_filter": { - "ignore": true + }, + "treebuilder": { + "functions": { + "git_treebuilder_filter": { + "ignore": true + } } } } diff --git a/generate/index.js b/generate/index.js index 0a27e7232..ce8d558e4 100644 --- a/generate/index.js +++ b/generate/index.js @@ -28,7 +28,8 @@ var templates = { class_header: file.read("templates/class_header.h"), struct_header: file.read("templates/struct_header.h"), binding: file.read("templates/binding.gyp"), - nodegit: file.read("templates/nodegit.cc") + nodegit: file.read("templates/nodegit.cc"), + enums: file.read("templates/enums.js") }; var filters = { @@ -71,17 +72,8 @@ Object.keys(partials).forEach(function(partial) { // Determine which definitions to actually include in the source code. +// This might not be needed anymore but to be frank I'm not totally positive var enabled = idefs.filter(function(idef) { - // Additionally provide a friendly name to the actual filename. - idef.name = path.basename(idef.filename, ".h"); - - // We need some custom data on each of the functions - idef.functions.forEach(function(fn) { - if (fn) { - fn.cppClassName = idef.cppClassName; - } - }); - return !idef.ignore; }); @@ -94,20 +86,43 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { file.write("../binding.gyp", templates.binding.render(enabled)); file.write("../src/nodegit.cc", templates.nodegit.render(enabled)); + // Write out all the classes. + var enums = []; enabled.forEach(function(idef) { try { - if (idef.hasConstructor) { + + if (idef.type == "struct") { file.write("../src/" + idef.filename + ".cc", templates.struct_content.render(idef)); file.write("../include/" + idef.filename + ".h", templates.struct_header.render(idef)); } - else { + else if (idef.type == "class") { file.write("../src/" + idef.filename + ".cc", templates.class_content.render(idef)); file.write("../include/" + idef.filename + ".h", templates.class_header.render(idef)); } + else if (idef.type == "enum") { + enums.push(idef); + } } catch (e) { console.log(e); } }); + + enums = enums.reduce(function(memo, enumerable) { + + memo[enumerable.owner] = memo[enumerable.owner] || []; + + memo[enumerable.owner].push(enumerable); + delete enumerable.owner; + return memo; + }, {}); + + + var output = []; + Object.keys(enums).forEach(function(key) { + output.push({owner: key, enums: enums[key]}); + }); + + file.write("../lib/enums.js", templates.enums.render(output)); }); diff --git a/generate/setup.js b/generate/setup.js index b612533f7..25b99d705 100644 --- a/generate/setup.js +++ b/generate/setup.js @@ -19,8 +19,9 @@ Array.prototype.push.apply(libgit2.types, supplement.new.types); Array.prototype.push.apply(libgit2.groups, supplement.new.groups); var output = []; -var groupNames = []; var dependencyLookup = {}; +var types = []; +var enums = []; // reduce all of the groups into a hashmap and a name array for easy lookup var groups = libgit2.groups.reduce(function(memo, group) { @@ -35,42 +36,68 @@ var groups = libgit2.groups.reduce(function(memo, group) { !~supplement.remove[groupName].functions.indexOf(fnName); }); - functionNames.typeName = groupName; memo[groupName] = functionNames; - groupNames.push(groupName); return memo; }, {}); -// Process each type in the types array into classes and structs and -// decorate the definitions with required data to build the C++ files + +// Split each type from the array into classes/structs and enums +// each entry is of type ['name', {definingobject}] libgit2.types.forEach(function(current) { - var typeName = current[0]; - var typeDefOverrides = descriptor[typeName] || {}; - var typeDef = current[1]; + current[1].typeName = current[0]; - // skip enums for now - if (typeDef.type === "enum") { - return; + // just log these out to a file for fun + if (current[1].type === "enum") { + enums.push(current[1]); + } + else { + types.push(current[1]); + } +}); + +var previous = ""; +enums = _(enums).sortBy("name").reduce(function(enumMemo, enumerable) { + if (previous == enumerable.typeName) { + console.log('WARNING: duplicate definition for enum ' + enumerable.typeName + + ". skipped."); + } + else if (!enumerable.fields) { + console.log('WARNING: incomplete definition for enum ' + enumerable.typeName + + ". skipped."); } + else { + enumMemo[enumerable.typeName] = { + typeName: enumerable.typeName.replace(/^git_/, "").replace(/_t$/, ""), + type: "enum", + cType: enumerable.typeName, + isMask: (/_t$/).test(enumerable.typeName), + values: enumerable.fields.map(function(field) { + return { + name: field.name, + value: field.value + } + }) + }; + } + + previous = enumerable.typeName; + return enumMemo; +}, {}).valueOf(); +// decorate the definitions with required data to build the C++ files +types.forEach(function(typeDef) { + var typeName = typeDef.typeName; typeDef.cType = typeName; typeName = typeName.replace("git_", ""); typeDef.typeName = typeName; dependencyLookup[typeName] = typeName; - typeDef.isClass = utils.isClass(typeName, groupNames); - typeDef.isStruct = !typeDef.isClass; + typeDef.functions = groups[typeName] || []; + utils.decoratePrimaryType(typeDef, enums); - utils.decoratePrimaryType(typeDef); + groups[typeName] = false; - if (typeDef.isClass) { - typeDef.functions = groups[typeName]; - utils.decorateClass(typeDef); - groups[typeName] = false; - } - else { - utils.decorateStruct(typeDef); - } + typeDef.type = typeDef.hasConstructor ? "struct" : "class"; output.push(typeDef); }); @@ -86,14 +113,11 @@ for (var groupName in groups) { functions: groupDef }; - var classDefOverrides = descriptor[groupName] || {}; - groupDef.isClass = true; - groupDef.isStruct = false; + groupDef.type = "class"; groupDef.typeName = groupName; dependencyLookup[groupName] = groupName; - utils.decoratePrimaryType(groupDef); - utils.decorateClass(groupDef, classDefOverrides); + utils.decoratePrimaryType(groupDef, enums); output.push(groupDef); } @@ -130,8 +154,58 @@ output.forEach(function (def) { Object.keys(dependencies).forEach(function (dependencyFilename) { def.dependencies.push("../include/" + dependencyFilename + ".h"); }); + + // Additionally provide a friendly name to the actual filename. + def.name = path.basename(def.filename, ".h"); + + def.functions.forEach(function(fn) { + if (fn) { + fn.cppClassName = def.cppClassName; + } + }); }); +// Process enums +_(enums).forEach(function(enumerable) { + output.some(function(obj) { + if (enumerable.typeName.indexOf(obj.typeName) == 0) { + enumerable.owner = obj.jsClassName; + } + else if (enumerable.owner) { + return true; + } + }); + + var override = descriptor.enums[enumerable.typeName] || {}; + + enumerable.owner = enumerable.owner || "Enums"; + + enumerable.JsName = enumerable.typeName + .replace(new RegExp("^" + enumerable.owner.toLowerCase()), "") + .replace(/^_/, "") + .toUpperCase(); + + enumerable.values.forEach(function(value) { + value.JsName = value.name + .replace(/^GIT_/, "") + .replace(new RegExp("^" + enumerable.owner.toUpperCase()), "") + .replace(/^_/, "") + .replace(new RegExp("^" + enumerable.JsName), "") + .replace(/^_/, "") + .toUpperCase(); + + if (override.values && override.values[value.name]) { + _.merge(value, override.values[value.name]); + } + }); + + _.merge(enumerable, _.omit(override, ["values"])); + + output.push(enumerable); +}); + +output = _.sortBy(output, "typeName"); + if (process.argv[2] != "--documentation") { utils.filterDocumentation(output); } diff --git a/generate/utils.js b/generate/utils.js index 5f84a542b..cbc3e70b1 100644 --- a/generate/utils.js +++ b/generate/utils.js @@ -105,10 +105,6 @@ var Utils = { && ~cbField.name.indexOf(payloadName.replace("_payload", "")); }, - isClass: function(typeName, groupNames) { - return !!~groupNames.indexOf(typeName); - }, - getLibgitType: function(normalizedType, types) { var libgitType; @@ -153,7 +149,7 @@ var Utils = { } }, - decorateLibgitType: function(type, types) { + decorateLibgitType: function(type, types, enums) { var normalizedType = Utils.normalizeCtype(type.cType); var libgitType = Utils.getLibgitType(normalizedType, types); @@ -166,69 +162,52 @@ var Utils = { if (type.isEnum) { type.cppClassName = "Number"; type.jsClassName = "Number"; + if (enums[type.cType]) { + type.isMask = enums[type.cType].isMask || false + } } - - _.merge(type, descriptor[normalizedType.replace("git_", "")] || {}); + _.merge(type, descriptor.types[normalizedType.replace("git_", "")] || {}); } }, - decoratePrimaryType: function(typeDef) { - var typeDefOverrides = descriptor[typeDef.typeName] || {}; + decoratePrimaryType: function(typeDef, enums) { + var typeDefOverrides = descriptor.types[typeDef.typeName] || {}; var partialOverrides = _.omit(typeDefOverrides, ["fields", "functions"]); typeDef.cType = typeDef.cType || null; typeDef.cppClassName = Utils.cTypeToCppName(typeDef.cType || "git_" + typeDef.typeName); typeDef.jsClassName = Utils.titleCase(Utils.cTypeToJsName(typeDef.cType || "git_" + typeDef.typeName)); - - typeDef.dependencies = []; typeDef.filename = typeDef.typeName; + typeDef.isLibgitType = true; + typeDef.dependencies = []; typeDef.fields = typeDef.fields || []; - typeDef.fields.forEach(function (field, index, allFields) { var fieldOverrides = typeDefOverrides.fields || {}; - Utils.decorateField(field, allFields, fieldOverrides[field.name] || {}); + Utils.decorateField(field, allFields, fieldOverrides[field.name] || {}, enums); }); typeDef.needsForwardDeclaration = typeDef.decl === typeDef.cType; - _.merge(typeDef, partialOverrides); - }, - - decorateStruct: function(structDef) { - /* There are no enums for now, and when we get there I'm gonna argue they should have - their own process - if (structDef.type === "enum") { - structDef.isEnum = true; - structDef.cppClassName = "Number"; - structDef.jsClassName = "Number"; - } */ - - structDef.isLibgitType = true; - - // TODO: Structs don't *have* functions, we need to remove the code thats requiring this (if there even is any) - structDef.functions = []; - - var normalizedType = Utils.normalizeCtype(structDef.cType); - structDef.hasConstructor = Utils.hasConstructor(structDef, normalizedType); - }, - - decorateClass: function(classDef) { - var typeDefOverrides = descriptor[classDef.typeName] || {}; + var normalizedType = Utils.normalizeCtype(typeDef.cType); + typeDef.hasConstructor = Utils.hasConstructor(typeDef, normalizedType); - classDef.functions = (classDef.functions || []).map(function(fn) { + typeDef.functions = (typeDef.functions).map(function(fn) { var fnDef = libgit2.functions[fn]; fnDef.cFunctionName = fn; return fnDef; }); + var typeDefOverrides = descriptor.types[typeDef.typeName] || {}; var functionOverrides = typeDefOverrides.functions || {}; - classDef.functions.forEach(function(fnDef) { - Utils.decorateFunction(fnDef, classDef, functionOverrides[fnDef.cFunctionName] || {}); + typeDef.functions.forEach(function(fnDef) { + Utils.decorateFunction(fnDef, typeDef, functionOverrides[fnDef.cFunctionName] || {}, enums); }); + + _.merge(typeDef, partialOverrides); }, - decorateField: function(field, allFields, fieldOverrides) { + decorateField: function(field, allFields, fieldOverrides, enums) { var normalizeType = Utils.normalizeCtype(field.type); field.cType = field.type; @@ -243,7 +222,7 @@ var Utils = { var argOverrides = fieldOverrides.args || {}; field.args = field.args || []; field.args.forEach(function (arg) { - Utils.decorateArg(arg, null, null, argOverrides[arg.name] || {}); + Utils.decorateArg(arg, null, null, argOverrides[arg.name] || {}, enums); }); } else { @@ -254,11 +233,11 @@ var Utils = { } } - Utils.decorateLibgitType(field, libgit2.types); + Utils.decorateLibgitType(field, libgit2.types, enums); _.merge(field, fieldOverrides); }, - decorateArg: function(arg, classDef, fnDef, argOverrides) { + decorateArg: function(arg, typeDef, fnDef, argOverrides, enums) { var type = arg.cType || arg.type; var normalizedType = Utils.normalizeCtype(type); @@ -266,14 +245,14 @@ var Utils = { arg.cppClassName = Utils.cTypeToCppName(arg.cType); arg.jsClassName = Utils.titleCase(Utils.cTypeToJsName(arg.cType)); - Utils.decorateLibgitType(arg, libgit2.types); + Utils.decorateLibgitType(arg, libgit2.types, enums); - if (classDef && fnDef) { + if (typeDef && fnDef) { // Mark all of the args that are either returns or are the object // itself and determine if this function goes on the prototype // or is a constructor method. - arg.isReturn = arg.name === "out" || (Utils.isDoublePointer(arg.type) && normalizedType == classDef.cType); - arg.isSelf = Utils.isPointer(arg.type) && normalizedType == classDef.cType; + arg.isReturn = arg.name === "out" || (Utils.isDoublePointer(arg.type) && normalizedType == typeDef.cType); + arg.isSelf = Utils.isPointer(arg.type) && normalizedType == typeDef.cType; if (arg.isReturn && fnDef.return && fnDef.return.type === "int") { fnDef.return.isErrorCode = true; @@ -292,34 +271,34 @@ var Utils = { _.merge(arg, argOverrides); }, - decorateFunction: function(fnDef, classDef, fnOverrides) { + decorateFunction: function(fnDef, typeDef, fnOverrides, enums) { var key = fnDef.cFunctionName; // if this is the free function for the class, make the ref on the class // and then return since we don't want the free functions publicly // available - if (key == classDef.cType + "_free") { - classDef.freeFunctionName = key; + if (key == typeDef.cType + "_free") { + typeDef.freeFunctionName = key; fnDef.ignore = true; return; } - fnDef.cppFunctionName = Utils.cTypeToCppName(key, "git_" + classDef.typeName); - fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + classDef.typeName); + fnDef.cppFunctionName = Utils.cTypeToCppName(key, "git_" + typeDef.typeName); + fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + typeDef.typeName); //fnDef.isAsync = false; // until proven otherwise - if (fnDef.cppFunctionName == classDef.cppClassName) { + if (fnDef.cppFunctionName == typeDef.cppClassName) { fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", ""); } var argOverrides = fnOverrides.args || {}; fnDef.args.forEach(function(arg) { - Utils.decorateArg(arg, classDef, fnDef, argOverrides[arg.name] || {}); + Utils.decorateArg(arg, typeDef, fnDef, argOverrides[arg.name] || {}, enums); }); if (fnDef.return) { - Utils.decorateArg(fnDef.return, classDef, fnDef, fnOverrides.return || {}); + Utils.decorateArg(fnDef.return, typeDef, fnDef, fnOverrides.return || {}, enums); } _(collisionMappings).forEach(function(newName, collidingName) { @@ -336,6 +315,9 @@ var Utils = { }, filterIgnored: function (arr, callback) { + if (!arr) { + return; + } for (var i = arr.length - 1; i >= 0; i--) { if (arr[i].ignore) { arr.splice(i, 1); diff --git a/lib/nodegit.js b/lib/nodegit.js index 0468cee47..d02041af9 100644 --- a/lib/nodegit.js +++ b/lib/nodegit.js @@ -63,6 +63,9 @@ require("./signature"); require("./tree"); require("./tree_entry"); +//must go last! +require("./enums"); + // Wrap asynchronous methods to return promises. promisify(exports); From a9195fc7173c17ca4bd0eea169ec1a0b255e09da Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 13:52:42 -0700 Subject: [PATCH 5/5] fix issue with missing cType for group based classes --- generate/setup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/generate/setup.js b/generate/setup.js index 25b99d705..4b9c12274 100644 --- a/generate/setup.js +++ b/generate/setup.js @@ -114,6 +114,7 @@ for (var groupName in groups) { }; groupDef.type = "class"; + groupDef.cType = (descriptor.types[groupName] || {}).cType || groupDef.cType; groupDef.typeName = groupName; dependencyLookup[groupName] = groupName;