Commit 37179aaad737deafec53e3dee30ae7f7b281a62c
Use object instead of multiple arguments for object source
Charles Lehner committed on 2/8/2016, 4:37:24 AMParent: 275e80fcc21f7743ee2a328818b6392eda134654
Files changed
index.js | changed |
lib/pack.js | changed |
test/pack.js | changed |
test/remote/git-remote-empty.js | changed |
test/remote/git-remote-full.js | changed |
index.js | ||
---|---|---|
@@ -226,9 +226,9 @@ | ||
226 | 226 | } |
227 | 227 | |
228 | 228 | module.exports = function (opts) { |
229 | 229 | var ended |
230 | - var objectSink = opts.objectSink | |
230 | + var objectSink = opts.objectSink || pull.error('Missing object sink') | |
231 | 231 | var haveObject = opts.haveObject || function (hash, cb) { cb(false) } |
232 | 232 | var getObjects = opts.getObjects || function (id, cb) { |
233 | 233 | cb(null, 0, pull.empty()) |
234 | 234 | } |
lib/pack.js | ||
---|---|---|
@@ -176,9 +176,13 @@ | ||
176 | 176 | if (end === true && expectChecksum) |
177 | 177 | onEnd(new Error('Missing checksum')) |
178 | 178 | if (ended = end) return cb(end) |
179 | 179 | // TODO: verify that the inflated data is the correct length |
180 | - cb(null, type, length, inflateBytes(readByte)) | |
180 | + cb(null, { | |
181 | + type: type, | |
182 | + length: length, | |
183 | + read: inflateBytes(readByte) | |
184 | + }) | |
181 | 185 | }) |
182 | 186 | } |
183 | 187 | |
184 | 188 | function readTrailer(cb) { |
@@ -268,11 +272,11 @@ | ||
268 | 272 | }) |
269 | 273 | else |
270 | 274 | readObject(abort, nextObject) |
271 | 275 | |
272 | - function nextObject(end, type, length, read) { | |
276 | + function nextObject(end, object) { | |
273 | 277 | if (end) return cb(end) |
274 | - readData = deflate(read) | |
275 | - encodeVarInt(type, length, cb) | |
278 | + readData = deflate(object.read) | |
279 | + encodeVarInt(object.type, object.length, cb) | |
276 | 280 | } |
277 | 281 | } |
278 | 282 | } |
test/pack.js | ||
---|---|---|
@@ -15,27 +15,31 @@ | ||
15 | 15 | return function readObject(abort, cb) { |
16 | 16 | read(abort, function (end, item) { |
17 | 17 | if (ended = end) return cb(end) |
18 | 18 | var data = item.object.data |
19 | - cb(null, item.type, data.length, pull.once(data)) | |
19 | + cb(null, { | |
20 | + type: item.type, | |
21 | + length: data.length, | |
22 | + read: pull.once(data) | |
23 | + }) | |
20 | 24 | }) |
21 | 25 | } |
22 | 26 | } |
23 | 27 | |
24 | 28 | function bufferObject(readObject) { |
25 | 29 | var ended |
26 | 30 | return function (abort, cb) { |
27 | - readObject(abort, function next(end, type, length, read) { | |
31 | + readObject(abort, function next(end, object) { | |
28 | 32 | if (ended = end) return cb(end) |
29 | - var hasher = util.createGitObjectHash(type, length) | |
33 | + var hasher = util.createGitObjectHash(object.type, object.length) | |
30 | 34 | pull( |
31 | - read, | |
35 | + object.read, | |
32 | 36 | hasher, |
33 | 37 | pull.collect(function (err, bufs) { |
34 | 38 | if (err) console.error(err) |
35 | 39 | // console.error('obj', type, length, JSON.stringify(buf.toString('ascii'))) |
36 | 40 | cb(err, { |
37 | - type: type, | |
41 | + type: object.type, | |
38 | 42 | object: { |
39 | 43 | hash: hasher.digest('hex'), |
40 | 44 | data: Buffer.concat(bufs) |
41 | 45 | } |
test/remote/git-remote-empty.js | ||
---|---|---|
@@ -13,26 +13,26 @@ | ||
13 | 13 | |
14 | 14 | pull( |
15 | 15 | toPull(process.stdin), |
16 | 16 | require('../../')({ |
17 | - objectSink: function (readObject) { | |
18 | - readObject(null, function next(end, type, length, read) { | |
17 | + objectSink: function (read) { | |
18 | + read(null, function next(end, object) { | |
19 | 19 | if (end === true) return |
20 | 20 | if (end) throw end |
21 | - var hasher = util.createGitObjectHash(type, length) | |
21 | + var hasher = util.createGitObjectHash(object.type, object.length) | |
22 | 22 | pull( |
23 | - read, | |
23 | + object.read, | |
24 | 24 | hasher, |
25 | 25 | pull.collect(function (err, bufs) { |
26 | 26 | if (err) throw err |
27 | - var buf = Buffer.concat(bufs, length) | |
27 | + var buf = Buffer.concat(bufs, object.length) | |
28 | 28 | process.send({object: { |
29 | - type: type, | |
29 | + type: object.type, | |
30 | 30 | data: buf.toString('ascii'), |
31 | - length: length, | |
31 | + length: object.length, | |
32 | 32 | hash: hasher.digest('hex') |
33 | 33 | }}) |
34 | - readObject(null, next) | |
34 | + read(null, next) | |
35 | 35 | }) |
36 | 36 | ) |
37 | 37 | }) |
38 | 38 | }, |
test/remote/git-remote-full.js | ||
---|---|---|
@@ -33,9 +33,13 @@ | ||
33 | 33 | return function readObject(abort, cb) { |
34 | 34 | read(abort, function (end, item) { |
35 | 35 | if (ended = end) return cb(end) |
36 | 36 | var data = item.object.data |
37 | - cb(null, item.type, data.length, pull.once(data)) | |
37 | + cb(null, { | |
38 | + type: item.type, | |
39 | + length: data.length, | |
40 | + read: pull.once(data) | |
41 | + }) | |
38 | 42 | }) |
39 | 43 | } |
40 | 44 | } |
41 | 45 |
Built with git-ssb-web