git ssb

0+

cel / pull-git-remote-helper



Commit 12cc851c71e6ab09d98c2ce054c7ae44d20f85b3

Get checksum working

Charles Lehner committed on 2/8/2016, 4:37:23 AM
Parent: ef07dd5bda4ebb6d6e9f63ebf742df7e23029f5f

Files changed

pack.jschanged
test/git-remote-test.jschanged
pack.jsView
@@ -65,13 +65,14 @@
6565
6666 var ended
6767 var numObjects = -1
6868 var checksum = createHash('sha1')
69- var b = buffered(checksum(read))
70- var readByte = b.chunks(1)
71- var readWord = b.chunks(4)
69+ var b = buffered(read)
70+ // TODO: optimize to pass through buffers to checksum
71+ var readByte = checksum(b.chunks(1))
72+ var readWord = checksum(b.chunks(4))
7273 var readChecksum = b.chunks(20)
73- var expectChecksum = false
74+ var expectChecksum = true
7475 var opts = {
7576 verbosity: 2
7677 }
7778
@@ -113,9 +114,9 @@
113114 if (ended = end) return cb(end)
114115 var firstByte = buf[0]
115116 type = objectTypes[(firstByte >> 4) & 7]
116117 value = firstByte & 15
117- console.error('byte1', firstByte, firstByte.toString(2), value, value.toString(2))
118+ // console.error('byte1', firstByte, firstByte.toString(2), value, value.toString(2))
118119 shift = 4
119120 checkByte(firstByte)
120121 })
121122
@@ -130,34 +131,41 @@
130131 if (ended = end) return cb(end)
131132 var byte = buf[0]
132133 value += (byte & 0x7f) << shift
133134 shift += 7
134- console.error('byte', byte, byte.toString(2), value, value.toString(2))
135+ // console.error('byte', byte, byte.toString(2), value, value.toString(2))
135136 checkByte(byte)
136137 }
137138 }
138139
139140 function getObject(cb) {
140141 readVarInt(function (end, type, length) {
141- console.error('read var int', end, type, length)
142+ if (opts.verbosity >= 2)
143+ console.error('read var int', end, type, length)
144+ numObjects--
142145 if (end === true && expectChecksum)
143146 onEnd(new Error('Missing checksum'))
144147 if (ended = end) return cb(end)
145- numObjects--
146148 // TODO: verify that the inflated data is the correct length
147149 cb(null, type, inflateBytes(readByte))
148150 })
149151 }
150152
151153 function readTrailer(cb) {
154+ // read the checksum before it updates to include the trailer
155+ var expected = checksum.digest()
152156 readChecksum(null, function (end, value) {
153157 cb(true)
154- var actual = checksum.digest()
155- if (!value.equals(actual))
158+ if (end === true && expectChecksum)
159+ onEnd(new Error('Missing checksum'))
160+ if (!value.equals(expected)) {
156161 onEnd(new Error('Checksum mismatch: ' +
157- actual.hexSlice() + ' != ' + value.hexSlice()))
158- else
162+ expected.hexSlice() + ' != ' + value.hexSlice()))
163+ } else {
164+ if (opts.verbosity >= 2)
165+ console.error('checksum ok', expected.hexSlice())
159166 onEnd(null)
167+ }
160168 })
161169 }
162170
163171 function readObject(abort, cb) {
test/git-remote-test.jsView
@@ -10,15 +10,14 @@
1010 objectSink: function (readObject) {
1111 readObject(null, function next(end, type, read) {
1212 if (end === true) return
1313 if (end) throw end
14- console.error('got object of type', type)
1514 pull(
1615 read,
1716 pull.collect(function (err, bufs) {
1817 if (err) throw err
1918 var data = Buffer.concat(bufs).toString('ascii')
20- console.error('object', data.length, data)
19+ console.error('object', type, bufs.length, data.length, JSON.stringify(data))
2120 readObject(null, next)
2221 })
2322 )
2423 })

Built with git-ssb-web