From 0024f0297b346b179c707053552e98a865b1a7fb Mon Sep 17 00:00:00 2001 From: Jeff Wilcox Date: Fri, 13 Feb 2015 17:06:47 -0800 Subject: [PATCH 1/3] Tree Entry getBlob() should also support the callback pattern. --- lib/tree_entry.js | 12 ++++++++++-- test/tests/tree_entry.js | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 0d926c4db..98a3ab288 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -63,8 +63,16 @@ TreeEntry.prototype.getTree = function(callback) { * Retrieve the tree for this entry. Make sure to call `isTree` first! * @return {Blob} */ -TreeEntry.prototype.getBlob = function() { - return this.parent.repo.getBlob(this.oid()); +TreeEntry.prototype.getBlob = function(callback) { + var entry = this; + + return this.parent.repo.getBlob(this.oid()).then(function(blob) { + if (typeof callback === "function") { + callback(null, blob); + } + + return blob; + }, callback); }; /** diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index ae481a1d2..19d322ba0 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -54,6 +54,15 @@ describe("TreeEntry", function() { }); }); + it("provides the blob representation of the entry via a callback", function() { + return this.commit.getEntry("test/raw-commit.js") + .then(function(entry) { + entry.getBlob(function (error, blob) { + assert.equal(blob.rawsize(), 2736); + }); + }); + }); + it("provides the tree the entry is part of", function() { return this.commit.getEntry("test") .then(function(entry) { From c6236980ce58e23bfc013365fb84ab3f91d1be7a Mon Sep 17 00:00:00 2001 From: Jeff Wilcox Date: Fri, 13 Feb 2015 17:24:02 -0800 Subject: [PATCH 2/3] treeEntry: fixing up jshint warnings --- lib/tree_entry.js | 2 -- test/tests/tree_entry.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 98a3ab288..9d145a866 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -64,8 +64,6 @@ TreeEntry.prototype.getTree = function(callback) { * @return {Blob} */ TreeEntry.prototype.getBlob = function(callback) { - var entry = this; - return this.parent.repo.getBlob(this.oid()).then(function(blob) { if (typeof callback === "function") { callback(null, blob); diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index 19d322ba0..5e6f42bcc 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -54,7 +54,7 @@ describe("TreeEntry", function() { }); }); - it("provides the blob representation of the entry via a callback", function() { + it("provides the blob representation viacallback", function() { return this.commit.getEntry("test/raw-commit.js") .then(function(entry) { entry.getBlob(function (error, blob) { From a023fa51685fd8e21aae89b26ec0c00b33da87e1 Mon Sep 17 00:00:00 2001 From: Jeff Wilcox Date: Sat, 14 Feb 2015 08:32:20 -0800 Subject: [PATCH 3/3] Fixing a typo --- test/tests/tree_entry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/tree_entry.js b/test/tests/tree_entry.js index 5e6f42bcc..c3451d8b3 100644 --- a/test/tests/tree_entry.js +++ b/test/tests/tree_entry.js @@ -54,7 +54,7 @@ describe("TreeEntry", function() { }); }); - it("provides the blob representation viacallback", function() { + it("provides the blob representation via callback", function() { return this.commit.getEntry("test/raw-commit.js") .then(function(entry) { entry.getBlob(function (error, blob) {