X Tutup
Skip to content

Commit dcb94e9

Browse files
Merge pull request #1772 from implausible/get-rid-of-promisify-node
Remove promisify-node and remove old callback api remnants
2 parents be55439 + 5d008e0 commit dcb94e9

File tree

14 files changed

+98
-320
lines changed

14 files changed

+98
-320
lines changed

generate/templates/templates/nodegit.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var _ = require("lodash");
2-
var promisify = require("promisify-node");
2+
var util = require("util");
33
var rawApi;
44

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

19+
var promisify = fn => fn && util.promisify(fn); // jshint ignore:line
20+
1921
// For disccussion on why `cloneDeep` is required, see:
2022
// https://github.com/facebook/jest/issues/3552
2123
// https://github.com/facebook/jest/issues/3550
@@ -132,9 +134,6 @@ importExtension("filter_registry");
132134
{% endeach %}
133135
/* jshint ignore:end */
134136

135-
// Wrap asynchronous methods to return promises.
136-
promisify(exports);
137-
138137
// Set version.
139138
exports.version = require("../package").version;
140139

lib/commit.js

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ Commit.lookup = LookupWrapper(Commit);
2121
* @param {Number} n
2222
* @return {Commit}
2323
*/
24-
Commit.prototype.parent = function(n, callback) {
24+
Commit.prototype.parent = function(n) {
2525
var repo = this.repo;
2626
return _parent.call(this, n).then(p => {
2727
p.repo = repo;
28-
29-
if (typeof callback === "function") {
30-
callback(null, p);
31-
}
32-
3328
return p;
34-
}, callback);
29+
});
3530
};
3631

3732
/**
@@ -43,10 +38,10 @@ Commit.prototype.parent = function(n, callback) {
4338
* @param {String} message_encoding
4439
* @param {String} message
4540
* @param {Tree|Oid} tree
46-
* @param {Oid} callback
41+
* @return {Oid}
4742
*/
4843
Commit.prototype.amend = function (
49-
updateRef, author, committer, message_encoding, message, tree, callback) {
44+
updateRef, author, committer, message_encoding, message, tree) {
5045
var repo = this.repo;
5146
var _this = this;
5247
var treePromise;
@@ -244,11 +239,10 @@ Commit.prototype.date = function() {
244239
* and its parent(s).
245240
*
246241
* @async
247-
* @param {Function} callback
248242
* @return {Array<Diff>} an array of diffs
249243
*/
250-
Commit.prototype.getDiff = function(callback) {
251-
return this.getDiffWithOptions(null, callback);
244+
Commit.prototype.getDiff = function() {
245+
return this.getDiffWithOptions(null);
252246
};
253247

254248
/**
@@ -257,10 +251,9 @@ Commit.prototype.getDiff = function(callback) {
257251
*
258252
* @async
259253
* @param {Object} options
260-
* @param {Function} callback
261254
* @return {Array<Diff>} an array of diffs
262255
*/
263-
Commit.prototype.getDiffWithOptions = function(options, callback) {
256+
Commit.prototype.getDiffWithOptions = function(options) {
264257
var commit = this;
265258

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

279272
return Promise.all(diffs);
280273
});
281-
}).then(function(diffs) {
282-
if (typeof callback === "function") {
283-
callback(null, diffs);
284-
}
285-
286-
return diffs;
287-
}, callback);
274+
});
288275
};
289276

290277
/**
@@ -295,34 +282,22 @@ Commit.prototype.getDiffWithOptions = function(options, callback) {
295282
* @param {String} path
296283
* @return {TreeEntry}
297284
*/
298-
Commit.prototype.getEntry = function(path, callback) {
285+
Commit.prototype.getEntry = function(path) {
299286
return this.getTree().then(function(tree) {
300-
return tree.getEntry(path).then(function(entry) {
301-
if (typeof callback === "function") {
302-
callback(null, entry);
303-
}
304-
305-
return entry;
306-
});
307-
}, callback);
287+
return tree.getEntry(path);
288+
});
308289
};
309290

310291
/**
311292
* Retrieve the commit's parents as commit objects.
312293
*
313294
* @async
314295
* @param {number} limit Optional amount of parents to return.
315-
* @param {Function} callback
316296
* @return {Array<Commit>} array of commits
317297
*/
318-
Commit.prototype.getParents = function(limit, callback) {
298+
Commit.prototype.getParents = function(limit) {
319299
var parents = [];
320300

321-
// Shift arguments.
322-
if (typeof limit === "function") {
323-
callback = limit;
324-
}
325-
326301
// If no limit was set, default to the maximum parents.
327302
limit = typeof limit === "number" ? limit : this.parentcount();
328303
limit = Math.min(limit, this.parentcount());
@@ -335,13 +310,7 @@ Commit.prototype.getParents = function(limit, callback) {
335310
}
336311

337312
// Wait for all parents to complete, before returning.
338-
return Promise.all(parents).then(function(parents) {
339-
if (typeof callback === "function") {
340-
callback(null, parents);
341-
}
342-
343-
return parents;
344-
}, callback);
313+
return Promise.all(parents);
345314
};
346315

347316
/**
@@ -367,8 +336,8 @@ Commit.prototype.getSignature = function(field) {
367336
* @async
368337
* @return {Tree}
369338
*/
370-
Commit.prototype.getTree = function(callback) {
371-
return this.repo.getTree(this.treeId(), callback);
339+
Commit.prototype.getTree = function() {
340+
return this.repo.getTree(this.treeId());
372341
};
373342

374343
/**
@@ -415,7 +384,7 @@ Commit.prototype.history = function() {
415384

416385
/**
417386
* Get the specified parent of the commit.
418-
*
387+
*
419388
* @param {number} the position of the parent, starting from 0
420389
* @async
421390
* @return {Commit} the parent commit at the specified position

lib/filter_registry.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ var normalizeOptions = NodeGit.Utils.normalizeOptions;
44
var FilterRegistry = NodeGit.FilterRegistry;
55

66
var _register = FilterRegistry.register;
7-
var _unregister = FilterRegistry.unregister;
87

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

1918
if (!filter.check || !filter.apply) {
20-
return callback(new Error(
19+
return Promise.reject(new Error(
2120
"ERROR: please provide check and apply callbacks for filter"
2221
));
2322
}
2423

25-
return _register(name, filter, priority)
26-
.then(function(result) {
27-
if (typeof callback === "function") {
28-
callback(null, result);
29-
}
30-
return result;
31-
}, callback);
32-
};
33-
34-
FilterRegistry.unregister = function(name, callback) {
35-
return _unregister(name)
36-
.then(function(result) {
37-
if (typeof callback === "function") {
38-
callback(null, result);
39-
}
40-
return result;
41-
}, callback);
24+
return _register(name, filter, priority);
4225
};

lib/odb.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup