FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor classes by maxkorp · Pull Request #250 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cc  (4) .h  (3) .js  (5) .json  (3) .yml  (1) All 5 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion .travis.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ git:
branches:
only:
- master

script: npm --expose-gc test
4 changes: 2 additions & 2 deletions example/add-and-commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 generate/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
12 changes: 12 additions & 0 deletions generate/manual/include/macros.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef NODEGIT_PSUEDONAN_H_
#if (NODE_MODULE_VERSION > 0x000B)
// Node 0.11+ (0.11.3 and below won't compile with these)
# define NodeGitPsueodoNanReturnEscapingValue(val) NanReturnValue(NanEscapeScope(val))

#else
// Node 0.8 and 0.10
# define NodeGitPsueodoNanReturnEscapingValue(val) NanReturnValue(val)

#endif

#endif //NODEGIT_PSUEDONAN_H_
4 changes: 2 additions & 2 deletions generate/nkallen.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 generate/partials/convert_to_v8.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
17 changes: 3 additions & 14 deletions generate/partials/sync_function.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

{%each .|returnsInfo 'true' as _return %}
Expand Down Expand Up @@ -36,17 +36,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 +66,9 @@ from_{{ arg.name }}
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
NanReturnValue(to);
NodeGitPsueodoNanReturnEscapingValue(to);
{%else%}
NanReturnValue(toReturn);
NodeGitPsueodoNanReturnEscapingValue(toReturn);
{%endif%}
{%endif%}
}
13 changes: 11 additions & 2 deletions generate/setup.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
20 changes: 13 additions & 7 deletions generate/templates/class_content.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
}

#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/{{ filename }}"

{%each dependencies as dependency%}
Expand All @@ -17,9 +18,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 +64,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), NanNew<Boolean>(selfFreeing) };
return NanEscapeScope(NanNew<Function>({{ cppClassName }}::constructor_template)->NewInstance(2, argv));
}

{{ cType }} *{{ cppClassName }}::GetValue() {
Expand Down
9 changes: 4 additions & 5 deletions generate/templates/class_header.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 generate/templates/struct_content.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 @@ -90,7 +90,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 generate/templates/struct_header.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 generate/types.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 lib/repository.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
8 changes: 4 additions & 4 deletions test/tests/commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
28 changes: 28 additions & 0 deletions test/tests/revwalk.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,32 @@ describe("Revwalk", function() {
});
});
});

// This test requires forcing garbage collection, so mocha needs to be run via
// node rather than npm, with a la `node --expose-gc [pathtohmoca] [testglob]`
var testGC = (global.gc ? it : it.skip);

testGC("doesnt segfault when accessing .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;
}
});
});
});
});

});

Back | FazBrowse Home | New Git URL