Skip to content

Commit 92a570f

Browse files
authored
Merge pull request #1331 from mohseenrm/feature/git-filter
Adding git_filter support in nodegit
2 parents 2db5a2b + debcf21 commit 92a570f

21 files changed

+1624
-144
lines changed

generate/input/callbacks.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,102 @@
311311
"error": -1
312312
}
313313
},
314+
"git_filter_apply_fn": {
315+
"args": [
316+
{
317+
"name": "self",
318+
"cType": "git_filter *"
319+
},
320+
{
321+
"name": "payload",
322+
"cType": "void **"
323+
},
324+
{
325+
"name": "to",
326+
"cType": "git_buf *"
327+
},
328+
{
329+
"name": "from",
330+
"cType": "const git_buf *"
331+
},
332+
{
333+
"name": "src",
334+
"cType": "const git_filter_source *"
335+
}
336+
],
337+
"return": {
338+
"type": "int",
339+
"noResults": -30,
340+
"success": 0,
341+
"error": -1
342+
}
343+
},
344+
"git_filter_check_fn": {
345+
"args": [
346+
{
347+
"name": "self",
348+
"cType": "git_filter *"
349+
},
350+
{
351+
"name": "payload",
352+
"cType": "void **"
353+
},
354+
{
355+
"name": "src",
356+
"cType": "const git_filter_source *"
357+
},
358+
{
359+
"name": "attr_values",
360+
"cType": "const char **"
361+
}
362+
],
363+
"return": {
364+
"type": "int",
365+
"noResults": -30,
366+
"success": 0,
367+
"error": -1
368+
}
369+
},
370+
"git_filter_cleanup_fn": {
371+
"args": [
372+
{
373+
"name": "self",
374+
"cType": "git_filter *"
375+
},
376+
{
377+
"name": "payload",
378+
"cType": "void *"
379+
}
380+
],
381+
"return": {
382+
"type": "void"
383+
}
384+
},
385+
"git_filter_init_fn": {
386+
"args": [
387+
{
388+
"name": "self",
389+
"cType": "git_filter *"
390+
}
391+
],
392+
"return": {
393+
"type": "int",
394+
"noResults": 0,
395+
"success": 0,
396+
"error": -1
397+
}
398+
},
399+
"git_filter_shutdown_fn": {
400+
"args": [
401+
{
402+
"name": "self",
403+
"cType": "git_filter *"
404+
}
405+
],
406+
"return": {
407+
"type": "void"
408+
}
409+
},
314410
"git_index_matched_path_cb": {
315411
"args": [
316412
{

generate/input/descriptor.json

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,8 @@
879879
}
880880
},
881881
"filter": {
882+
"selfFreeing": false,
883+
"hasConstructor": true,
882884
"functions": {
883885
"git_filter_list_apply_to_blob": {
884886
"ignore": true
@@ -920,30 +922,21 @@
920922
"ignore": true
921923
}
922924
},
925+
"cDependencies": [
926+
"git2/sys/filter.h"
927+
],
923928
"fields": {
924-
"initialize": {
925-
"ignore": true
926-
},
927-
"shutdown": {
928-
"ignore": true
929-
},
930-
"check": {
931-
"ignore": true
932-
},
933-
"apply": {
934-
"ignore": true
935-
},
936-
"cleanup": {
929+
"stream": {
937930
"ignore": true
938931
}
939-
},
932+
}
933+
},
934+
"filter_source": {
935+
"ignore": false,
940936
"cDependencies": [
941937
"git2/sys/filter.h"
942938
]
943939
},
944-
"filter_source": {
945-
"ignore": true
946-
},
947940
"graph": {
948941
"functions": {
949942
"git_graph_ahead_behind": {

generate/input/libgit2-supplement.json

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@
273273
"git_annotated_commit_lookup"
274274
]
275275
],
276+
[
277+
"filter_source",
278+
[
279+
"git_filter_source_repo",
280+
"git_filter_source_path",
281+
"git_filter_source_filemode",
282+
"git_filter_source_id",
283+
"git_filter_source_mode",
284+
"git_filter_source_flags"
285+
]
286+
],
276287
[
277288
"odb_object",
278289
[
@@ -422,33 +433,23 @@
422433
},
423434
{
424435
"type": "git_filter_init_fn",
425-
"name": "initialize",
426-
"ignore": true
436+
"name": "initialize"
427437
},
428438
{
429439
"type": "git_filter_shutdown_fn",
430-
"name": "shutdown",
431-
"ignore": true
440+
"name": "shutdown"
432441
},
433442
{
434443
"type": "git_filter_check_fn",
435-
"name": "check",
436-
"ignore": true
444+
"name": "check"
437445
},
438446
{
439447
"type": "git_filter_apply_fn",
440-
"name": "apply",
441-
"ignore": true
442-
},
443-
{
444-
"type": "git_filter_stream_fn",
445-
"name": "stream",
446-
"ignore": true
448+
"name": "apply"
447449
},
448450
{
449451
"type": "git_filter_cleanup_fn",
450-
"name": "cleanup",
451-
"ignore": true
452+
"name": "cleanup"
452453
}
453454
]
454455
}
@@ -765,14 +766,26 @@
765766
"git_annotated_commit_lookup"
766767
]
767768
},
768-
"odb": {
769+
"filter": {
769770
"functions": [
770-
"git_odb_object_data",
771-
"git_odb_object_dup",
772-
"git_odb_object_free",
773-
"git_odb_object_id",
774-
"git_odb_object_size",
775-
"git_odb_object_type"
771+
"git_filter_list_apply_to_blob",
772+
"git_filter_list_apply_to_data",
773+
"git_filter_list_apply_to_file",
774+
"git_filter_list_contains",
775+
"git_filter_list_free",
776+
"git_filter_list_length",
777+
"git_filter_list_load",
778+
"git_filter_list_new",
779+
"git_filter_list_push",
780+
"git_filter_list_stream_blob",
781+
"git_filter_list_stream_data",
782+
"git_filter_list_stream_file",
783+
"git_filter_source_filemode",
784+
"git_filter_source_flags",
785+
"git_filter_source_id",
786+
"git_filter_source_mode",
787+
"git_filter_source_path",
788+
"git_filter_source_repo"
776789
]
777790
},
778791
"merge": {
@@ -784,6 +797,16 @@
784797
"git_merge_head_id"
785798
]
786799
},
800+
"odb": {
801+
"functions": [
802+
"git_odb_object_data",
803+
"git_odb_object_dup",
804+
"git_odb_object_free",
805+
"git_odb_object_id",
806+
"git_odb_object_size",
807+
"git_odb_object_type"
808+
]
809+
},
787810
"reflog": {
788811
"functions": [
789812
"git_reflog_entry_committer",

generate/scripts/generateJson.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,18 @@ module.exports = function generateJson() {
169169
}
170170
};
171171

172+
var addSelfReferentialField = function(prop){
173+
if (helpers.isSelfReferential(prop.type)) {
174+
prop.isSelfReferential = true;
175+
def.isExtendedStruct = true;
176+
}
177+
};
178+
172179
def.fields.forEach(addDependencies);
180+
def.fields.forEach(addSelfReferentialField);
173181
def.functions.forEach(addDependencies);
174182

183+
175184
Object.keys(dependencies).forEach(function (dependencyFilename) {
176185
def.dependencies.push("../include/" + dependencyFilename + ".h");
177186
});
@@ -183,7 +192,6 @@ module.exports = function generateJson() {
183192
fn.cppClassName = def.cppClassName;
184193
});
185194
});
186-
187195
// Process enums
188196
_(enums).forEach(function(enumerable) {
189197
output.some(function(obj) {

generate/scripts/generateNativeCode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ module.exports = function generateNativeCode() {
6868
replace: require("../templates/filters/replace"),
6969
returnsCount: require("../templates/filters/returns_count"),
7070
returnsInfo: require("../templates/filters/returns_info"),
71+
subtract: require("../templates/filters/subtract"),
7172
titleCase: require("../templates/filters/title_case"),
7273
toBool: require('../templates/filters/to_bool'),
7374
unPointer: require("../templates/filters/un_pointer"),
75+
setUnsigned: require("../templates/filters/unsigned"),
7476
upper: require("../templates/filters/upper")
7577
};
7678

generate/scripts/helpers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var callbackTypePattern = /\s*_cb/;
1+
var callbackTypePattern = /\s*_(cb|fn)/,
2+
selfReferentialTypePattern = /\s*_fn/;
23

34
var utils = require("./utils");
45
var _ = require("lodash");
@@ -93,6 +94,10 @@ var Helpers = {
9394
&& ~cbField.name.indexOf(payloadName.replace("_payload", ""));
9495
},
9596

97+
isSelfReferential: function(cType){
98+
return selfReferentialTypePattern.test(cType);
99+
},
100+
96101
getLibgitType: function(normalizedType, types) {
97102
var libgitType;
98103

generate/templates/filters/args_info.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ module.exports = function(args) {
1313
jsArg++;
1414
}
1515

16-
if (cArg === args.length -1) {
17-
arg.lastArg = true;
18-
}
19-
else {
20-
arg.lastArg = false;
21-
}
16+
arg.lastArg = cArg === args.length - 1;
17+
arg.firstArg = !arg.lastArg && cArg === 0;
2218

2319
arg.cArg = cArg;
2420
arg.isCppClassStringOrArray = ~["String", "Array"].indexOf(arg.cppClassName);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(value, other) {
2+
return value - other;
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(value) {
2+
return value < 0 ? 0 : value;
3+
};

generate/templates/manual/include/async_baton.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,38 @@ struct AsyncBatonWithResult : public AsyncBaton {
6060
}
6161
};
6262

63+
struct AsyncBatonWithNoResult : public AsyncBaton {
64+
void (*onCompletion)(AsyncBaton *);
65+
66+
void Done() {
67+
if (onCompletion) {
68+
onCompletion(this);
69+
} else {
70+
// signal completion
71+
uv_sem_post(&semaphore);
72+
}
73+
}
74+
75+
void ExecuteAsync(ThreadPool::Callback asyncCallback, void (*onCompletion)(AsyncBaton *) = NULL) {
76+
this->onCompletion = onCompletion;
77+
if (!onCompletion) {
78+
uv_sem_init(&semaphore, 0);
79+
}
80+
81+
{
82+
LockMaster::TemporaryUnlock temporaryUnlock;
83+
84+
libgit2ThreadPool.ExecuteReverseCallback(asyncCallback, this);
85+
86+
if (!onCompletion) {
87+
// wait for completion
88+
uv_sem_wait(&semaphore);
89+
uv_sem_destroy(&semaphore);
90+
}
91+
}
92+
93+
return;
94+
}
95+
};
96+
6397
#endif

0 commit comments

Comments
 (0)