index.jsView |
---|
88 | 88 | } |
89 | 89 | |
90 | 90 | function uploadPack(read) { |
91 | 91 | return function (abort, cb) { |
92 | | - cb('upload pack not implemented') |
| 92 | + var lines = packLineDecode(read) |
| 93 | + receiveRefs(lines.packLines, function (err, refs) { |
| 94 | + console.error('refs', refs, err) |
| 95 | + if (err) return cb(err) |
| 96 | + }) |
93 | 97 | } |
94 | | - |
95 | 98 | } |
96 | 99 | |
97 | 100 | function getRefs() { |
98 | 101 | return pull.values([ |
155 | 158 | */ |
156 | 159 | |
157 | 160 | |
158 | 161 | |
159 | | -function receivePackHeader(capabilities) { |
160 | | - var readRef = getRefs() |
| 162 | +function receivePackHeader(capabilities, refsSource) { |
161 | 163 | var first = true |
162 | 164 | var ended |
163 | 165 | return function (abort, cb) { |
164 | 166 | if (ended) return cb(true) |
165 | | - readRef(abort, function (end, ref) { |
| 167 | + refsSource(abort, function (end, ref) { |
166 | 168 | ended = end |
167 | 169 | var name = ref && ref.name |
168 | 170 | var hash = ref && ref.hash |
169 | 171 | if (first) { |
190 | 192 | }) |
191 | 193 | objectSink(objects) |
192 | 194 | } |
193 | 195 | |
194 | | -function receivePack(read, objectSink) { |
| 196 | +function receiveRefs(readLine, cb) { |
| 197 | + var refs = [] |
| 198 | + readLine(null, function next(end, line) { |
| 199 | + if (end) |
| 200 | + cb(end) |
| 201 | + else if (line.length == 0) |
| 202 | + cb(null, refs) |
| 203 | + else { |
| 204 | + var args = split2(line.toString('ascii')) |
| 205 | + refs.push({ |
| 206 | + hash: args[0], |
| 207 | + name: args[1] |
| 208 | + }) |
| 209 | + readLine(null, next) |
| 210 | + } |
| 211 | + }) |
| 212 | +} |
| 213 | + |
| 214 | +function receivePack(read, objectSink, refsSource) { |
195 | 215 | var ended |
196 | | - var sendRefs = receivePackHeader([]) |
| 216 | + var sendRefs = receivePackHeader([], refsSource) |
197 | 217 | |
198 | | - function receiveRefs(readLine, cb) { |
199 | | - var refs = [] |
200 | | - readLine(null, function next(end, line) { |
201 | | - |
202 | | - if (end === true) |
203 | | - cb(new Error('refs line ended early')) |
204 | | - else */ |
205 | | - if (end) |
206 | | - cb(end) |
207 | | - else if (line === '') |
208 | | - cb(null, refs) |
209 | | - else { |
210 | | - var args = split2(line) |
211 | | - refs.push({ |
212 | | - hash: args[0], |
213 | | - name: args[1] |
214 | | - }) |
215 | | - readLine(null, next) |
216 | | - } |
217 | | - }) |
218 | | - } |
219 | | - |
220 | 218 | return packLineEncode( |
221 | 219 | cat([ |
222 | 220 | |
223 | 221 | sendRefs, |
226 | 224 | if (abort) return |
227 | 225 | |
228 | 226 | var lines = packLineDecode(read) |
229 | 227 | receiveRefs(lines.packLines, function (err, refs) { |
230 | | - if (refs) |
231 | | - console.error('refs', refs, err) |
| 228 | + |
232 | 229 | if (err) return cb(err) |
233 | 230 | |
234 | 231 | receiveActualPack(lines.passthrough, objectSink, function (err) { |
235 | 232 | if (err) return cb(err) |
257 | 254 | module.exports = function (opts) { |
258 | 255 | var ended |
259 | 256 | var prefix = opts.prefix |
260 | 257 | var objectSink = opts.objectSink |
| 258 | + var refsSource = opts.refsSource || pull.empty() |
261 | 259 | |
262 | 260 | function handleConnect(cmd, read) { |
263 | 261 | var args = split2(cmd) |
264 | 262 | switch (args[0]) { |
265 | 263 | case 'git-upload-pack': |
266 | 264 | return prepend('\n', uploadPack(read)) |
267 | 265 | case 'git-receive-pack': |
268 | | - return prepend('\n', receivePack(read), objectSink) |
| 266 | + return prepend('\n', receivePack(read, objectSink, refsSource)) |
269 | 267 | default: |
270 | 268 | return pull.error(new Error('Unknown service ' + args[0])) |
271 | 269 | } |
272 | 270 | } |