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
114 lines (96 loc) · 3.2 KB
/
Copy pathrevwalk.js
File metadata and controls
114 lines (96 loc) · 3.2 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var assert = require("assert");
var path = require("path");
describe("Revwalk", function() {
var reposPath = path.resolve("test/repos/workdir/.git");
var Repository = require("../../lib/repository");
var Revwalk = require("../../lib/revwalk");
var Oid = require("../../lib/oid");
// Set a reasonable timeout here now that our repository has grown.
this.timeout(60000);
before(function(done) {
var test = this;
return Repository.open(reposPath).then(function(repository) {
test.repository = repository;
return test.repository.getBranchCommit("rev-walk").then(function(commit) {
test.commit = commit;
done();
});
});
});
beforeEach(function() {
this.walker = this.repository.createRevWalk();
this.walker.push(this.commit.id());
});
it("can create a walker", function() {
assert.ok(this.walker instanceof Revwalk);
});
it("can push an object", function() {
var sha = this.commit.sha();
return this.walker.next().then(function(commit) {
assert.equal(sha, commit);
});
});
it("can hide an object", function() {
var test = this;
return test.walker.next().then(function(commit) {
return test.walker.next();
}).then(function() {
return test.walker.next();
}).then(function() {
return test.walker.next();
}).then(function(commit) {
assert.equal(commit.toString(),
"b8a94aefb22d0534cc0e5acf533989c13d8725dc");
test.walker = test.repository.createRevWalk();
test.walker.push(test.commit.id());
test.walker.hide(
Oid.fromString("b8a94aefb22d0534cc0e5acf533989c13d8725dc"));
return test.walker.next();
}).then(function() {
return test.walker.next();
}).then(function() {
return test.walker.next();
}).then(function(commit) {
assert.equal(commit.toString(),
"95f695136203a372751c19b6353aeb5ae32ea40e");
return test.walker.next();
}).then(function(commit) {
assert.equal(commit, undefined);
});
});
it("can simplify to first parent", function() {
var test = this;
test.walker.simplifyFirstParent();
return test.walker.next().then(function() {
return test.walker.next();
}).then(function() {
return test.walker.next();
}).then(function(commit) {
assert.equal(commit.toString(),
"b8a94aefb22d0534cc0e5acf533989c13d8725dc");
});
});
// This test requires forcing garbage collection, so mocha needs to be run
// via node rather than npm, with a la `node --expose-gc [pathtohmoca]
// [testglob]`
var testGC = global.gc ? it : it.skip;
testGC("doesnt segfault when accessing .author() twice", function(done) {
Repository.open(reposPath).then(function(repository) {
var walker = repository.createRevWalk();
repository.getMasterCommit().then(function(firstCommitOnMaster) {
walker.walk(firstCommitOnMaster, function(err, commit) {
if (!err && !commit) {
return done();
}
for (var i = 0; i < 500; i++) {
commit.author().name();
commit.author().email();
if ( i % 250 === 0) {
global.gc();
}
}
});
});
});
});
});