Skip to content

Commit

Permalink
Merge pull request #1772 from implausible/get-rid-of-promisify-node
Browse files Browse the repository at this point in the history
Remove promisify-node and remove old callback api remnants
  • Loading branch information
ianhattendorf committed Mar 26, 2020
2 parents be55439 + 5d008e0 commit dcb94e9
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 320 deletions.
7 changes: 3 additions & 4 deletions generate/templates/templates/nodegit.js
@@ -1,5 +1,5 @@
var _ = require("lodash");
var promisify = require("promisify-node");
var util = require("util");
var rawApi;

// Attempt to load the production release first, if it fails fall back to the
Expand All @@ -16,6 +16,8 @@ catch (ex) {
rawApi = require("../build/Debug/nodegit.node");
}

var promisify = fn => fn && util.promisify(fn); // jshint ignore:line

// For disccussion on why `cloneDeep` is required, see:
// https://github.com/facebook/jest/issues/3552
// https://github.com/facebook/jest/issues/3550
Expand Down Expand Up @@ -132,9 +134,6 @@ importExtension("filter_registry");
{% endeach %}
/* jshint ignore:end */

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

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

Expand Down
63 changes: 16 additions & 47 deletions lib/commit.js
Expand Up @@ -21,17 +21,12 @@ Commit.lookup = LookupWrapper(Commit);
* @param {Number} n
* @return {Commit}
*/
Commit.prototype.parent = function(n, callback) {
Commit.prototype.parent = function(n) {
var repo = this.repo;
return _parent.call(this, n).then(p => {
p.repo = repo;

if (typeof callback === "function") {
callback(null, p);
}

return p;
}, callback);
});
};

/**
Expand All @@ -43,10 +38,10 @@ Commit.prototype.parent = function(n, callback) {
* @param {String} message_encoding
* @param {String} message
* @param {Tree|Oid} tree
* @param {Oid} callback
* @return {Oid}
*/
Commit.prototype.amend = function (
updateRef, author, committer, message_encoding, message, tree, callback) {
updateRef, author, committer, message_encoding, message, tree) {
var repo = this.repo;
var _this = this;
var treePromise;
Expand Down Expand Up @@ -244,11 +239,10 @@ Commit.prototype.date = function() {
* and its parent(s).
*
* @async
* @param {Function} callback
* @return {Array<Diff>} an array of diffs
*/
Commit.prototype.getDiff = function(callback) {
return this.getDiffWithOptions(null, callback);
Commit.prototype.getDiff = function() {
return this.getDiffWithOptions(null);
};

/**
Expand All @@ -257,10 +251,9 @@ Commit.prototype.getDiff = function(callback) {
*
* @async
* @param {Object} options
* @param {Function} callback
* @return {Array<Diff>} an array of diffs
*/
Commit.prototype.getDiffWithOptions = function(options, callback) {
Commit.prototype.getDiffWithOptions = function(options) {
var commit = this;

return commit.getTree().then(function(thisTree) {
Expand All @@ -278,13 +271,7 @@ Commit.prototype.getDiffWithOptions = function(options, callback) {

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

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

/**
Expand All @@ -295,34 +282,22 @@ Commit.prototype.getDiffWithOptions = function(options, callback) {
* @param {String} path
* @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 (typeof callback === "function") {
callback(null, entry);
}

return entry;
});
}, callback);
return tree.getEntry(path);
});
};

/**
* Retrieve the commit's parents as commit objects.
*
* @async
* @param {number} limit Optional amount of parents to return.
* @param {Function} callback
* @return {Array<Commit>} array of commits
*/
Commit.prototype.getParents = function(limit, callback) {
Commit.prototype.getParents = function(limit) {
var parents = [];

// Shift arguments.
if (typeof limit === "function") {
callback = limit;
}

// If no limit was set, default to the maximum parents.
limit = typeof limit === "number" ? limit : this.parentcount();
limit = Math.min(limit, this.parentcount());
Expand All @@ -335,13 +310,7 @@ Commit.prototype.getParents = function(limit, callback) {
}

// Wait for all parents to complete, before returning.
return Promise.all(parents).then(function(parents) {
if (typeof callback === "function") {
callback(null, parents);
}

return parents;
}, callback);
return Promise.all(parents);
};

/**
Expand All @@ -367,8 +336,8 @@ Commit.prototype.getSignature = function(field) {
* @async
* @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 Down Expand Up @@ -415,7 +384,7 @@ Commit.prototype.history = function() {

/**
* Get the specified parent of the commit.
*
*
* @param {number} the position of the parent, starting from 0
* @async
* @return {Commit} the parent commit at the specified position
Expand Down
23 changes: 3 additions & 20 deletions lib/filter_registry.js
Expand Up @@ -4,11 +4,10 @@ var normalizeOptions = NodeGit.Utils.normalizeOptions;
var FilterRegistry = NodeGit.FilterRegistry;

var _register = FilterRegistry.register;
var _unregister = FilterRegistry.unregister;

// register should add filter by name to dict and return
// Override FilterRegistry.register to normalize Filter
FilterRegistry.register = function(name, filter, priority, callback) {
FilterRegistry.register = function(name, filter, priority) {
// setting default value of attributes
if (filter.attributes === undefined) {
filter.attributes = "";
Expand All @@ -17,26 +16,10 @@ FilterRegistry.register = function(name, filter, priority, callback) {
filter = normalizeOptions(filter, NodeGit.Filter);

if (!filter.check || !filter.apply) {
return callback(new Error(
return Promise.reject(new Error(
"ERROR: please provide check and apply callbacks for filter"
));
}

return _register(name, filter, priority)
.then(function(result) {
if (typeof callback === "function") {
callback(null, result);
}
return result;
}, callback);
};

FilterRegistry.unregister = function(name, callback) {
return _unregister(name)
.then(function(result) {
if (typeof callback === "function") {
callback(null, result);
}
return result;
}, callback);
return _register(name, filter, priority);
};
15 changes: 0 additions & 15 deletions lib/odb.js

This file was deleted.

0 comments on commit dcb94e9

Please sign in to comment.