Skip to content
Merged
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
Added all test files and did some refactoring
  • Loading branch information
tbranyen committed Jul 11, 2014
commit 9ea39f6942999795c5cb645a65941a086380a693
2 changes: 1 addition & 1 deletion generate/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"isConstructorMethod": true,
"args": [
{ "isReturn": true },
{ "isSelf": true },
{ "isSelf": false },
{},
{},
{ "isOptional": true }
Expand Down
26 changes: 12 additions & 14 deletions lib/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Commit.prototype.date = function() {
* Get the tree associated with this commit.
* @return {Tree}
*/
Commit.prototype.getTree = function(callback) {
return this.repo.getTree(this.treeId(), callback);
Commit.prototype.getTree = function() {
return this.repo.getTree(this.treeId());
};

/**
Expand All @@ -44,16 +44,12 @@ Commit.prototype.getTree = function(callback) {
* @param {Function} callback
* @return {TreeEntry}
*/
Commit.prototype.getEntry = function(path, callback) {
Commit.prototype.getEntry = function(path) {
return this.getTree().then(function(tree) {
return tree.getEntry(path).then(function(entry) {
if (callback) {
callback(entry);
}

return entry;
});
}, callback);
});
};

/**
Expand Down Expand Up @@ -172,19 +168,21 @@ Commit.prototype.getDiff = function(callback) {
var commit = this;

return commit.getParents().then(function(parents) {
return parents.map(function(parent) {
return parent.getTree(function(parentTree) {
return commit.getTree(function(thisTree) {
var diffs = parents.map(function(parent) {
return parent.getTree().then(function(parentTree) {
return commit.getTree().then(function(thisTree) {
return parentTree.diff(thisTree);
});
});
});
}).then(function(parentDiffs) {

return Promise.all(diffs);
}).then(function(diffs) {
if (callback) {
callback(null, parentDiffs);
callback(null, diffs);
}

return parentDiffs;
return diffs;
}, callback);
};

Expand Down
2 changes: 2 additions & 0 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ Diff.LineOrigin = {
Diff.prototype.patches = function() {
var size = this.size();
var result = [];

for (var i = 0; i < size; i++) {
result.push(new ConvenientPatch(this.getDelta(i), Patch.fromDiff(this, i)));
}

return result;
};

Expand Down
40 changes: 20 additions & 20 deletions lib/nodegit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ catch (e) {
rawApi = require("../build/Debug/nodegit");
}

// Set the exports prototype to the raw API.
exports.__proto__ = rawApi;

// Import extensions
require("./commit.js");
require("./diff.js");
require("./blob.js");
require("./object.js");
require("./signature.js");
require("./odb.js");
require("./oid.js");
require("./index.js");
require("./repository.js");
require("./reference.js");
require("./revwalk.js");
require("./tree.js");

// Wrap asynchronous methods to return promises.
promisify(exports);

// Native methods do not return an identifiable function, so this function will
// filter down the function identity to match the libgit2 descriptor.
descriptors.forEach(function(descriptor) {
Expand All @@ -55,6 +35,26 @@ descriptors.forEach(function(descriptor) {
});
});

// Set the exports prototype to the raw API.
exports.__proto__ = rawApi;

// Import extensions
require("./commit.js");
require("./diff.js");
require("./blob.js");
require("./object.js");
require("./signature.js");
require("./odb.js");
require("./oid.js");
require("./index.js");
require("./repository.js");
require("./refs.js");
require("./revwalk.js");
require("./tree.js");

// Wrap asynchronous methods to return promises.
promisify(exports);

// Set version.
exports.version = require("../package").version;

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var NodeGit = require("../");
var normalizeOid = require("./util/normalize_oid");
var Blob = require("./blob");
var Tree = require("./tree");
var Reference = require("./reference");
var Reference = require("./refs");
var Revwalk = require("./revwalk");
var Commit = require("./commit");

Expand Down Expand Up @@ -122,7 +122,6 @@ Repository.prototype.getTree = function(oid, callback) {

var repository = this;


return Tree.lookup(repository, oid).then(function(tree) {
tree.repo = repository;

Expand Down
18 changes: 9 additions & 9 deletions lib/revwalk.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var git = require("../");
var util = require("./util");
var Revwalk = git.Revwalk;
var NodeGit = require("../");
var normalizeOid = require("./util/normalize_oid");

var Revwalk = NodeGit.Revwalk;

// Backwards compatibility.
Object.defineProperty(git, "RevWalk", {
Object.defineProperty(NodeGit, "RevWalk", {
value: Revwalk,
enumerable: false
});

var oldSorting = Revwalk.prototype.sorting;

/**
* Refer to vendor/libgit2/include/git2/revwalk.h for sort definitions.
* Refer to vendor/libNodeGit2/include/NodeGit2/revwalk.h for sort definitions.
*/
Revwalk.Sort = {
None: 0,
Expand All @@ -22,7 +23,7 @@ Revwalk.Sort = {

/**
* Set the sort order for the revwalk. This function takes variable arguments
* like `revwalk.sorting(git.RevWalk.Topological, git.RevWalk.Reverse).`
* like `revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse).`
*
* @param {Number} sort
*/
Expand All @@ -45,6 +46,8 @@ Revwalk.prototype.sorting = function() {
* @return {Commit}
*/
Revwalk.prototype.walk = function(oid, callback) {
oid = normalizeOid(oid);

var self = this;

this.push(oid);
Expand Down Expand Up @@ -73,7 +76,4 @@ Revwalk.prototype.walk = function(oid, callback) {
walk();
};

util.normalizeOid(Revwalk.prototype, "walk");
util.makeSafe(Revwalk.prototype, "walk");

module.exports = Revwalk;
2 changes: 1 addition & 1 deletion lib/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Object.defineProperties(Tree.prototype, {
* @return {DiffList}
*/
Tree.prototype.diff = function(tree, callback) {
return Diff.treeToTree.call(this.repo, tree, this, null, callback);
return Diff.treeToTree(this.repo, tree, this, null).then(null, callback);
};

/**
Expand Down
24 changes: 0 additions & 24 deletions lib/util.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/commit.js

This file was deleted.

49 changes: 0 additions & 49 deletions test/diff.js

This file was deleted.

20 changes: 0 additions & 20 deletions test/nodegit.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/oid.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/reference.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/revwalk.js

This file was deleted.

Empty file added test/tests/convenient_hunk.js
Empty file.
Empty file added test/tests/convenient_patch.js
Empty file.
Loading