Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions generate/templates/templates/nodegit.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.

Loading