Commit bed0b983a87d456d6c072f88bb5f7081614d4ed1
Cleanup code
Charles Lehner committed on 2/8/2016, 4:37:24 AMParent: 609ae28b8d57e7d4f47e0a987d5d1c7286001a60
Files changed
index.js | changed |
pack.js | changed |
test/pack.js | changed |
test/remote/git-remote-empty.js | changed |
test/remote/git-remote-full.js | changed |
test/run.js | changed |
index.js | ||
---|---|---|
@@ -70,9 +70,8 @@ | ||
70 | 70 | var sendRefs = receivePackHeader([ |
71 | 71 | ], refSource, false) |
72 | 72 | |
73 | 73 | var lines = packLineDecode(read, options) |
74 | - // var havesSink = pull.drain(console.error.bind(console, 'have:')) | |
75 | 74 | var readHave = lines.haves() |
76 | 75 | var acked |
77 | 76 | var commonHash |
78 | 77 | var sendPack |
@@ -122,9 +121,8 @@ | ||
122 | 121 | cb(end) |
123 | 122 | else if (have.type != 'have') |
124 | 123 | cb(new Error('Unknown have' + JSON.stringify(have))) |
125 | 124 | else |
126 | - console.error('got have', have), | |
127 | 125 | haveObject(have.hash, function (haveIt) { |
128 | 126 | if (!haveIt) |
129 | 127 | return readHave(null, next) |
130 | 128 | commonHash = haveIt |
@@ -157,17 +155,16 @@ | ||
157 | 155 | read(end, function (end, data) { |
158 | 156 | if (ended = end) { |
159 | 157 | cb(end) |
160 | 158 | } else { |
161 | - // console.error("data", data) | |
162 | 159 | if (data) |
163 | 160 | data += '\n' |
164 | 161 | else |
165 | 162 | data = '' |
166 | 163 | var len = data ? data.length + 4 : 0 |
167 | 164 | var hexLen = ('000' + len.toString(16)).substr(-4) |
168 | 165 | var pkt = hexLen + data |
169 | - console.error('>', JSON.stringify(pkt)) | |
166 | + // console.error('>', JSON.stringify(pkt)) | |
170 | 167 | cb(end, pkt) |
171 | 168 | } |
172 | 169 | }) |
173 | 170 | } |
pack.js | ||
---|---|---|
@@ -75,23 +75,14 @@ | ||
75 | 75 | queue.push([(status === 0) ? true : new Error(def.msg)]) |
76 | 76 | } |
77 | 77 | |
78 | 78 | 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 | - */ | |
86 | 79 | if (ended) |
87 | 80 | cb(ended) |
88 | 81 | else if (queue.length) |
89 | 82 | cb.apply(this, queue.shift()) |
90 | 83 | else |
91 | 84 | read(abort, function next(end, data) { |
92 | - if (data) | |
93 | - console.error('read into deflat', data.length, JSON.stringify(data)) | |
94 | 85 | if (end === true) def.push([], true) |
95 | 86 | else if (end) return cb(end) |
96 | 87 | else def.push(data) |
97 | 88 | readOut(null, cb) |
@@ -112,9 +103,9 @@ | ||
112 | 103 | var readWord = checksum(b.chunks(4)) |
113 | 104 | var readChecksum = b.chunks(20) |
114 | 105 | var expectChecksum = true |
115 | 106 | var opts = { |
116 | - verbosity: 2 | |
107 | + verbosity: 0 | |
117 | 108 | } |
118 | 109 | |
119 | 110 | function readHeader(cb) { |
120 | 111 | readWord(null, function (end, header) { |
@@ -154,9 +145,9 @@ | ||
154 | 145 | if (ended = end) return cb(end) |
155 | 146 | var firstByte = buf[0] |
156 | 147 | type = objectTypes[(firstByte >> 4) & 7] |
157 | 148 | value = firstByte & 15 |
158 | - console.error('byte1', firstByte, firstByte.toString(2), value, value.toString(2)) | |
149 | + // console.error('byte1', firstByte, firstByte.toString(2)) | |
159 | 150 | shift = 4 |
160 | 151 | checkByte(firstByte) |
161 | 152 | }) |
162 | 153 | |
@@ -171,17 +162,17 @@ | ||
171 | 162 | if (ended = end) return cb(end) |
172 | 163 | var byte = buf[0] |
173 | 164 | value += (byte & 0x7f) << shift |
174 | 165 | shift += 7 |
175 | - console.error('byte', byte, byte.toString(2), value, value.toString(2)) | |
166 | + // console.error('byte', byte, byte.toString(2)) | |
176 | 167 | checkByte(byte) |
177 | 168 | } |
178 | 169 | } |
179 | 170 | |
180 | 171 | function getObject(cb) { |
181 | 172 | readVarInt(function (end, type, length) { |
182 | 173 | if (opts.verbosity >= 2) |
183 | - console.error('read var int', end, type, length) | |
174 | + console.error('read object header', end, type, length) | |
184 | 175 | numObjects-- |
185 | 176 | if (end === true && expectChecksum) |
186 | 177 | onEnd(new Error('Missing checksum')) |
187 | 178 | if (ended = end) return cb(end) |
@@ -239,11 +230,13 @@ | ||
239 | 230 | vals.push(b | 0x80) |
240 | 231 | b = length & 0x7f |
241 | 232 | } |
242 | 233 | vals.push(b) |
234 | + /* | |
243 | 235 | console.error('sending var int', vals, vals.map(function (n) { |
244 | 236 | return ('00000000' + Number(n).toString(2)).substr(-8) |
245 | 237 | })) |
238 | + */ | |
246 | 239 | cb(null, new Buffer(vals)) |
247 | 240 | } |
248 | 241 | |
249 | 242 | /* |
@@ -271,21 +264,15 @@ | ||
271 | 264 | header.writeUInt32BE(numObjects, 8) |
272 | 265 | var checksum = createHash('sha1') |
273 | 266 | var readData |
274 | 267 | |
275 | - /* | |
276 | - return pull.through(function (data) { | |
277 | - console.error('> ' + data.length, JSON.stringify(data.toString('ascii'))) | |
278 | - })(cat([ | |
279 | - */ | |
280 | 268 | return cat([ |
281 | 269 | checksum(cat([ |
282 | 270 | pull.once(header), |
283 | 271 | encodeObject |
284 | 272 | ])), |
285 | 273 | checksum.readDigest |
286 | 274 | ]) |
287 | - // ) | |
288 | 275 | |
289 | 276 | function encodeObject(abort, cb) { |
290 | 277 | if (readData) |
291 | 278 | readData(abort, function (end, data) { |
@@ -297,11 +284,10 @@ | ||
297 | 284 | else |
298 | 285 | readObject(abort, nextObject) |
299 | 286 | |
300 | 287 | function nextObject(end, type, length, read) { |
301 | - // console.error('got obj', end, type, length) | |
302 | 288 | if (end) return cb(end) |
303 | 289 | readData = deflate(read) |
304 | - encodeVarInt(type, length, cb) // nextCb(deflate(read), encodeObject)) | |
290 | + encodeVarInt(type, length, cb) | |
305 | 291 | } |
306 | 292 | } |
307 | 293 | } |
test/pack.js | ||
---|---|---|
@@ -9,12 +9,8 @@ | ||
9 | 9 | {type: 'tree', object: repo.tree}, |
10 | 10 | {type: 'blob', object: repo.file} |
11 | 11 | ] |
12 | 12 | |
13 | -function sha1(str) { | |
14 | - return require('crypto').createHash('sha1').update(str).digest('hex') | |
15 | -} | |
16 | - | |
17 | 13 | function streamObject(read) { |
18 | 14 | var ended |
19 | 15 | return function readObject(abort, cb) { |
20 | 16 | read(abort, function (end, item) { |
@@ -60,16 +56,8 @@ | ||
60 | 56 | t.error(err, 'decoded pack') |
61 | 57 | }), |
62 | 58 | bufferObject, |
63 | 59 | 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)) | |
72 | 60 | if (i < objects.length) |
73 | 61 | t.deepEquals(obj, objects[i++]) |
74 | 62 | else |
75 | 63 | t.notOk(obj, 'unexpected object') |
test/remote/git-remote-empty.js | ||
---|---|---|
@@ -24,9 +24,8 @@ | ||
24 | 24 | hasher, |
25 | 25 | pull.collect(function (err, bufs) { |
26 | 26 | if (err) throw err |
27 | 27 | var buf = Buffer.concat(bufs, length) |
28 | - console.error('obj', type, length, JSON.stringify(buf.toString('ascii'))) | |
29 | 28 | process.send({object: { |
30 | 29 | type: type, |
31 | 30 | data: buf.toString('ascii'), |
32 | 31 | length: length, |
test/remote/git-remote-full.js | ||
---|---|---|
@@ -41,9 +41,8 @@ | ||
41 | 41 | wantSink: pull.drain(function (want) { |
42 | 42 | process.send({want: want}) |
43 | 43 | }), |
44 | 44 | getObjects: function (ancestorHash, cb) { |
45 | - // console.error('get obj!', ancestorHash) | |
46 | 45 | cb(null, objects.length, pull( |
47 | 46 | pull.values(objects), |
48 | 47 | streamObject |
49 | 48 | )) |
test/run.js | ||
---|---|---|
@@ -17,9 +17,8 @@ | ||
17 | 17 | |
18 | 18 | var tmpDir = mktemp.createDirSync(path.join(require('os').tmpdir(), 'XXXXXXX')) |
19 | 19 | tape.onFinish(function () { |
20 | 20 | if (tmpDir) |
21 | - // console.error(tmpDir) | |
22 | 21 | rimraf.sync(tmpDir) |
23 | 22 | }) |
24 | 23 | |
25 | 24 | function handleIpcMessage(t, cb) { |
@@ -112,9 +111,9 @@ | ||
112 | 111 | t.git('add', filePath, function (code) { |
113 | 112 | t.equals(code, 0, 'added file') |
114 | 113 | t.git('commit', '-m', commitMessage, function (code) { |
115 | 114 | 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) { | |
117 | 116 | if (msg.object) |
118 | 117 | objects(msg.object) |
119 | 118 | else if (msg.ref) |
120 | 119 | refs(msg.ref) |
@@ -128,21 +127,20 @@ | ||
128 | 127 | }) |
129 | 128 | }) |
130 | 129 | |
131 | 130 | 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) { | |
133 | 132 | t.notOk(msg, 'should not get a message here') |
134 | 133 | }, function (code) { |
135 | 134 | t.equals(code, 0, 'fetched') |
136 | 135 | t.end() |
137 | 136 | }) |
138 | 137 | }) |
139 | 138 | |
140 | -0 && | |
141 | 139 | tape('clone into new dir', function (t) { |
142 | 140 | var dir = path.join(tmpDir, 'clonedir') |
143 | 141 | t.plan(2) |
144 | - t.git('clone', '-vv', remote.full, dir, function (msg) { | |
142 | + t.git('clone', remote.full, dir, function (msg) { | |
145 | 143 | if (msg.want) |
146 | 144 | t.deepEquals(msg.want, { |
147 | 145 | type: 'want', |
148 | 146 | hash: 'edb5b50e8019797925820007d318870f8c346726' |
Built with git-ssb-web