forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevwalk.js
More file actions
63 lines (55 loc) · 1.45 KB
/
revwalk.js
File metadata and controls
63 lines (55 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var git = require('../'),
RevWalk = git.Revwalk;
// Backwards compatibility.
Object.defineProperty(git, "RevWalk", {
value: RevWalk,
enumerable: false
});
var oldSorting = RevWalk.prototype.sorting;
/**
* Refer to vendor/libgit2/include/git2/revwalk.h for sort definitions.
*/
RevWalk.Sort = {
None: 0,
Topological: 1,
Time: 2,
Reverse: 4
};
/**
* Set the sort order for the revwalk. This function takes variable arguments
* like `revwalk.sorting(git.RevWalk.Topological, git.RevWalk.Reverse).`
*
* @param {Number} sort
*/
RevWalk.prototype.sorting = function() {
var sort = 0;
for (var i = 0; i < arguments.length; i++)
sort |= arguments[i];
oldSorting.call(this, sort);
};
/**
* Walk the history from the given oid. The callback is invoked for each commit;
* When the walk is over, the callback is invoked with `(null, null)`.
*
* @param {Oid} oid
* @param {Function} callback
* @return {Commit}
*/
RevWalk.prototype.walk = function(oid, callback) {
var self = this;
this.push(oid, function revWalkPush(error) {
if (error) return callback(error);
function walk() {
self.next(function revWalkNext(error, oid) {
if (error) return callback(error);
if (!oid) return callback();
self.repo.getCommit(oid, function revWalkCommitLookup(error, commit) {
if (error) return callback(error);
callback(null, commit);
walk();
});
});
}
walk();
});
};