Skip to content

Commit d4981f0

Browse files
Fix issues with index entries
1 parent ee48c70 commit d4981f0

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

generate/input/descriptor.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,11 +1881,19 @@
18811881
"git_index_free": {
18821882
"ignore": true
18831883
},
1884+
"git_index_get_byindex": {
1885+
"return": {
1886+
"ownedByThis": true
1887+
}
1888+
},
18841889
"git_index_get_bypath": {
18851890
"args": {
18861891
"stage": {
18871892
"isOptional": true
18881893
}
1894+
},
1895+
"return": {
1896+
"ownedByThis": true
18891897
}
18901898
},
18911899
"git_index_new": {
@@ -2035,9 +2043,11 @@
20352043
},
20362044
"index_entry": {
20372045
"dependencies": [
2046+
"../include/functions/copy.h",
20382047
"../include/functions/free.h"
20392048
],
20402049
"freeFunctionName": "git_index_entry_free",
2050+
"dupFunction": "git_index_entry_dup",
20412051
"isReturnable": true,
20422052
"hasConstructor": true,
20432053
"ignoreInit": true

generate/templates/manual/include/functions/copy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
const git_error *git_error_dup(const git_error *arg);
1111
const git_oid *git_oid_dup(const git_oid *arg);
12-
const git_index_entry *git_index_entry_dup(const git_index_entry *arg);
1312
const git_index_time *git_index_time_dup(const git_index_time *arg);
1413
const git_time *git_time_dup(const git_time *arg);
1514
const git_diff_delta *git_diff_delta_dup(const git_diff_delta *arg);
@@ -19,5 +18,6 @@ git_remote_head *git_remote_head_dup(const git_remote_head *src);
1918

2019
void git_time_dup(git_time **out, const git_time *arg);
2120
void git_transfer_progress_dup(git_transfer_progress **out, const git_transfer_progress *arg);
21+
void git_index_entry_dup(git_index_entry **dest, const git_index_entry *src);
2222

2323
#endif

generate/templates/manual/include/functions/free.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
void git_remote_head_free(git_remote_head *remote_head);
1111
void git_diff_line_free(const git_diff_line *diff_line);
12-
void git_index_entry_free(git_index_entry *index_entry);
12+
void git_index_entry_free(const git_index_entry *index_entry);
1313

1414
#endif

generate/templates/manual/src/functions/copy.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "git2.h"
55
#include "git2/diff.h"
66

7+
#include<iostream>
8+
79
const git_error *git_error_dup(const git_error *arg) {
810
git_error *result = (git_error *)malloc(sizeof(git_error));
911
result->klass = arg->klass;
@@ -35,3 +37,11 @@ git_remote_head *git_remote_head_dup(const git_remote_head *src) {
3537
: NULL;
3638
return dest;
3739
}
40+
41+
void git_index_entry_dup(git_index_entry **dest, const git_index_entry *src) {
42+
*dest = (git_index_entry *)malloc(sizeof(git_index_entry));
43+
memcpy(*dest, src, sizeof(git_index_entry));
44+
(*dest)->path = src->path
45+
? strdup(src->path)
46+
: NULL;
47+
}

generate/templates/manual/src/functions/free.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cstring>
22

33
#include "git2.h"
4+
#include<iostream>
45

56
void git_remote_head_free(git_remote_head *remote_head) {
67
free(remote_head->name);
@@ -13,7 +14,7 @@ void git_diff_line_free(const git_diff_line *diff_line) {
1314
free((void*) diff_line);
1415
}
1516

16-
void git_index_entry_free(git_index_entry *index_entry) {
17+
void git_index_entry_free(const git_index_entry *index_entry) {
1718
free((void*)(index_entry->path));
1819
free((void*) index_entry);
1920
}

generate/templates/partials/field_accessors.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
{% elsif field.cppClassName == 'String' %}
5757
if (wrapper->GetValue()->{{ field.name }}) {
58+
free((void*)wrapper->GetValue()->{{ field.name }});
5859
}
5960

6061
Nan::Utf8String str(value);

generate/templates/partials/sync_function.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,7 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
115115
free((void *)from_{{ arg.name }});
116116
{%endif%}
117117
{%endif%}
118-
{%if not arg.shouldAlloc %}
119-
{%if arg.ownedByThis|and arg.dupFunction|and arg.freeFunctionName|and arg.isReturn|and arg.selfFreeing %}
120-
// We need to free duplicated memory we are responsible for that we obtained from libgit2 because
121-
// nodegit duplicates it again when calling the wrapper
122-
if(from_{{ arg.name }} != NULL) {
123-
{{ arg.freeFunctionName }}(from_{{ arg.name }});
124-
}
125-
{%endif%}
126-
{%elsif arg.isReturn %}
118+
{%if arg.shouldAlloc|and arg.isReturn %}
127119
{%if not arg.selfFreeing %}
128120
{%if arg.cppClassName == "GitBuf" %}
129121
{%else%}

0 commit comments

Comments
 (0)