git ssb

0+

cel / pull-git-remote-helper



Commit bed0b983a87d456d6c072f88bb5f7081614d4ed1

Cleanup code

Charles Lehner committed on 2/8/2016, 4:37:24 AM
Parent: 609ae28b8d57e7d4f47e0a987d5d1c7286001a60

Files changed

index.jschanged
pack.jschanged
test/pack.jschanged
test/remote/git-remote-empty.jschanged
test/remote/git-remote-full.jschanged
test/run.jschanged
index.jsView
@@ -70,9 +70,8 @@
7070 var sendRefs = receivePackHeader([
7171 ], refSource, false)
7272
7373 var lines = packLineDecode(read, options)
74- // var havesSink = pull.drain(console.error.bind(console, 'have:'))
7574 var readHave = lines.haves()
7675 var acked
7776 var commonHash
7877 var sendPack
@@ -122,9 +121,8 @@
122121 cb(end)
123122 else if (have.type != 'have')
124123 cb(new Error('Unknown have' + JSON.stringify(have)))
125124 else
126- console.error('got have', have),
127125 haveObject(have.hash, function (haveIt) {
128126 if (!haveIt)
129127 return readHave(null, next)
130128 commonHash = haveIt
@@ -157,17 +155,16 @@
157155 read(end, function (end, data) {
158156 if (ended = end) {
159157 cb(end)
160158 } else {
161- // console.error("data", data)
162159 if (data)
163160 data += '\n'
164161 else
165162 data = ''
166163 var len = data ? data.length + 4 : 0
167164 var hexLen = ('000' + len.toString(16)).substr(-4)
168165 var pkt = hexLen + data
169- console.error('>', JSON.stringify(pkt))
166+ // console.error('>', JSON.stringify(pkt))
170167 cb(end, pkt)
171168 }
172169 })
173170 }
pack.jsView
@@ -75,23 +75,14 @@
7575 queue.push([(status === 0) ? true : new Error(def.msg)])
7676 }
7777
7878 return function readOut(abort, cb) {
79- /*
80- function _cb(end, data) {
81- console.error('sending deflated', end,
82- data && JSON.stringify(data.toString()))
83- cb(end, data)
84- }
85- */
8679 if (ended)
8780 cb(ended)
8881 else if (queue.length)
8982 cb.apply(this, queue.shift())
9083 else
9184 read(abort, function next(end, data) {
92- if (data)
93- console.error('read into deflat', data.length, JSON.stringify(data))
9485 if (end === true) def.push([], true)
9586 else if (end) return cb(end)
9687 else def.push(data)
9788 readOut(null, cb)
@@ -112,9 +103,9 @@
112103 var readWord = checksum(b.chunks(4))
113104 var readChecksum = b.chunks(20)
114105 var expectChecksum = true
115106 var opts = {
116- verbosity: 2
107+ verbosity: 0
117108 }
118109
119110 function readHeader(cb) {
120111 readWord(null, function (end, header) {
@@ -154,9 +145,9 @@
154145 if (ended = end) return cb(end)
155146 var firstByte = buf[0]
156147 type = objectTypes[(firstByte >> 4) & 7]
157148 value = firstByte & 15
158- console.error('byte1', firstByte, firstByte.toString(2), value, value.toString(2))
149+ // console.error('byte1', firstByte, firstByte.toString(2))
159150 shift = 4
160151 checkByte(firstByte)
161152 })
162153
@@ -171,17 +162,17 @@
171162 if (ended = end) return cb(end)
172163 var byte = buf[0]
173164 value += (byte & 0x7f) << shift
174165 shift += 7
175- console.error('byte', byte, byte.toString(2), value, value.toString(2))
166+ // console.error('byte', byte, byte.toString(2))
176167 checkByte(byte)
177168 }
178169 }
179170
180171 function getObject(cb) {
181172 readVarInt(function (end, type, length) {
182173 if (opts.verbosity >= 2)
183- console.error('read var int', end, type, length)
174+ console.error('read object header', end, type, length)
184175 numObjects--
185176 if (end === true && expectChecksum)
186177 onEnd(new Error('Missing checksum'))
187178 if (ended = end) return cb(end)
@@ -239,11 +230,13 @@
239230 vals.push(b | 0x80)
240231 b = length & 0x7f
241232 }
242233 vals.push(b)
234+ /*
243235 console.error('sending var int', vals, vals.map(function (n) {
244236 return ('00000000' + Number(n).toString(2)).substr(-8)
245237 }))
238+ */
246239 cb(null, new Buffer(vals))
247240 }
248241
249242 /*
@@ -271,21 +264,15 @@
271264 header.writeUInt32BE(numObjects, 8)
272265 var checksum = createHash('sha1')
273266 var readData
274267
275- /*
276- return pull.through(function (data) {
277- console.error('> ' + data.length, JSON.stringify(data.toString('ascii')))
278- })(cat([
279- */
280268 return cat([
281269 checksum(cat([
282270 pull.once(header),
283271 encodeObject
284272 ])),
285273 checksum.readDigest
286274 ])
287- // )
288275
289276 function encodeObject(abort, cb) {
290277 if (readData)
291278 readData(abort, function (end, data) {
@@ -297,11 +284,10 @@
297284 else
298285 readObject(abort, nextObject)
299286
300287 function nextObject(end, type, length, read) {
301- // console.error('got obj', end, type, length)
302288 if (end) return cb(end)
303289 readData = deflate(read)
304- encodeVarInt(type, length, cb) // nextCb(deflate(read), encodeObject))
290+ encodeVarInt(type, length, cb)
305291 }
306292 }
307293 }
test/pack.jsView
@@ -9,12 +9,8 @@
99 {type: 'tree', object: repo.tree},
1010 {type: 'blob', object: repo.file}
1111 ]
1212
13-function sha1(str) {
14- return require('crypto').createHash('sha1').update(str).digest('hex')
15-}
16-
1713 function streamObject(read) {
1814 var ended
1915 return function readObject(abort, cb) {
2016 read(abort, function (end, item) {
@@ -60,16 +56,8 @@
6056 t.error(err, 'decoded pack')
6157 }),
6258 bufferObject,
6359 pull.drain(function (obj) {
64- var a = obj.object
65- var b = objects[i].object
66- if (a.hash != b.hash)
67- console.error(new Buffer(b.data))
68- console.error(a.hash, b.hash, a.data.length, b.data.length,
69- a.data === b.data,
70- '"' + objects[i].type + ' ' + b.data.length + '\0' + b.data + '"',
71- sha1(objects[i].type + ' ' + b.data.length + '\0' + b.data))
7260 if (i < objects.length)
7361 t.deepEquals(obj, objects[i++])
7462 else
7563 t.notOk(obj, 'unexpected object')
test/remote/git-remote-empty.jsView
@@ -24,9 +24,8 @@
2424 hasher,
2525 pull.collect(function (err, bufs) {
2626 if (err) throw err
2727 var buf = Buffer.concat(bufs, length)
28- console.error('obj', type, length, JSON.stringify(buf.toString('ascii')))
2928 process.send({object: {
3029 type: type,
3130 data: buf.toString('ascii'),
3231 length: length,
test/remote/git-remote-full.jsView
@@ -41,9 +41,8 @@
4141 wantSink: pull.drain(function (want) {
4242 process.send({want: want})
4343 }),
4444 getObjects: function (ancestorHash, cb) {
45- // console.error('get obj!', ancestorHash)
4645 cb(null, objects.length, pull(
4746 pull.values(objects),
4847 streamObject
4948 ))
test/run.jsView
@@ -17,9 +17,8 @@
1717
1818 var tmpDir = mktemp.createDirSync(path.join(require('os').tmpdir(), 'XXXXXXX'))
1919 tape.onFinish(function () {
2020 if (tmpDir)
21- // console.error(tmpDir)
2221 rimraf.sync(tmpDir)
2322 })
2423
2524 function handleIpcMessage(t, cb) {
@@ -112,9 +111,9 @@
112111 t.git('add', filePath, function (code) {
113112 t.equals(code, 0, 'added file')
114113 t.git('commit', '-m', commitMessage, function (code) {
115114 t.equals(code, 0, 'made initial commit')
116- t.git('push', '-vv', remote.empty, 'master', function (msg) {
115+ t.git('push', remote.empty, 'master', function (msg) {
117116 if (msg.object)
118117 objects(msg.object)
119118 else if (msg.ref)
120119 refs(msg.ref)
@@ -128,21 +127,20 @@
128127 })
129128 })
130129
131130 tape('fetch when already up-to-date', function (t) {
132- t.git('fetch', '-vv', remote.full, function (msg) {
131+ t.git('fetch', remote.full, function (msg) {
133132 t.notOk(msg, 'should not get a message here')
134133 }, function (code) {
135134 t.equals(code, 0, 'fetched')
136135 t.end()
137136 })
138137 })
139138
140-0 &&
141139 tape('clone into new dir', function (t) {
142140 var dir = path.join(tmpDir, 'clonedir')
143141 t.plan(2)
144- t.git('clone', '-vv', remote.full, dir, function (msg) {
142+ t.git('clone', remote.full, dir, function (msg) {
145143 if (msg.want)
146144 t.deepEquals(msg.want, {
147145 type: 'want',
148146 hash: 'edb5b50e8019797925820007d318870f8c346726'

Built with git-ssb-web