git ssb

0+

cel / pull-git-remote-helper



Commit eead209ce126ffd087a7c49489717bf124bdda58

Handle push-options

cel committed on 5/21/2018, 2:15:55 PM
Parent: 9c05c1c900d10939caf231cd5987f540e19d96ee

Files changed

index.jschanged
lib/pkt-line.jschanged
index.jsView
@@ -289,17 +289,22 @@
289289 }
290290
291291 // receive-pack: push from client
292292 function receivePack(read, repo, options) {
293- var sendRefs = receivePackHeader([
293 + var serverCaps = [
294294 agentCap,
295295 'delete-refs',
296296 'quiet',
297- 'no-thin',
298- ], repo.refs(), null)
297 + 'no-thin'
298 + ]
299 + if (repo.setPushOptions) serverCaps.push('push-options')
300 + var sendRefs = receivePackHeader(serverCaps, repo.refs(), null)
299301 var done = multicb({pluck: 1})
300302
303 + var clientCaps = {}
304 +
301305 function onCaps(caps) {
306 + clientCaps = caps
302307 if (options.verbosity >= 2) {
303308 console.error('client capabilities:', caps)
304309 }
305310 }
@@ -320,49 +325,61 @@
320325 lines.updates,
321326 pull.collect(function (err, updates) {
322327 if (err) return cb(err)
323328 if (updates.length === 0) return cb(true)
324- var progress = progressObjects(options)
329 + var usePushOpts = clientCaps['push-options']
330 + pull(
331 + usePushOpts ? lines.pktLineStrs : pull.empty(),
332 + pull.reduce(function (opts, opt) {
333 + opts[opt] = true
334 + return opts
335 + }, {}, pushOptsCb)
336 + )
337 + function pushOptsCb(err, pushOpts) {
338 + if (err) return cb(err)
339 + repo.setPushOptions(pushOpts)
340 + var progress = progressObjects(options)
325341
326- var hasPack = !updates.every(function (update) {
327- return update.new === null
328- })
329- if (repo.uploadPack) {
330- if (!hasPack) {
331- repo.uploadPack(pull.values(updates), pull.empty(), done())
342 + var hasPack = !updates.every(function (update) {
343 + return update.new === null
344 + })
345 + if (repo.uploadPack) {
346 + if (!hasPack) {
347 + repo.uploadPack(pull.values(updates), pull.empty(), done())
348 + } else {
349 + var idxCb = done()
350 + pull(lines.passthrough, indexPack(function (err, idx, packfileFixed) {
351 + if (err) return idxCb(err)
352 + repo.uploadPack(pull.values(updates), pull.once({
353 + pack: pull(
354 + packfileFixed,
355 + // for some reason i was getting zero length buffers which
356 + // were causing muxrpc to fail, so remove them here.
357 + pull.filter(function (buf) {
358 + return buf.length
359 + })
360 + ),
361 + idx: idx
362 + }), idxCb)
363 + }))
364 + }
332365 } else {
333- var idxCb = done()
334- pull(lines.passthrough, indexPack(function (err, idx, packfileFixed) {
335- if (err) return idxCb(err)
336- repo.uploadPack(pull.values(updates), pull.once({
337- pack: pull(
338- packfileFixed,
339- // for some reason i was getting zero length buffers which
340- // were causing muxrpc to fail, so remove them here.
341- pull.filter(function (buf) {
342- return buf.length
343- })
344- ),
345- idx: idx
346- }), idxCb)
347- }))
366 + repo.update(pull.values(updates), !hasPack ? pull.empty() : pull(
367 + lines.passthrough,
368 + pack.decode({
369 + verbosity: options.verbosity,
370 + onHeader: function (numObjects) {
371 + progress.setNumObjects(numObjects)
372 + }
373 + }, repo, done()),
374 + progress
375 + ), done())
348376 }
349- } else {
350- repo.update(pull.values(updates), !hasPack ? pull.empty() : pull(
351- lines.passthrough,
352- pack.decode({
353- verbosity: options.verbosity,
354- onHeader: function (numObjects) {
355- progress.setNumObjects(numObjects)
356- }
357- }, repo, done()),
358- progress
359- ), done())
377 +
378 + done(function (err) {
379 + cb(err || true)
380 + })
360381 }
361-
362- done(function (err) {
363- cb(err || true)
364- })
365382 })
366383 )
367384 },
368385 pull.once('unpack ok')
lib/pkt-line.jsView
@@ -65,8 +65,17 @@
6565 cb(null, line)
6666 })
6767 }
6868
69 + function readPackLineStr1(abort, cb) {
70 + if (ended) return cb(ended)
71 + readPackLine(abort, function (end, buf) {
72 + if (ended = end) return cb(end)
73 + if (buf.length === 0) return cb(true)
74 + cb(null, buf.toString('utf8'))
75 + })
76 + }
77 +
6978 function readUpdate(abort, cb) {
7079 readPackLine(abort, function (end, line) {
7180 if (end) return cb(end)
7281 if (!line.length) return cb(true)
@@ -75,9 +84,9 @@
7584 var caps = args2[1]
7685 if (caps) {
7786 if (options.onCaps) {
7887 var capsSet = {}
79- caps.split(' ').forEach(function (cap) {
88 + caps.trim().split(' ').forEach(function (cap) {
8089 capsSet[cap] = true
8190 })
8291 options.onCaps(capsSet)
8392 }
@@ -110,8 +119,9 @@
110119 }
111120 }
112121
113122 b.pktLines = readPackLine
123 + b.pktLineStrs = readPackLineStr1
114124 b.updates = readUpdate
115125 b.wants = b.haves = havesWants
116126
117127 return b

Built with git-ssb-web