Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,13 @@
"diff_format_email_options": {
"ignore": true
},
"diff_line": {
"dependencies": [
"../include/functions/free.h"
],
"selfFreeing": true,
"freeFunctionName": "git_diff_line_free"
},
"diff_perfdata": {
"selfFreeing": true,
"cDependencies": [
Expand Down Expand Up @@ -1874,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 @@ -2027,6 +2042,12 @@
}
},
"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
15 changes: 12 additions & 3 deletions generate/templates/manual/commit/extract_signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ NAN_METHOD(GitCommit::ExtractSignature)
if (info[1]->IsString()) {
Nan::Utf8String oidString(Nan::To<v8::String>(info[1]).ToLocalChecked());
baton->commit_id = (git_oid *)malloc(sizeof(git_oid));
if (git_oid_fromstr(baton->commit_id, (const char *)strdup(*oidString)) != GIT_OK) {
baton->commit_idNeedsFree = true;
string str = string(*oidString);
if (git_oid_fromstr(baton->commit_id, str.c_str()) != GIT_OK) {
free(baton->commit_id);

if (git_error_last()) {
Expand All @@ -39,6 +41,7 @@ NAN_METHOD(GitCommit::ExtractSignature)
}
} else {
baton->commit_id = Nan::ObjectWrap::Unwrap<GitOid>(Nan::To<v8::Object>(info[1]).ToLocalChecked())->GetValue();
baton->commit_idNeedsFree = false;
}

// baton->field
Expand Down Expand Up @@ -96,6 +99,10 @@ void GitCommit::ExtractSignatureWorker::HandleErrorCallback() {
git_buf_dispose(&baton->signature);
git_buf_dispose(&baton->signed_data);

if (baton->commit_idNeedsFree) {
free(baton->commit_id);
}

free(baton->field);

delete baton;
Expand Down Expand Up @@ -154,9 +161,11 @@ void GitCommit::ExtractSignatureWorker::HandleOKCallback()
git_buf_dispose(&baton->signature);
git_buf_dispose(&baton->signed_data);

if (baton->field != NULL) {
free((void *)baton->field);
if (baton->commit_idNeedsFree) {
free(baton->commit_id);
}

free(baton->field);

delete baton;
}
12 changes: 12 additions & 0 deletions generate/templates/manual/include/cleanup_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <memory>
#include <string>

extern "C" {
#include <git2.h>
#include <git2/sys/filter.h>
}


namespace nodegit {
class CleanupHandle {
public:
Expand All @@ -14,6 +20,12 @@ namespace nodegit {

class FilterRegistryCleanupHandles : public CleanupHandle {
public:
~FilterRegistryCleanupHandles() {
for(std::map<std::string, std::shared_ptr<CleanupHandle>>::iterator iter = registeredFilters.begin(); iter != registeredFilters.end(); ++iter) {
std::string filtername = iter->first;
git_filter_unregister(filtername.c_str());
}
}
std::map<std::string, std::shared_ptr<CleanupHandle>> registeredFilters;
};
}
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: 2 additions & 0 deletions generate/templates/manual/include/functions/free.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
#define NODEGIT_FREE_FUNCTIONS

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(const git_index_entry *index_entry);

#endif
13 changes: 9 additions & 4 deletions generate/templates/manual/patches/convenient_patches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() {
}

delete baton->out;
delete baton;

Local<v8::Value> argv[2] = {
Nan::Null(),
Expand Down Expand Up @@ -185,8 +186,6 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() {
}

free((void *)baton->error);

return;
}

if (baton->error_code < 0) {
Expand All @@ -197,9 +196,15 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() {
err
};
callback->Call(1, argv, async_resource);

return;
}
while (!baton->out->empty()) {
PatchDataFree(baton->out->back());
baton->out->pop_back();
}

delete baton->out;

delete baton;

Nan::Call(*callback, 0, NULL);
}
5 changes: 5 additions & 0 deletions generate/templates/manual/revwalk/file_history_walk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ void GitRevwalk::FileHistoryWalkWorker::Execute()

if (fileHistoryEvent->type != GIT_DELTA_UNMODIFIED) {
baton->out->push_back(fileHistoryEvent);
} else {
delete fileHistoryEvent;
}

git_commit_free(currentCommit);
Expand Down Expand Up @@ -470,6 +472,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
callback->Call(2, argv, async_resource);

delete baton->out;
delete baton;
return;
}

Expand All @@ -492,6 +495,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
}

free((void *)baton->error);
delete baton;
return;
}

Expand All @@ -503,6 +507,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
err
};
callback->Call(1, argv, async_resource);
delete baton;
return;
}

Expand Down
2 changes: 2 additions & 0 deletions generate/templates/manual/src/convenient_patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ void PatchDataFree(PatchData *patch) {
free((void *)line->content);
free((void *)line);
}
delete hunk->lines;
delete hunk;
}
delete patch->hunks;
delete patch;
}

Expand Down
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;
}
11 changes: 11 additions & 0 deletions generate/templates/manual/src/functions/free.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#include <cstring>

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

void git_remote_head_free(git_remote_head *remote_head) {
free(remote_head->name);
free(remote_head->symref_target);
free(remote_head);
}

void git_diff_line_free(const git_diff_line *diff_line) {
free((void*)(diff_line->content));
free((void*) diff_line);
}

void git_index_entry_free(const git_index_entry *index_entry) {
free((void*)(index_entry->path));
free((void*) index_entry);
}
6 changes: 2 additions & 4 deletions generate/templates/manual/src/str_array_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ git_strarray *StrArrayConverter::Convert(v8::Local<v8::Value> val) {
}

git_strarray * StrArrayConverter::AllocStrArray(const size_t count) {
const size_t size = sizeof(git_strarray) + (sizeof(char*) * count);
uint8_t* memory = reinterpret_cast<uint8_t*>(malloc(size));
git_strarray *result = reinterpret_cast<git_strarray *>(memory);
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray));
result->strings = (char **)malloc(sizeof(char*) * count);
result->count = count;
result->strings = reinterpret_cast<char**>(memory + sizeof(git_strarray));
return result;
}

Expand Down
Loading