git ssb

0+

cel / pull-git-remote-helper



Commit f65379392f63738750a80ce19d6c9d6d454c86d3

Allow using pull(readObjects, ...)

When reading from a packfile, block reading the next object until the current
one is finished
Charles Lehner committed on 2/27/2016, 4:55:55 PM
Parent: 858cdead4fef03613e3213ced272d7902fa83a55

Files changed

lib/pack.jschanged
lib/pack.jsView
@@ -102,8 +102,9 @@
102102 if (err) throw err
103103 }
104104
105105 var ended
106+ var inObject = false
106107 var numObjects = -1
107108 var checksum = createHash('sha1')
108109 var b = buffered(read)
109110 // TODO: optimize to pass through buffers to checksum
@@ -111,8 +112,9 @@
111112 var readWord = checksum(b.chunks(4))
112113 var readHash = checksum(b.chunks(20))
113114 var readChecksum = b.chunks(20)
114115 var expectChecksum = true
116+ var _cb
115117
116118 function readHeader(cb) {
117119 readWord(null, function (end, header) {
118120 if (ended = end) return cb(end)
@@ -176,8 +178,9 @@
176178 }
177179 }
178180
179181 function getObject(cb) {
182+ inObject = true
180183 readTypedVarInt(function (end, type, length) {
181184 if (opts.verbosity >= 2)
182185 console.error('read object header', end, type, length)
183186 numObjects--
@@ -185,16 +188,35 @@
185188 onEnd(new Error('Missing checksum'))
186189 if (ended = end) return cb(end)
187190 // TODO: verify that the inflated data is the correct length
188191 if (type == 'ref-delta')
189- getObjectFromRefDelta(length, cb)
192+ getObjectFromRefDelta(length, gotObject)
190193 else
191- cb(null, {
194+ gotObject(null, {
192195 type: type,
193196 length: length,
194197 read: inflateBytes(readByte)
195198 })
196199 })
200+
201+ function gotObject(err, obj) {
202+ // pass through the object but detect when it ends
203+ if (err) return cb(err)
204+ cb(null, {
205+ type: obj.type,
206+ length: obj.length,
207+ read: pull(
208+ obj.read,
209+ pull.through(null, function () {
210+ inObject = false
211+ if (_cb) {
212+ var cb = _cb
213+ readObject(null, cb)
214+ }
215+ })
216+ )
217+ })
218+ }
197219 }
198220
199221 // TODO: test with ref-delta objects in pack
200222 function getObjectFromRefDelta(length, cb) {
@@ -243,8 +265,9 @@
243265 }
244266
245267 function readObject(abort, cb) {
246268 if (ended) cb(ended)
269+ else if (inObject) _cb = cb
247270 else if (abort) read(abort, function (err) { cb(ended = err || abort) })
248271 else if (numObjects < 0) readHeader(cb)
249272 else if (numObjects > 0) getObject(cb)
250273 else if (expectChecksum) readTrailer(cb)

Built with git-ssb-web