Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
4 changes: 2 additions & 2 deletions 4 example/add-and-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var git = require('../'),
;

/**
* This example creates a certain file `newfile.txt`, adds it to the git index and
* This example creates a certain file `newfile.txt`, adds it to the git index and
* commits it to head. Similar to a `git add newfile.txt` followed by a `git commit`
**/

Expand Down Expand Up @@ -56,4 +56,4 @@ git.Repo.open(path.resolve(__dirname, '../.git'), function(openReporError, repo)
});
});
});
});
});
4 changes: 2 additions & 2 deletions 4 generate/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
"functions": {
"git_commit_create": {
"ignore": false,
"jsFunctionName": "createCommit",
"cppFunctionName": "CreateCommit",
"jsFunctionName": "create",
"cppFunctionName": "Create",
"isConstructorMethod": true,
"isAsync": true,
"return": {
Expand Down
4 changes: 2 additions & 2 deletions 4 generate/nkallen.json
Original file line number Diff line number Diff line change
Expand Up @@ -12344,8 +12344,8 @@
"isAsync": true,
"isConstructorMethod": false,
"isPrototypeMethod": true,
"jsFunctionName": "createCommit",
"cppFunctionName": "CreateCommit",
"jsFunctionName": "create",
"cppFunctionName": "Create",
"return": {
"cType": "int",
"cppClassName": "Int32",
Expand Down
7 changes: 7 additions & 0 deletions 7 generate/partials/convert_to_v8.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// start convert_to_v8 block
{%if cppClassName == 'String' %}
{%if size %}
to = NanNew<String>({{= parsedName =}}, {{ size }});
Expand Down Expand Up @@ -39,9 +40,15 @@ to = tmpArray;
{%endif%}

if ({{= parsedName =}} != NULL) {
// {{= cppClassName }} {{= parsedName }}
{%if cppClassName == 'Wrapper' %}
to = {{ cppClassName }}::New((void *){{= parsedName =}});
{%else%}
to = {{ cppClassName }}::New((void *){{= parsedName =}}, false);
{%endif%}
} else {
to = NanNull();
}

{%endif%}
// end convert_to_v8 block
16 changes: 2 additions & 14 deletions 16 generate/partials/sync_function.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

{%partial doc .%}
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
NanScope();
{%partial guardArguments .%}

{%each .|returnsInfo 'true' as _return %}
Expand Down Expand Up @@ -36,17 +35,6 @@ from_{{ arg.name }}
{%if not arg.lastArg %},{%endif%}
{%endeach%}
);

{%each args|argsInfo as arg %}
{%if arg.isCppClassStringOrArray %}
{%if arg.freeFunctionName %}
{{ arg.freeFunctionName }}(from_{{ arg.name }});
{%else%}
free((void *)from_{{ arg.name }});
{%endif%}
{%endif%}
{%endeach%}

{%if return.isErrorCode %}
if (result != GIT_OK) {
{%each args|argsInfo as arg %}
Expand Down Expand Up @@ -77,9 +65,9 @@ from_{{ arg.name }}
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
NanReturnValue(to);
return to;
{%else%}
NanReturnValue(toReturn);
return toReturn;
{%endif%}
{%endif%}
}
13 changes: 11 additions & 2 deletions 13 generate/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fileNames.forEach(function(fileName, index) {
}

file.freeFunctionName = "git_" + fileName + "_free";
file.createFunctionName = "git_" + fileName + "_create";
}

// TODO Obsolete this.
Expand All @@ -136,12 +137,14 @@ fileNames.forEach(function(fileName, index) {
return fnName === initFnName;
});

// Doesn't actually exist.
// Free function doesn't actually exist.
if (cFile.functions.indexOf(file.freeFunctionName) === -1) {
delete file.freeFunctionName;
}


if (cFile.functions.indexOf(file.createFunctionName) === -1) {
delete file.createFunctionName;
}
var legacyFile = {};

if (file.jsClassName.indexOf("Git") === 0) {
Expand Down Expand Up @@ -394,6 +397,12 @@ fileNames.forEach(function(fileName, index) {
}
});

if (file.createFunctionName) {
file.cppCreateFunctionName = typeMap[file.createFunctionName].cpp;
file.jsCreateFunctionName = typeMap[file.createFunctionName].js;
delete file.createFunctionName;
}

files.push(file);
});

Expand Down
19 changes: 12 additions & 7 deletions 19 generate/templates/class_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using namespace v8;
using namespace node;

{%if cType%}
{{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw) {
{{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw, bool selfFreeing) {
this->raw = raw;
this->selfFreeing = true;
this->selfFreeing = selfFreeing;
}

{{ cppClassName }}::~{{ cppClassName }}() {
Expand Down Expand Up @@ -63,18 +63,23 @@ NAN_METHOD({{ cppClassName }}::New) {
NanScope();

if (args.Length() == 0 || !args[0]->IsExternal()) {
return NanThrowError("{{ cType }} is required.");
{%if createFunctionName%}
return NanThrowError("A new {{ cppClassName }} cannot be instantiated. Use {{ jsCreateFunctionName }} instead.");
{%else%}
return NanThrowError("A new {{ cppClassName }} cannot be instantiated.");
{%endif%}
}
{{ cppClassName }}* object = new {{ cppClassName }}(static_cast<{{ cType }} *>(Handle<External>::Cast(args[0])->Value()));

{{ cppClassName }}* object = new {{ cppClassName }}(static_cast<{{ cType }} *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
object->Wrap(args.This());

NanReturnValue(args.This());
}

Handle<Value> {{ cppClassName }}::New(void *raw) {
Handle<Value> {{ cppClassName }}::New(void *raw, bool selfFreeing) {
NanEscapableScope();
Handle<Value> argv[1] = { NanNew<External>((void *)raw) };
return NanEscapeScope(NanNew<Function>({{ cppClassName }}::constructor_template)->NewInstance(1, argv));
Handle<Value> argv[2] = { NanNew<External>((void *)raw), Boolean::New(selfFreeing) };
return NanEscapeScope(NanNew<Function>({{ cppClassName }}::constructor_template)->NewInstance(2, argv));
}

{{ cType }} *{{ cppClassName }}::GetValue() {
Expand Down
9 changes: 4 additions & 5 deletions 9 generate/templates/class_header.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef {{ cppClassName|upper }}_H
#define {{ cppClassName|upper }}_H

// generated from class_header.h
#include <nan.h>
#include <string>

Expand Down Expand Up @@ -36,14 +36,13 @@ class {{ cppClassName }} : public ObjectWrap {
{{ cType }} *GetValue();
{{ cType }} **GetRefValue();

static Handle<Value> New(void *raw);

bool selfFreeing;
static Handle<Value> New(void *raw, bool selfFreeing);
{%endif%}
bool selfFreeing;

private:
{%if cType%}
{{ cppClassName }}({{ cType }} *raw);
{{ cppClassName }}({{ cType }} *raw, bool selfFreeing);
~{{ cppClassName }}();
{%endif%}

Expand Down
8 changes: 4 additions & 4 deletions 8 generate/templates/struct_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" {
using namespace v8;
using namespace node;
using namespace std;

// generated from struct_content.cc
{{ cppClassName }}::{{ cppClassName }}() {
{{ cType }} wrappedValue = {{ cType|upper }}_INIT;
this->raw = ({{ cType }}*) malloc(sizeof({{ cType }}));
Expand All @@ -28,10 +28,10 @@ using namespace std;
this->selfFreeing = true;
}

{{ cppClassName }}::{{ cppClassName }}({{ cType }}* raw) {
{{ cppClassName }}::{{ cppClassName }}({{ cType }}* raw, bool selfFreeing) {
this->raw = raw;
this->ConstructFields();
this->selfFreeing = true;
this->selfFreeing = selfFreeing;
}

{{ cppClassName }}::~{{ cppClassName }}() {
Expand Down Expand Up @@ -83,7 +83,7 @@ NAN_METHOD({{ cppClassName }}::New) {
instance = new {{ cppClassName }}();
}
else {
instance = new {{ cppClassName }}(static_cast<{{ cType }}*>(Handle<External>::Cast(args[0])->Value()));
instance = new {{ cppClassName }}(static_cast<{{ cType }}*>(Handle<External>::Cast(args[0])->Value()), true);
}

instance->Wrap(args.This());
Expand Down
4 changes: 2 additions & 2 deletions 4 generate/templates/struct_header.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef {{ cppClassName|upper }}_H
#define {{ cppClassName|upper }}_H

// generated from struct_header.h
#include <nan.h>
#include <string>

Expand All @@ -17,7 +17,7 @@ using namespace v8;

class {{ cppClassName }} : public ObjectWrap {
public:
{{ cppClassName }}({{ cType }}* raw);
{{ cppClassName }}({{ cType }}* raw, bool selfFreeing);
static Persistent<Function> constructor_template;
static void Initialize (Handle<v8::Object> target);

Expand Down
12 changes: 6 additions & 6 deletions 12 generate/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,8 @@
"js": "lookup"
},
"git_commit_create": {
"cpp": "CreateCommit",
"js": "createCommit"
"cpp": "Create",
"js": "create"
},
"const git_commit **": {
"cpp": "GitCommit",
Expand Down Expand Up @@ -3301,12 +3301,12 @@
"js": "nthGenAncestor"
},
"git_commit_create *": {
"cpp": "CreateCommit",
"js": "createCommit"
"cpp": "Create",
"js": "create"
},
"const git_commit_create *": {
"cpp": "CreateCommit",
"js": "createCommit"
"cpp": "Create",
"js": "create"
},
"git_commit_create_v *": {
"cpp": "CreateV",
Expand Down
6 changes: 3 additions & 3 deletions 6 lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Repository.prototype.getRemotes = function(callback) {
callback(null, remotes);
}

return remotes;
return remotes;
}, callback);
};

Expand Down Expand Up @@ -218,7 +218,7 @@ Repository.prototype.createCommit = function(
var commit = this;

if (tree instanceof Tree) {
commit = Commit.createCommit.call(
commit = Commit.create.call(
this,
updateRef,
author,
Expand All @@ -231,7 +231,7 @@ Repository.prototype.createCommit = function(
);
} else {
createCommit = this.getTree(tree).then(function(tree) {
return Commit.createCommit.call(
return Commit.create.call(
commit,
updateRef,
author,
Expand Down
1 change: 0 additions & 1 deletion 1 test/tests/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe("Clone", function() {
assert.ok(repository instanceof Repository);
});
});

// Currently waiting on AppVeyor to support an interactive Windows Service
// builder, so we can correctly run pageant.exe.
var testSsh = process.platform === "win32" ? it.skip : it;
Expand Down
8 changes: 4 additions & 4 deletions 8 test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ describe("Commit", function() {
history.on("commit", function(commit) {
historyCount++;
});

history.on("end", function(commits) {
assert.equal(historyCount, expectedHistoryCount);
assert.equal(commits.length, expectedHistoryCount);

done();
});

history.on("error", function(err) {
assert.ok(false);
});

history.start();
});

Expand Down Expand Up @@ -143,7 +143,7 @@ describe("Commit", function() {
treeWalker.on("error", function() {
assert.ok(false);
});

treeWalker.on("end", function(entries) {
assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount);
done();
Expand Down
26 changes: 26 additions & 0 deletions 26 test/tests/revwalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,30 @@ describe("Revwalk", function() {
});
});
});

if (global.gc) {
it("doesnt segfault when accessing commit.author() twice", function(done) {
this.timeout(10000);
return Repository.open(reposPath).then(function(repository) {
var walker = repository.createRevWalk();
repository.getMaster().then(function(master) {
var did = false;
walker.walk(master, function(error, commit) {
for (var i = 0; i < 1000; i++) {
if (true) {
commit.author().name();
commit.author().email();
}
global.gc();
}
if (!did) {
done();
did = true;
}
});
});
});
});
}

});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.