Skip to content

Commit c0922f7

Browse files
committed
Merge pull request nodegit#513 from nodegit/synchronous-create-methods
Converted create methods to be synchronous
2 parents 1cfacc7 + 4c14cc1 commit c0922f7

File tree

9 files changed

+108
-96
lines changed

9 files changed

+108
-96
lines changed

generate/input/descriptor.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@
11321132
"ignore": true
11331133
},
11341134
"git_packbuilder_new": {
1135-
"ignore": true
1135+
"isAsync": false
11361136
},
11371137
"git_packbuilder_set_callbacks": {
11381138
"ignore": true
@@ -1182,6 +1182,9 @@
11821182
"functions": {
11831183
"git_pathspec_match_list_free": {
11841184
"ignore": true
1185+
},
1186+
"git_pathspec_new": {
1187+
"isAsync": false
11851188
}
11861189
}
11871190
},
@@ -1306,6 +1309,9 @@
13061309
"remote": {
13071310
"cType": "git_remote",
13081311
"functions": {
1312+
"git_remote_create": {
1313+
"isAsync": false
1314+
},
13091315
"git_remote_connect": {
13101316
"isAsync": true,
13111317
"return": {
@@ -1596,7 +1602,7 @@
15961602
"status_list": {
15971603
"functions": {
15981604
"git_status_list_new": {
1599-
"isAsync": true,
1605+
"isAsync": false,
16001606
"args": {
16011607
"opts": {
16021608
"isOptional": true

lib/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
3131
paths.push(path);
3232
};
3333
var idx = this;
34-
return Pathspec.create(pathspec || "*")
35-
.then(function(ps) {
36-
pathspec = ps;
37-
return Status.foreach(repo, statusCB);
38-
})
34+
var ps = Pathspec.create(pathspec || "*");
35+
36+
return Status.foreach(repo, statusCB)
3937
.then(function() {
4038
return paths;
4139
})
4240
.then(function(paths) {
4341
paths = paths.filter(function(path) {
44-
return !!(pathspec.matchesPath(0, path));
42+
return !!(ps.matchesPath(0, path));
4543
});
4644
return addAll.call(idx, paths, flags, matchedCallback, null);
4745
});

lib/repository.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,14 @@ Repository.prototype.getStatusExt = function(opts) {
798798
};
799799
}
800800

801-
return StatusList.create(this, opts).then(function(list) {
802-
for (var i = 0; i < list.entrycount(); i++) {
803-
var entry = Status.byIndex(list, i);
804-
statuses.push(new StatusFile({entry: entry}));
805-
}
801+
var list = StatusList.create(this, opts);
806802

807-
return statuses;
808-
});
803+
for (var i = 0; i < list.entrycount(); i++) {
804+
var entry = Status.byIndex(list, i);
805+
statuses.push(new StatusFile({entry: entry}));
806+
}
807+
808+
return statuses;
809809
};
810810

811811
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"cov": "npm run cppcov && npm run filtercov && npm run mergecov",
9191
"mocha": "mocha test/runner test/tests",
9292
"mochaDebug": "mocha --debug-brk test/runner test/tests",
93-
"test": "npm run lint && iojs --expose-gc test || node --expose-gc test",
93+
"test": "npm run lint && (iojs --expose-gc test || node --expose-gc test)",
9494
"generateJson": "node generate/scripts/generateJson",
9595
"generateNativeCode": "node generate/scripts/generateNativeCode",
9696
"generateMissingTests": "node generate/scripts/generateMissingTests",

test/tests/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var writeFile = promisify(function(filename, data, callback) {
1212
describe("Index", function() {
1313
var NodeGit = require("../../");
1414
var Repository = NodeGit.Repository;
15-
15+
1616
var reposPath = local("../repos/workdir");
1717

1818
beforeEach(function() {

test/tests/packbuilder.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
var local = path.join.bind(path, __dirname);
4+
5+
describe("Packbuilder", function() {
6+
var NodeGit = require("../../");
7+
var Repository = NodeGit.Repository;
8+
var Packbuilder = NodeGit.Packbuilder;
9+
10+
var reposPath = local("../repos/workdir");
11+
12+
beforeEach(function() {
13+
var test = this;
14+
15+
return Repository.open(reposPath).then(function(repository) {
16+
test.repository = repository;
17+
});
18+
});
19+
20+
it("can be initialized", function() {
21+
var packBuilder = Packbuilder.create(this.repository);
22+
23+
assert(packBuilder instanceof Packbuilder);
24+
});
25+
});

test/tests/pathspec.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,40 @@ describe("Pathspec", function() {
55
var Pathspec = NodeGit.Pathspec;
66

77
it("can accept just about anything against a * pathspec", function() {
8-
return Pathspec.create("*")
9-
.then(function(pathspec) {
10-
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
11-
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
12-
});
8+
var pathspec = Pathspec.create("*");
9+
10+
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
11+
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
1312
});
1413

1514
it("can take a * in an array", function() {
16-
return Pathspec.create(["*"])
17-
.then(function(pathspec) {
18-
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
19-
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
20-
});
15+
var pathspec = Pathspec.create("*");
16+
17+
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
18+
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
2119
});
2220

2321
it("can take a single file", function() {
24-
return Pathspec.create(["myDir/burritoSupreme.mp4"])
25-
.then(function(pathspec) {
26-
assert.equal(pathspec.matchesPath(0, "myDir/burritoSupreme.mp4"), 1);
27-
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 0);
28-
});
22+
var pathspec = Pathspec.create(["myDir/burritoSupreme.mp4"]);
23+
24+
assert.equal(pathspec.matchesPath(0, "myDir/burritoSupreme.mp4"), 1);
25+
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 0);
2926
});
3027

3128
it("can take files in an array", function() {
32-
return Pathspec.create(["gwendoline.txt", "sausolito.ogg"])
33-
.then(function(pathspec) {
34-
assert.equal(pathspec.matchesPath(0, "gwendoline.txt"), 1);
35-
assert.equal(pathspec.matchesPath(0, "sausolito.ogg"), 1);
36-
assert.equal(pathspec.matchesPath(0, "sausolito.txt"), 0);
37-
});
29+
var pathspec = Pathspec.create(["gwendoline.txt", "sausolito.ogg"]);
30+
31+
assert.equal(pathspec.matchesPath(0, "gwendoline.txt"), 1);
32+
assert.equal(pathspec.matchesPath(0, "sausolito.ogg"), 1);
33+
assert.equal(pathspec.matchesPath(0, "sausolito.txt"), 0);
3834
});
3935

4036
it("can handle dirs", function() {
41-
return Pathspec.create(["myDir/", "bob.js"])
42-
.then(function(pathspec) {
43-
assert.equal(pathspec.matchesPath(0, "bob.js"), 1);
44-
assert.equal(pathspec.matchesPath(0, "myDir/bob2.js"), 1);
45-
assert.equal(pathspec.matchesPath(0, "bob2.js"), 0);
46-
assert.equal(pathspec.matchesPath(0, "herDir/bob.js"), 0);
47-
});
48-
});
37+
var pathspec = Pathspec.create(["myDir/", "bob.js"]);
4938

39+
assert.equal(pathspec.matchesPath(0, "bob.js"), 1);
40+
assert.equal(pathspec.matchesPath(0, "myDir/bob2.js"), 1);
41+
assert.equal(pathspec.matchesPath(0, "bob2.js"), 0);
42+
assert.equal(pathspec.matchesPath(0, "herDir/bob.js"), 0);
43+
});
5044
});

test/tests/remote.js

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,10 @@ describe("Remote", function() {
5353

5454
it("can set a remote", function() {
5555
var repository = this.repository;
56-
var newRemote;
56+
var remote = Remote.create(repository, "origin1", url);
5757

58-
return Remote.create(repository, "origin1", url)
59-
.then(function(remote) {
60-
newRemote = remote;
61-
return remote.setPushurl("https://google.com/");
62-
})
63-
.then(function() {
64-
assert(newRemote.pushurl(), "https://google.com/");
65-
});
58+
remote.setPushurl("https://google.com/");
59+
assert(remote.pushurl(), "https://google.com/");
6660
});
6761

6862
it("can read the remote name", function() {
@@ -71,24 +65,20 @@ describe("Remote", function() {
7165

7266
it("can create and load a new remote", function() {
7367
var repository = this.repository;
68+
var remote = Remote.create(repository, "origin2", url);
7469

75-
return Remote.create(repository, "origin2", url)
76-
.then(function() {
77-
return Remote.lookup(repository, "origin2");
78-
})
79-
.then(function(remote) {
80-
assert(remote.url(), url);
81-
});
70+
return Remote.lookup(repository, "origin2").then(function() {
71+
assert(remote.url(), url);
72+
});
8273
});
8374

8475
it("can delete a remote", function() {
8576
var repository = this.repository;
77+
Remote.create(repository, "origin3", url);
8678

87-
return Remote.create(repository, "origin3", url)
88-
.then(function(remote) {
89-
Remote.delete(repository, "origin3");
90-
return Remote.lookup(repository, "origin3");
91-
})
79+
Remote.delete(repository, "origin3");
80+
81+
return Remote.lookup(repository, "origin3")
9282
.then(Promise.reject, Promise.resolve);
9383
});
9484

@@ -119,31 +109,30 @@ describe("Remote", function() {
119109
var repo = this.repository;
120110
var wasCalled = false;
121111

122-
return Remote.create(repo, "test2", url2)
123-
.then(function() {
124-
return repo.getRemote("test2");
125-
})
126-
.then(function(remote) {
127-
remote.setCallbacks({
128-
credentials: function(url, userName) {
129-
return NodeGit.Cred.sshKeyFromAgent(userName);
130-
},
131-
certificateCheck: function() {
132-
return 1;
133-
},
134-
135-
transferProgress: function() {
136-
wasCalled = true;
137-
}
138-
});
112+
Remote.create(repo, "test2", url2);
139113

140-
return remote.fetch(null, repo.defaultSignature(), null);
141-
})
142-
.then(function() {
143-
assert.ok(wasCalled);
114+
return repo.getRemote("test2")
115+
.then(function(remote) {
116+
remote.setCallbacks({
117+
credentials: function(url, userName) {
118+
return NodeGit.Cred.sshKeyFromAgent(userName);
119+
},
120+
certificateCheck: function() {
121+
return 1;
122+
},
144123

145-
Remote.delete(repo, "test2");
146-
});
124+
transferProgress: function() {
125+
wasCalled = true;
126+
}
127+
});
128+
129+
return remote.fetch(null, repo.defaultSignature(), null);
130+
})
131+
.then(function() {
132+
assert.ok(wasCalled);
133+
134+
Remote.delete(repo, "test2");
135+
});
147136
});
148137

149138
it("can fetch from a remote", function() {

test/tests/repository.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ describe("Repository", function() {
120120

121121
return fse.writeFile(filePath, fileContent)
122122
.then(function() {
123-
return repo.getStatusExt().then(function(statuses) {
124-
assert.equal(statuses.length, 1);
125-
assert.equal(statuses[0].path(), fileName);
126-
assert.equal(statuses[0].indexToWorkdir().newFile().path(), fileName);
127-
assert.ok(statuses[0].isNew());
128-
});
123+
var statuses = repo.getStatusExt();
124+
125+
assert.equal(statuses.length, 1);
126+
assert.equal(statuses[0].path(), fileName);
127+
assert.equal(statuses[0].indexToWorkdir().newFile().path(), fileName);
128+
assert.ok(statuses[0].isNew());
129129
})
130130
.then(function() {
131131
return fse.remove(filePath);

0 commit comments

Comments
 (0)