git ssb

0+

cel / pull-git-remote-helper



Commit 37179aaad737deafec53e3dee30ae7f7b281a62c

Use object instead of multiple arguments for object source

Charles Lehner committed on 2/8/2016, 4:37:24 AM
Parent: 275e80fcc21f7743ee2a328818b6392eda134654

Files changed

index.jschanged
lib/pack.jschanged
test/pack.jschanged
test/remote/git-remote-empty.jschanged
test/remote/git-remote-full.jschanged
index.jsView
@@ -226,9 +226,9 @@
226226 }
227227
228228 module.exports = function (opts) {
229229 var ended
230- var objectSink = opts.objectSink
230+ var objectSink = opts.objectSink || pull.error('Missing object sink')
231231 var haveObject = opts.haveObject || function (hash, cb) { cb(false) }
232232 var getObjects = opts.getObjects || function (id, cb) {
233233 cb(null, 0, pull.empty())
234234 }
lib/pack.jsView
@@ -176,9 +176,13 @@
176176 if (end === true && expectChecksum)
177177 onEnd(new Error('Missing checksum'))
178178 if (ended = end) return cb(end)
179179 // 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+ })
181185 })
182186 }
183187
184188 function readTrailer(cb) {
@@ -268,11 +272,11 @@
268272 })
269273 else
270274 readObject(abort, nextObject)
271275
272- function nextObject(end, type, length, read) {
276+ function nextObject(end, object) {
273277 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)
276280 }
277281 }
278282 }
test/pack.jsView
@@ -15,27 +15,31 @@
1515 return function readObject(abort, cb) {
1616 read(abort, function (end, item) {
1717 if (ended = end) return cb(end)
1818 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+ })
2024 })
2125 }
2226 }
2327
2428 function bufferObject(readObject) {
2529 var ended
2630 return function (abort, cb) {
27- readObject(abort, function next(end, type, length, read) {
31+ readObject(abort, function next(end, object) {
2832 if (ended = end) return cb(end)
29- var hasher = util.createGitObjectHash(type, length)
33+ var hasher = util.createGitObjectHash(object.type, object.length)
3034 pull(
31- read,
35+ object.read,
3236 hasher,
3337 pull.collect(function (err, bufs) {
3438 if (err) console.error(err)
3539 // console.error('obj', type, length, JSON.stringify(buf.toString('ascii')))
3640 cb(err, {
37- type: type,
41+ type: object.type,
3842 object: {
3943 hash: hasher.digest('hex'),
4044 data: Buffer.concat(bufs)
4145 }
test/remote/git-remote-empty.jsView
@@ -13,26 +13,26 @@
1313
1414 pull(
1515 toPull(process.stdin),
1616 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) {
1919 if (end === true) return
2020 if (end) throw end
21- var hasher = util.createGitObjectHash(type, length)
21+ var hasher = util.createGitObjectHash(object.type, object.length)
2222 pull(
23- read,
23+ object.read,
2424 hasher,
2525 pull.collect(function (err, bufs) {
2626 if (err) throw err
27- var buf = Buffer.concat(bufs, length)
27+ var buf = Buffer.concat(bufs, object.length)
2828 process.send({object: {
29- type: type,
29+ type: object.type,
3030 data: buf.toString('ascii'),
31- length: length,
31+ length: object.length,
3232 hash: hasher.digest('hex')
3333 }})
34- readObject(null, next)
34+ read(null, next)
3535 })
3636 )
3737 })
3838 },
test/remote/git-remote-full.jsView
@@ -33,9 +33,13 @@
3333 return function readObject(abort, cb) {
3434 read(abort, function (end, item) {
3535 if (ended = end) return cb(end)
3636 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+ })
3842 })
3943 }
4044 }
4145

Built with git-ssb-web