Skip to content

Commit 1da88f3

Browse files
committed
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 <remy.suen@gmail.com>
1 parent 75e0f22 commit 1da88f3

File tree

11 files changed

+28
-31
lines changed

11 files changed

+28
-31
lines changed

examples/walk-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
1010
return repo.getMasterCommit();
1111
})
1212
.then(function(firstCommitOnMaster) {
13-
return firstCommitOnMaster.getTree();
13+
return firstCommitOnMaster.tree();
1414
})
1515
.then(function(tree) {
1616
// `walk()` returns an event.

generate/input/descriptor.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@
535535
"ownedByThis": true
536536
}
537537
},
538+
"git_commit_tree": {
539+
"isAsync": true,
540+
"return" : {
541+
"isReturn": true,
542+
"isErrorCode": true
543+
}
544+
},
538545
"git_commit_tree_id": {
539546
"return": {
540547
"ownedByThis": true

lib/commit.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ Commit.prototype.getDiff = function(callback) {
8282
Commit.prototype.getDiffWithOptions = function(options, callback) {
8383
var commit = this;
8484

85-
return commit.getTree().then(function(thisTree) {
85+
return commit.tree().then(function(thisTree) {
8686
return commit.getParents().then(function(parents) {
8787
var diffs;
8888
if (parents.length) {
8989
diffs = parents.map(function(parent) {
90-
return parent.getTree().then(function(parentTree) {
90+
return parent.tree().then(function(parentTree) {
9191
return thisTree.diffWithOptions(parentTree, options);
9292
});
9393
});
@@ -115,7 +115,7 @@ Commit.prototype.getDiffWithOptions = function(options, callback) {
115115
* @return {TreeEntry}
116116
*/
117117
Commit.prototype.getEntry = function(path, callback) {
118-
return this.getTree().then(function(tree) {
118+
return this.tree().then(function(tree) {
119119
return tree.getEntry(path).then(function(entry) {
120120
if (typeof callback === "function") {
121121
callback(null, entry);
@@ -180,16 +180,6 @@ Commit.prototype.getSignature = function(field) {
180180
return Commit.extractSignature(this.repo, this.id(), field);
181181
};
182182

183-
/**
184-
* Get the tree associated with this commit.
185-
*
186-
* @async
187-
* @return {Tree}
188-
*/
189-
Commit.prototype.getTree = function(callback) {
190-
return this.repo.getTree(this.treeId(), callback);
191-
};
192-
193183
/**
194184
* Walk the history from this commit backwards.
195185
*

lib/repository.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
137137
if (isStaged) {
138138
return repo.getHeadCommit()
139139
.then(function getTreeFromCommit(commit) {
140-
return commit.getTree();
140+
return commit.tree();
141141
})
142142
.then(function getDiffFromTree(tree) {
143143
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);
@@ -414,7 +414,7 @@ Repository.prototype.checkoutRef = function(reference, opts) {
414414
NodeGit.Checkout.STRATEGY.RECREATE_MISSING);
415415
return repo.getReferenceCommit(reference.name())
416416
.then(function(commit) {
417-
return commit.getTree();
417+
return commit.tree();
418418
})
419419
.then(function(tree) {
420420
return Checkout.tree(repo, tree, opts);
@@ -1538,7 +1538,7 @@ Repository.prototype.mergeBranches = function(
15381538
" to branch " +
15391539
fromBranch.shorthand();
15401540

1541-
return branchCommits[1].getTree()
1541+
return branchCommits[1].tree()
15421542
.then(function(tree) {
15431543
if (toBranch.isHead()) {
15441544
// Checkout the tree if we're on the branch
@@ -1626,7 +1626,7 @@ Repository.prototype.mergeBranches = function(
16261626
return repo.getBranchCommit(branch);
16271627
})
16281628
.then(function(branchCommit) {
1629-
return branchCommit.getTree();
1629+
return branchCommit.tree();
16301630
})
16311631
.then(function(tree) {
16321632
var opts = {
@@ -1686,7 +1686,7 @@ Repository.prototype.stageFilemode =
16861686
:
16871687
repo.getHeadCommit()
16881688
.then(function getTreeFromCommit(commit) {
1689-
return commit.getTree();
1689+
return commit.tree();
16901690
})
16911691
.then(function getDiffFromTree(tree) {
16921692
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);

test/tests/commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ describe("Commit", function() {
458458
var commitTreeEntryCount = 0;
459459
var expectedCommitTreeEntryCount = 198;
460460

461-
return this.commit.getTree().then(function(tree) {
461+
return this.commit.tree().then(function(tree) {
462462
return new Promise(function(resolve, fail) {
463463

464464
var treeWalker = tree.walk();

test/tests/diff.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Diff", function() {
5757
return test.repository.getBranchCommit("master");
5858
})
5959
.then(function(masterCommit) {
60-
return masterCommit.getTree();
60+
return masterCommit.tree();
6161
})
6262
.then(function(tree) {
6363
test.masterCommitTree = tree;
@@ -411,7 +411,7 @@ describe("Diff", function() {
411411
return test.repository.getHeadCommit();
412412
})
413413
.then(function(headCommit) {
414-
return headCommit.getTree();
414+
return headCommit.tree();
415415
})
416416
.then(function(headTree) {
417417
return Promise.all([

test/tests/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("Patch", function() {
2323
return test.repository.getBranchCommit("master");
2424
})
2525
.then(function(masterCommit) {
26-
return masterCommit.getTree();
26+
return masterCommit.tree();
2727
})
2828
.then(function(tree) {
2929
test.masterCommitTree = tree;

test/tests/stage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe("Stage", function() {
8686
return test.repository.getBranchCommit("master");
8787
})
8888
.then(function(masterCommit) {
89-
var treePromise = masterCommit.getTree();
89+
var treePromise = masterCommit.tree();
9090
var indexPromise = test.repository.refreshIndex();
9191

9292
return Promise.all([treePromise, indexPromise]);
@@ -247,7 +247,7 @@ describe("Stage", function() {
247247
//fileModeDifference - expected (newfilemode) - (oldfilemode)
248248
return test.repository.getHeadCommit()
249249
.then(function(commit) {
250-
return commit.getTree();
250+
return commit.tree();
251251
})
252252
.then(function(tree) {
253253
if (vsWorkdir) {

test/tests/tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("Tree", function() {
3333

3434
it("gets an entry by name",
3535
function(done) {
36-
this.commit.getTree().then(function(tree) {
36+
this.commit.tree().then(function(tree) {
3737
var entry = tree.entryByName("README.md");
3838
assert(entry);
3939
}).done(done);
@@ -53,7 +53,7 @@ describe("Tree", function() {
5353
return RepoUtils.commitFileToRepo(repo, file2, "", commit);
5454
})
5555
.then(function(commit) {
56-
return commit.getTree();
56+
return commit.tree();
5757
})
5858
.then(function(tree) {
5959
assert(tree);

test/tests/tree_entry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("TreeEntry", function() {
8181
return Promise.all(testPromises);
8282
};
8383

84-
return this.commit.getTree()
84+
return this.commit.tree()
8585
.then(testTree)
8686
.done(function() {
8787
done();
@@ -182,7 +182,7 @@ describe("TreeEntry", function() {
182182
var test = this;
183183

184184
return leakTest(NodeGit.TreeEntry, function() {
185-
return test.commit.getTree()
185+
return test.commit.tree()
186186
.then(function(tree) {
187187
return tree.entryByPath("example");
188188
});

0 commit comments

Comments
 (0)