From 1da88f382d920dafa6141bb40c947a661989f317 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Wed, 27 Dec 2017 17:51:15 +0900 Subject: [PATCH] Remove handwritten commit.getTree() function There is a custom handwritte commit.getTree() JavaScript function which conflicts with the git_commit_tree C function provided by libgit2. The custom function has been removed in favour of generating such a function from libgit2's API. Signed-off-by: Remy Suen --- examples/walk-tree.js | 2 +- generate/input/descriptor.json | 7 +++++++ lib/commit.js | 16 +++------------- lib/repository.js | 10 +++++----- test/tests/commit.js | 2 +- test/tests/diff.js | 4 ++-- test/tests/patch.js | 2 +- test/tests/stage.js | 4 ++-- test/tests/tree.js | 4 ++-- test/tests/tree_entry.js | 4 ++-- test/tests/treebuilder.js | 4 ++-- 11 files changed, 28 insertions(+), 31 deletions(-) diff --git a/examples/walk-tree.js b/examples/walk-tree.js index 6c564acb6..830650f3d 100644 --- a/examples/walk-tree.js +++ b/examples/walk-tree.js @@ -10,7 +10,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git")) return repo.getMasterCommit(); }) .then(function(firstCommitOnMaster) { - return firstCommitOnMaster.getTree(); + return firstCommitOnMaster.tree(); }) .then(function(tree) { // `walk()` returns an event. diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index fde52a83a..b53adb610 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -535,6 +535,13 @@ "ownedByThis": true } }, + "git_commit_tree": { + "isAsync": true, + "return" : { + "isReturn": true, + "isErrorCode": true + } + }, "git_commit_tree_id": { "return": { "ownedByThis": true diff --git a/lib/commit.js b/lib/commit.js index 232d771b0..a1d6daefd 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -82,12 +82,12 @@ Commit.prototype.getDiff = function(callback) { Commit.prototype.getDiffWithOptions = function(options, callback) { var commit = this; - return commit.getTree().then(function(thisTree) { + return commit.tree().then(function(thisTree) { return commit.getParents().then(function(parents) { var diffs; if (parents.length) { diffs = parents.map(function(parent) { - return parent.getTree().then(function(parentTree) { + return parent.tree().then(function(parentTree) { return thisTree.diffWithOptions(parentTree, options); }); }); @@ -115,7 +115,7 @@ Commit.prototype.getDiffWithOptions = function(options, callback) { * @return {TreeEntry} */ Commit.prototype.getEntry = function(path, callback) { - return this.getTree().then(function(tree) { + return this.tree().then(function(tree) { return tree.getEntry(path).then(function(entry) { if (typeof callback === "function") { callback(null, entry); @@ -180,16 +180,6 @@ Commit.prototype.getSignature = function(field) { return Commit.extractSignature(this.repo, this.id(), field); }; -/** - * Get the tree associated with this commit. - * - * @async - * @return {Tree} - */ -Commit.prototype.getTree = function(callback) { - return this.repo.getTree(this.treeId(), callback); -}; - /** * Walk the history from this commit backwards. * diff --git a/lib/repository.js b/lib/repository.js index d876b1241..8eae87973 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -137,7 +137,7 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) { if (isStaged) { return repo.getHeadCommit() .then(function getTreeFromCommit(commit) { - return commit.getTree(); + return commit.tree(); }) .then(function getDiffFromTree(tree) { return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions); @@ -414,7 +414,7 @@ Repository.prototype.checkoutRef = function(reference, opts) { NodeGit.Checkout.STRATEGY.RECREATE_MISSING); return repo.getReferenceCommit(reference.name()) .then(function(commit) { - return commit.getTree(); + return commit.tree(); }) .then(function(tree) { return Checkout.tree(repo, tree, opts); @@ -1538,7 +1538,7 @@ Repository.prototype.mergeBranches = function( " to branch " + fromBranch.shorthand(); - return branchCommits[1].getTree() + return branchCommits[1].tree() .then(function(tree) { if (toBranch.isHead()) { // Checkout the tree if we're on the branch @@ -1626,7 +1626,7 @@ Repository.prototype.mergeBranches = function( return repo.getBranchCommit(branch); }) .then(function(branchCommit) { - return branchCommit.getTree(); + return branchCommit.tree(); }) .then(function(tree) { var opts = { @@ -1686,7 +1686,7 @@ Repository.prototype.stageFilemode = : repo.getHeadCommit() .then(function getTreeFromCommit(commit) { - return commit.getTree(); + return commit.tree(); }) .then(function getDiffFromTree(tree) { return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions); diff --git a/test/tests/commit.js b/test/tests/commit.js index 181a1461b..07c3700d5 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -458,7 +458,7 @@ describe("Commit", function() { var commitTreeEntryCount = 0; var expectedCommitTreeEntryCount = 198; - return this.commit.getTree().then(function(tree) { + return this.commit.tree().then(function(tree) { return new Promise(function(resolve, fail) { var treeWalker = tree.walk(); diff --git a/test/tests/diff.js b/test/tests/diff.js index fdad25354..4be5cec5b 100644 --- a/test/tests/diff.js +++ b/test/tests/diff.js @@ -57,7 +57,7 @@ describe("Diff", function() { return test.repository.getBranchCommit("master"); }) .then(function(masterCommit) { - return masterCommit.getTree(); + return masterCommit.tree(); }) .then(function(tree) { test.masterCommitTree = tree; @@ -411,7 +411,7 @@ describe("Diff", function() { return test.repository.getHeadCommit(); }) .then(function(headCommit) { - return headCommit.getTree(); + return headCommit.tree(); }) .then(function(headTree) { return Promise.all([ diff --git a/test/tests/patch.js b/test/tests/patch.js index e426d2b63..330954329 100644 --- a/test/tests/patch.js +++ b/test/tests/patch.js @@ -23,7 +23,7 @@ describe("Patch", function() { return test.repository.getBranchCommit("master"); }) .then(function(masterCommit) { - return masterCommit.getTree(); + return masterCommit.tree(); }) .then(function(tree) { test.masterCommitTree = tree; diff --git a/test/tests/stage.js b/test/tests/stage.js index 248c3e0f1..c3de375b0 100644 --- a/test/tests/stage.js +++ b/test/tests/stage.js @@ -86,7 +86,7 @@ describe("Stage", function() { return test.repository.getBranchCommit("master"); }) .then(function(masterCommit) { - var treePromise = masterCommit.getTree(); + var treePromise = masterCommit.tree(); var indexPromise = test.repository.refreshIndex(); return Promise.all([treePromise, indexPromise]); @@ -247,7 +247,7 @@ describe("Stage", function() { //fileModeDifference - expected (newfilemode) - (oldfilemode) return test.repository.getHeadCommit() .then(function(commit) { - return commit.getTree(); + return commit.tree(); }) .then(function(tree) { if (vsWorkdir) { diff --git a/test/tests/tree.js b/test/tests/tree.js index 0790759f5..fe0ac1d1c 100644 --- a/test/tests/tree.js +++ b/test/tests/tree.js @@ -33,7 +33,7 @@ describe("Tree", function() { it("gets an entry by name", function(done) { - this.commit.getTree().then(function(tree) { + this.commit.tree().then(function(tree) { var entry = tree.entryByName("README.md"); assert(entry); }).done(done); @@ -53,7 +53,7 @@ describe("Tree", function() { return RepoUtils.commitFileToRepo(repo, file2, "", commit); }) .then(function(commit) { - return commit.getTree(); + return commit.tree(); }) .then(function(tree) { assert(tree); diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index 086a4f8d2..f23cfa626 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -81,7 +81,7 @@ describe("TreeEntry", function() { return Promise.all(testPromises); }; - return this.commit.getTree() + return this.commit.tree() .then(testTree) .done(function() { done(); @@ -182,7 +182,7 @@ describe("TreeEntry", function() { var test = this; return leakTest(NodeGit.TreeEntry, function() { - return test.commit.getTree() + return test.commit.tree() .then(function(tree) { return tree.entryByPath("example"); }); diff --git a/test/tests/treebuilder.js b/test/tests/treebuilder.js index c7ef01f43..ec595a924 100644 --- a/test/tests/treebuilder.js +++ b/test/tests/treebuilder.js @@ -36,7 +36,7 @@ describe("TreeBuilder", function(){ //get latest commit return test.repo.getHeadCommit() //get tree of commit - .then(function(commit){ return commit.getTree(); }) + .then(function(commit){ return commit.tree(); }) //make treebuilder from tree .then(function(tree){ return Git.Treebuilder.create(test.repo, tree); }) //verify treebuilder can do stuff @@ -58,7 +58,7 @@ describe("TreeBuilder", function(){ //get latest commit return test.repo.getHeadCommit() //get tree of commit - .then(function(commit){ return commit.getTree(); }) + .then(function(commit){ return commit.tree(); }) //make treebuilder from tree .then(function(tree){ return Git.Treebuilder.create(test.repo, tree); }) //verify treebuilder can do stuff