Skip to content

Commit e1235bd

Browse files
author
John Haley
committed
Enabled git_index_add_all
1 parent 2b62791 commit e1235bd

File tree

8 files changed

+118
-5
lines changed

8 files changed

+118
-5
lines changed

generate/input/descriptor.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,21 @@
727727
"index": {
728728
"functions": {
729729
"git_index_add_all": {
730-
"ignore": true
730+
"args": {
731+
"pathspec": {
732+
"isOptional": true
733+
},
734+
"flags": {
735+
"isOptional": true
736+
},
737+
"callback": {
738+
"isOptional": true
739+
}
740+
},
741+
"isAsync": true,
742+
"return": {
743+
"isErrorCode": true
744+
}
731745
},
732746
"git_index_conflict_get": {
733747
"ignore": true
@@ -780,7 +794,10 @@
780794
}
781795
}
782796
}
783-
}
797+
},
798+
"dependencies": [
799+
"../include/str_array_converter.h"
800+
]
784801
},
785802
"index_entry": {
786803
"ignore": false

generate/scripts/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ var Helpers = {
244244
if (Helpers.isCallbackFunction(type)) {
245245
Helpers.processCallback(arg);
246246

247-
var argOverrides = argOverrides.args || {};
247+
var callBackArgOverrides = argOverrides.args || {};
248248
arg.args = arg.args || [];
249249
arg.args.forEach(function (argForCallback) {
250-
Helpers.decorateArg(argForCallback, arg.args, null, null, argOverrides[argForCallback.name] || {}, enums);
250+
Helpers.decorateArg(argForCallback, arg.args, null, null, callBackArgOverrides[argForCallback.name] || {}, enums);
251251
});
252252
}
253253
else if (typeDef && fnDef) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef STR_ARRAY_H
2+
#define STR_ARRAY_H
3+
4+
#include <v8.h>
5+
6+
#include "nan.h"
7+
#include "git2/strarray.h"
8+
9+
using namespace v8;
10+
11+
class StrArrayConverter {
12+
public:
13+
14+
static git_strarray *Convert (Handle<v8::Value> val);
15+
16+
private:
17+
static git_strarray *ConvertArray(Array *val);
18+
static git_strarray *ConvertString(Handle<String> val);
19+
static git_strarray *ConstructStrArray(int argc, char** argv);
20+
};
21+
22+
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <nan.h>
2+
#include <node.h>
3+
#include <string>
4+
#include <cstring>
5+
6+
#include "../include/str_array_converter.h"
7+
#include "git2/strarray.h"
8+
9+
using namespace v8;
10+
using namespace node;
11+
12+
git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
13+
if (!val->BooleanValue()) {
14+
return NULL;
15+
}
16+
else if (val->IsArray()) {
17+
return ConvertArray(Array::Cast(*val));
18+
}
19+
else if (val->IsString() || val->IsStringObject()) {
20+
return ConvertString(val->ToString());
21+
}
22+
else {
23+
return NULL;
24+
}
25+
}
26+
27+
git_strarray *StrArrayConverter::ConvertArray(Array *val) {
28+
int count = val->Length();
29+
char *strings[count];
30+
31+
for(int i = 0; i < count; i++) {
32+
NanUtf8String entry(val->CloneElementAt(i));
33+
strings[i] = *entry;
34+
}
35+
36+
return ConstructStrArray(count, strings);
37+
}
38+
39+
git_strarray* StrArrayConverter::ConvertString(Handle<String> val) {
40+
char *strings[1];
41+
NanUtf8String utf8String(val);
42+
43+
strings[0] = *utf8String;
44+
45+
return ConstructStrArray(1, strings);
46+
}
47+
48+
git_strarray *StrArrayConverter::ConstructStrArray(int argc, char** argv) {
49+
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
50+
result->count = argc;
51+
result->strings = (char **)malloc(sizeof(char*) * result->count);
52+
53+
for(size_t i = 0; i < result->count; i++) {
54+
result->strings[i] = strdup(argv[i]);
55+
}
56+
57+
return result;
58+
}

generate/templates/partials/convert_from_v8.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
{{ cType }} from_{{ name }};
44
{%if isOptional | or isBoolean %}
55

6+
{%if cppClassName != 'GitStrarray'%}
67
if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) {
8+
{%endif%}
79
{%endif%}
810
{%if cppClassName == 'String'%}
911

1012
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
1113
from_{{ name }} = ({{ cType }}) strdup(*{{ name }});
14+
{%elsif cppClassName == 'GitStrarray' %}
15+
16+
from_{{ name }} = StrArrayConverter::Convert(args[{{ jsArg }}]);
1217
{%elsif cppClassName == 'Wrapper'%}
1318

1419
String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString());
@@ -77,11 +82,12 @@
7782
from_{{ name }} = args[{{ jsArg }}]->IsTrue() ? 1 : 0;
7883
}
7984
{%elsif isOptional %}
85+
{%if cppClassName != 'GitStrarray'%}
8086
}
8187
else {
8288
from_{{ name }} = 0;
8389
}
84-
90+
{%endif%}
8591
{%endif%}
8692
// end convert_from_v8 block
8793
{%endif%}

generate/templates/partials/guard_arguments.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{%elsif arg.isCallbackFunction %}
1212
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->IsFunction()) {
1313
return NanThrowError("{{arg.jsClassName}} {{arg.name}} is required.");
14+
}
15+
{%elsif arg.cppClassName == "GitStrarray" %}
16+
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->BooleanValue()) {
17+
return NanThrowError("Array, String Object, or string {{arg.name}} is required.");
1418
}
1519
{%else%}
1620
if (args.Length() == {{arg.jsArg}} || !args[{{arg.jsArg}}]->Is{{arg.cppClassName|cppToV8}}()) {

generate/templates/templates/binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"src/nodegit.cc",
1414
"src/wrapper.cc",
1515
"src/functions/copy.cc",
16+
"src/str_array_converter.cc",
1617
{% each %}
1718
{% if type != "enum" %}
1819
"src/{{ name }}.cc",

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ Index.prototype.entries = function() {
1717
return result;
1818
};
1919

20+
var addAll = Index.prototype.addAll;
21+
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
22+
return addAll.call(this, pathspec, flags, matchedCallback, null);
23+
}
24+
2025
module.exports = Index;

0 commit comments

Comments
 (0)