Skip to content

Commit 486b0cc

Browse files
committed
Removed unnecessary success() utility
1 parent 271c65e commit 486b0cc

File tree

12 files changed

+48
-114
lines changed

12 files changed

+48
-114
lines changed

lib/blob.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Blob convenience class constructor.
@@ -9,7 +8,7 @@ var git = require('../'),
98
*/
109
var Blob = function(rawBlob) {
1110
if (!(rawBlob instanceof git.raw.Blob)) {
12-
throw new Exception('First parameter for Blob must be a raw blob');
11+
throw new Error('First parameter for Blob must be a raw blob');
1312
}
1413
this.rawBlob = rawBlob;
1514
};
@@ -49,10 +48,8 @@ Blob.prototype.createFromFile = function(path, callback) {
4948
* @param {Blob|null} blob The new blob or null.
5049
*/
5150
git.raw.Blob.createFromFile(path, self.rawRepo, function blobCreateFromFileCallback(error, rawBlob) {
52-
if (success(error, callback)) {
53-
self.rawBlob = rawBlob;
54-
callback(null, self);
55-
}
51+
if (error) return callback(error);
52+
callback(null, new Blob(rawBlob));
5653
});
5754
};
5855

@@ -70,10 +67,8 @@ Blob.prototype.createFromFile = function(path, callback) {
7067
*/
7168
var self = this;
7269
self.rawBlob.createFromBuffer(buffer, self.rawRepo, function blobCreateFromBufferCallback(error, rawBlob) {
73-
if (success(error, callback)) {
74-
self.rawBlob = rawBlob;
75-
callback(null, self);
76-
}
70+
if (error) return callback(error);
71+
callback(null, new Blob(rawBlob));
7772
});
7873
};
7974

lib/commit.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var git = require( '../' ),
2-
success = require('./utilities').success,
32
events = require('events');
43

54
/**
@@ -11,12 +10,12 @@ var git = require( '../' ),
1110
*/
1211
var Commit = function(repo, rawCommit) {
1312
if (!(repo instanceof git.repo)) {
14-
throw new git.error('First parameter for Commit must be a raw repo');
13+
throw new Error('First parameter for Commit must be a raw repo');
1514
}
1615
this.repo = repo;
1716

1817
if (!(rawCommit instanceof git.raw.Commit)) {
19-
throw new git.error('Second parameter for Commit must be a raw commit');
18+
throw new Error('Second parameter for Commit must be a raw commit');
2019
}
2120
this.rawCommit = rawCommit;
2221
};
@@ -113,9 +112,8 @@ Commit.prototype.file = function(path, callback) {
113112
this.getTree(function (error, tree) {
114113
if (error) return callback(error);
115114
tree.entry(path, function(error, entry) {
116-
if (success(error, callback)) {
117-
callback(null, entry);
118-
}
115+
if (error) return callback(error);
116+
callback(null, entry);
119117
});
120118
});
121119
};
@@ -184,9 +182,8 @@ Commit.prototype.parents = function(callback) {
184182
if (n < 0) return callback(null, acc);
185183

186184
rawCommit.parent(n, function nextParent(error, rawParentCommit) {
187-
if (success(error, callback)) {
188-
processParents(rawParentCommit, n-1, acc.concat([new Commit(self.repo, rawParentCommit)]), callback)
189-
}
185+
if (error) return callback(error);
186+
processParents(rawParentCommit, n-1, acc.concat([new Commit(self.repo, rawParentCommit)]), callback)
190187
});
191188
}
192189

@@ -207,18 +204,18 @@ Commit.prototype.parentsDiffTrees = function(callback) {
207204
*/
208205
var self = this;
209206
self.parents(function commitParents(error, parents) {
210-
if (!success(error, callback)) return;
207+
if (error) return callback(error);
211208

212209
var parentDiffLists = [];
213210
parents.forEach(function commitEachParent(parent) {
214211
parent.getTree(function(error, parentTree) {
215-
if (!success(error, callback)) return;
212+
if (error) return callback(error);
216213

217214
self.getTree(function(error, thisTree) {
218-
if (!success(error, callback)) return;
215+
if (error) return callback(error);
219216

220217
git.diffList.treeToTree(self.repo, parentTree, thisTree, function walkDiffList(error, diffList) {
221-
if (!success(error, callback)) return;
218+
if (error) return callback(error);
222219

223220
parentDiffLists.push(diffList);
224221
if (parentDiffLists.length === parents.length) {

lib/diff_list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var git = require('../'),
99
*/
1010
var DiffList = function(rawDiffList) {
1111
if (!(rawDiffList instanceof git.raw.DiffList)) {
12-
throw new git.error('Parameter for DiffList must be a raw difflist');
12+
throw new Error('Parameter for DiffList must be a raw difflist');
1313
}
1414
this.rawDiffList = rawDiffList;
1515
};

lib/oid.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Convenience Oid constructor.

lib/patch.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Convenience patch class.

lib/reference.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Convenience reference constructor.
@@ -10,7 +9,7 @@ var git = require('../'),
109
*/
1110
var Reference = function(rawReference) {
1211
if (!(rawReference instanceof git.raw.Reference)) {
13-
throw new git.error('First parameter for Reference must be a raw reference');
12+
throw new Error('First parameter for Reference must be a raw reference');
1413
}
1514
this.rawReference = rawReference;
1615
};
@@ -36,11 +35,11 @@ Reference.lookup = function(rawRepo, name, callback) {
3635
git.raw.Reference.lookup(rawRepo, name, function referenceLookup(error, rawReference) {
3736
if (rawReference.type() == Reference.Type.Symbolic) {
3837
rawReference.resolve(function referenceResolve(error, rawReference) {
39-
if (!success(error, callback)) return;
38+
if (error) return callback(error);
4039
callback(null, new Reference(rawReference));
4140
});
4241
} else {
43-
if (!success(error, callback)) return;
42+
if (error) return callback(error);
4443
callback(null, new Reference(rawReference));
4544
}
4645
});

lib/repo.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Convenience repository class.
@@ -24,9 +23,8 @@ Repo.init = function(directory, isBare, callback) {
2423
* @param {Repo|null} repo Initialized repository.
2524
*/
2625
git.raw.Repo.init(directory, isBare, function(error, rawRepo) {
27-
if (success(error, callback)) {
28-
callback(null, new Repo(rawRepo));
29-
}
26+
if (error) return callback(error);
27+
callback(null, new Repo(rawRepo));
3028
});
3129
};
3230

@@ -46,12 +44,11 @@ Repo.open = function(directory, callback) {
4644
* @param {Repo|null} repo Opened repository.
4745
*/
4846
if (typeof callback !== 'function') {
49-
throw new git.error('Callback is required and must be a Function');
47+
throw new Error('Callback is required and must be a Function');
5048
}
5149
git.raw.Repo.open(directory, function openRepository(error, rawRepo) {
52-
if (success(error, callback)) {
53-
callback(null, new Repo(rawRepo));
54-
}
50+
if (error) return callback(error);
51+
callback(null, new Repo(rawRepo));
5552
});
5653
};
5754

@@ -69,11 +66,11 @@ Repo.prototype.branch = function(name, callback) {
6966
*/
7067
var self = this;
7168
git.reference.lookup(this.rawRepo, 'refs/heads/' + name, function referenceLookupCallback(error, reference) {
72-
if (!success(error, callback)) return;
69+
if (error) return callback(error);
7370

7471
var oid = reference.oid();
7572
self.commit(oid, function commitLookupCallback(error, commit) {
76-
if (!success(error, callback)) return;
73+
if (error) return callback(error);
7774

7875
callback(null, commit);
7976
});
@@ -97,9 +94,8 @@ Repo.prototype.commit = function(oid, callback) {
9794
if (typeof oid === 'string') oid = git.raw.Oid.fromString(oid);
9895

9996
git.raw.Commit.lookup(this.rawRepo, oid, function(error, rawCommit) {
100-
if (success(error, callback)) {
101-
callback(null, new git.commit(self, rawCommit));
102-
}
97+
if (error) return callback(error);
98+
callback(null, new git.commit(self, rawCommit));
10399
});
104100
} catch (e) {
105101
callback(e);
@@ -119,9 +115,8 @@ Repo.prototype.blob = function(oid, callback) {
119115
* @param {Blob|null} blob Retrieved blob object or null.
120116
*/
121117
git.raw.Blob.lookup(this.rawRepo, oid.rawOid, function blobLookup(error, rawBlob) {
122-
if (success(error, callback)) {
123-
callback(null, new git.blob(rawBlob));
124-
}
118+
if (error) return callback(error);
119+
callback(null, new git.blob(rawBlob));
125120
});
126121
};
127122

@@ -139,9 +134,8 @@ Repo.prototype.tree = function(oid, callback) {
139134
*/
140135
var self = this;
141136
git.raw.Tree.lookup(this.rawRepo, oid.rawOid, function(error, rawTree) {
142-
if (success(error, callback)) {
143-
callback(null, new git.tree(self, rawTree));
144-
}
137+
if (error) return callback(error);
138+
callback(null, new git.tree(self, rawTree));
145139
});
146140
};
147141

lib/revwalk.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var git = require('../'),
2-
success = require('./utilities').success;
1+
var git = require('../');
32

43
/**
54
* Convenience revision walking class
@@ -10,11 +9,11 @@ var git = require('../'),
109
*/
1110
var RevWalk = function(repo, rawRevWalk) {
1211
if (!(repo instanceof git.repo)) {
13-
throw new Exception('First parameter for RevWalk must be a repo');
12+
throw new Error('First parameter for RevWalk must be a repo');
1413
}
1514

1615
if (!(rawRevWalk instanceof git.raw.RevWalk)) {
17-
throw new Exception('Second parameter for RevWalk must be a raw.RevWalk');
16+
throw new Error('Second parameter for RevWalk must be a raw.RevWalk');
1817
}
1918

2019
this.repo = repo;
@@ -38,7 +37,7 @@ RevWalk.make = function(repo) {
3837
RevWalk.prototype.walk = function(oid, callback) {
3938
var self = this;
4039
this.rawRevWalk.push(oid.getRawOid(), function revWalkPush(error) {
41-
if (!success(error, callback)) return;
40+
if (error) return callback(error);
4241

4342
function walk() {
4443
self.rawRevWalk.next(function revWalkNext(error, oid) {

lib/tree.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var git = require('../'),
2-
success = require('./utilities').success,
32
events = require('events');
43

54
/**
@@ -10,12 +9,12 @@ var git = require('../'),
109
* @param {git.raw.Tree} [rawTree = new git.raw.Tree(rawRepo)] Raw tree object.
1110
*/
1211
var Tree = function(repo, rawTree) {
13-
if(!(repo instanceof git.repo)) {
14-
throw new Exception('First parameter for Tree must be a raw repo');
12+
if (!(repo instanceof git.repo)) {
13+
throw new Error('First parameter for Tree must be a raw repo');
1514
}
1615

17-
if(!(rawTree instanceof git.raw.Tree)) {
18-
throw new Exception('Second parameter for Tree must be a raw tree');
16+
if (!(rawTree instanceof git.raw.Tree)) {
17+
throw new Error('Second parameter for Tree must be a raw tree');
1918
}
2019

2120
this.repo = repo;
@@ -36,9 +35,8 @@ Tree.prototype.entry = function(path, callback) {
3635
*/
3736
var self = this;
3837
self.rawTree.getEntryByPath(path, function(error, rawEntry) {
39-
if (success(error, callback)) {
40-
callback(null, new git.entry(self.repo, rawEntry));
41-
}
38+
if (error) return callback(error);
39+
callback(null, new git.entry(self.repo, rawEntry));
4240
});
4341
};
4442

lib/tree_entry.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var git = require('../'),
2-
path = require('path'),
3-
success = require('./utilities').success;
2+
path = require('path');
43

54
/**
65
* Convenience tree entry constructor.

0 commit comments

Comments
 (0)