lib/pack.jsView |
---|
94 | 94 | }) |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | | -function decodePack(repo, onEnd, read) { |
| 98 | +function decodePack(opts, repo, onEnd, read) { |
99 | 99 | if (read === undefined) |
100 | | - return decodePack.bind(this, repo, onEnd) |
| 100 | + return decodePack.bind(this, opts, repo, onEnd) |
101 | 101 | |
102 | 102 | var ended |
103 | 103 | var numObjects = -1 |
104 | 104 | var checksum = createHash('sha1') |
108 | 108 | var readWord = checksum(b.chunks(4)) |
109 | 109 | var readHash = checksum(b.chunks(20)) |
110 | 110 | var readChecksum = b.chunks(20) |
111 | 111 | var expectChecksum = true |
112 | | - var opts = { |
113 | | - verbosity: 2 |
114 | | - } |
115 | 112 | |
116 | 113 | function readHeader(cb) { |
117 | 114 | readWord(null, function (end, header) { |
118 | 115 | if (ended = end) return cb(end) |
137 | 134 | function readNumObjects(cb) { |
138 | 135 | readWord(null, function (end, word) { |
139 | 136 | if (ended = end) return cb(end) |
140 | 137 | numObjects = word.readUInt32BE() |
141 | | - if (opts.verbosity >= 1) |
| 138 | + if (opts.verbosity >= 2) |
142 | 139 | console.error(numObjects + ' objects') |
143 | 140 | readObject(null, cb) |
144 | 141 | }) |
145 | 142 | } |
204 | 201 | readVarInt(readInflatedByte, function (err, expectedSourceLength) { |
205 | 202 | if (err) return cb(err) |
206 | 203 | readVarInt(readInflatedByte, function (err, expectedTargetLength) { |
207 | 204 | if (err) return cb(err) |
| 205 | + if (opts.verbosity >= 3) |
| 206 | + console.error('getting object', sourceHash) |
208 | 207 | repo.getObject(sourceHash, function (err, sourceObject) { |
| 208 | + if (opts.verbosity >= 3) |
| 209 | + console.error('got object', sourceHash, sourceObject, err) |
209 | 210 | if (err) return cb(err) |
210 | 211 | if (sourceObject.length != expectedSourceLength) |
211 | 212 | cb(new Error('Incorrect source object size in ref delta')) |
212 | 213 | else |
213 | | - patchObject(b, length, sourceObject, expectedTargetLength, cb) |
| 214 | + patchObject(opts, b, length, sourceObject, |
| 215 | + expectedTargetLength, cb) |
214 | 216 | }) |
215 | 217 | }) |
216 | 218 | }) |
217 | 219 | }) |
227 | 229 | if (!value.equals(expected)) { |
228 | 230 | onEnd(new Error('Checksum mismatch: ' + |
229 | 231 | expected.hexSlice() + ' != ' + value.hexSlice())) |
230 | 232 | } else { |
231 | | - if (opts.verbosity >= 2) |
| 233 | + if (opts.verbosity >= 3) |
232 | 234 | console.error('checksum ok', expected.hexSlice()) |
233 | 235 | onEnd(null) |
234 | 236 | } |
235 | 237 | }) |
259 | 261 | cb(null, value) |
260 | 262 | }) |
261 | 263 | } |
262 | 264 | |
263 | | -function patchObject(deltaB, deltaLength, srcObject, targetLength, cb) { |
| 265 | +function patchObject(opts, deltaB, deltaLength, srcObject, targetLength, cb) { |
264 | 266 | var readByte = deltaB.chunks(1) |
265 | 267 | var srcBuf |
266 | 268 | var ended |
267 | 269 | |
268 | | - |
| 270 | + if (opts.verbosity >= 2) |
| 271 | + console.error('patching', srcObject.type, targetLength) |
269 | 272 | pull( |
270 | 273 | srcObject.read, |
271 | 274 | pull.collect(function (err, bufs) { |
272 | 275 | srcBuf = Buffer.concat(bufs, srcObject.length) |
364 | 367 | */ |
365 | 368 | cb(null, new Buffer(vals)) |
366 | 369 | } |
367 | 370 | |
368 | | -function encodePack(numObjects, readObject) { |
| 371 | +function encodePack(opts, numObjects, readObject) { |
369 | 372 | if (readObject === undefined) |
370 | 373 | return encodePack.bind(this, numObjects) |
371 | 374 | |
372 | 375 | var header = new Buffer(12) |