Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issues with index entries
  • Loading branch information
julianmesa-gitkraken committed Oct 28, 2022
commit d4981f04261f34b98e5d78ff1b04fb59b5137819
10 changes: 10 additions & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1881,11 +1881,19 @@
"git_index_free": {
"ignore": true
},
"git_index_get_byindex": {
"return": {
"ownedByThis": true
}
},
"git_index_get_bypath": {
"args": {
"stage": {
"isOptional": true
}
},
"return": {
"ownedByThis": true
}
},
"git_index_new": {
Expand Down Expand Up @@ -2035,9 +2043,11 @@
},
"index_entry": {
"dependencies": [
"../include/functions/copy.h",
"../include/functions/free.h"
],
"freeFunctionName": "git_index_entry_free",
"dupFunction": "git_index_entry_dup",
"isReturnable": true,
"hasConstructor": true,
"ignoreInit": true
Expand Down
2 changes: 1 addition & 1 deletion generate/templates/manual/include/functions/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

const git_error *git_error_dup(const git_error *arg);
const git_oid *git_oid_dup(const git_oid *arg);
const git_index_entry *git_index_entry_dup(const git_index_entry *arg);
const git_index_time *git_index_time_dup(const git_index_time *arg);
const git_time *git_time_dup(const git_time *arg);
const git_diff_delta *git_diff_delta_dup(const git_diff_delta *arg);
Expand All @@ -19,5 +18,6 @@ git_remote_head *git_remote_head_dup(const git_remote_head *src);

void git_time_dup(git_time **out, const git_time *arg);
void git_transfer_progress_dup(git_transfer_progress **out, const git_transfer_progress *arg);
void git_index_entry_dup(git_index_entry **dest, const git_index_entry *src);

#endif
2 changes: 1 addition & 1 deletion generate/templates/manual/include/functions/free.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

void git_remote_head_free(git_remote_head *remote_head);
void git_diff_line_free(const git_diff_line *diff_line);
void git_index_entry_free(git_index_entry *index_entry);
void git_index_entry_free(const git_index_entry *index_entry);

#endif
10 changes: 10 additions & 0 deletions generate/templates/manual/src/functions/copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "git2.h"
#include "git2/diff.h"

#include<iostream>

const git_error *git_error_dup(const git_error *arg) {
git_error *result = (git_error *)malloc(sizeof(git_error));
result->klass = arg->klass;
Expand Down Expand Up @@ -35,3 +37,11 @@ git_remote_head *git_remote_head_dup(const git_remote_head *src) {
: NULL;
return dest;
}

void git_index_entry_dup(git_index_entry **dest, const git_index_entry *src) {
*dest = (git_index_entry *)malloc(sizeof(git_index_entry));
memcpy(*dest, src, sizeof(git_index_entry));
(*dest)->path = src->path
? strdup(src->path)
: NULL;
}
3 changes: 2 additions & 1 deletion generate/templates/manual/src/functions/free.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cstring>

#include "git2.h"
#include<iostream>

void git_remote_head_free(git_remote_head *remote_head) {
free(remote_head->name);
Expand All @@ -13,7 +14,7 @@ void git_diff_line_free(const git_diff_line *diff_line) {
free((void*) diff_line);
}

void git_index_entry_free(git_index_entry *index_entry) {
void git_index_entry_free(const git_index_entry *index_entry) {
free((void*)(index_entry->path));
free((void*) index_entry);
}
1 change: 1 addition & 0 deletions generate/templates/partials/field_accessors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

{% elsif field.cppClassName == 'String' %}
if (wrapper->GetValue()->{{ field.name }}) {
free((void*)wrapper->GetValue()->{{ field.name }});
}

Nan::Utf8String str(value);
Expand Down
10 changes: 1 addition & 9 deletions generate/templates/partials/sync_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,7 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
free((void *)from_{{ arg.name }});
{%endif%}
{%endif%}
{%if not arg.shouldAlloc %}
{%if arg.ownedByThis|and arg.dupFunction|and arg.freeFunctionName|and arg.isReturn|and arg.selfFreeing %}
// We need to free duplicated memory we are responsible for that we obtained from libgit2 because
// nodegit duplicates it again when calling the wrapper
if(from_{{ arg.name }} != NULL) {
{{ arg.freeFunctionName }}(from_{{ arg.name }});
}
{%endif%}
{%elsif arg.isReturn %}
{%if arg.shouldAlloc|and arg.isReturn %}
{%if not arg.selfFreeing %}
{%if arg.cppClassName == "GitBuf" %}
{%else%}
Expand Down