git ssb

0+

cel / pull-git-remote-helper



Commit 548ff18b7fa54b0dfe6b4e70b69367c0c1734dbf

Refactor getting wants and haves

Remove extra close callback
Charles Lehner committed on 8/1/2016, 6:40:52 AM
Parent: 4d7cb1b2be2593d1acbdfbfbab1d9c642a0017ef

Files changed

index.jschanged
index.jsView
@@ -72,17 +72,16 @@
7272 var wants = {}
7373 var shallows = {}
7474 var aborted
7575 var hasWants
76- var gotWants, gotHaves
76+ var gotHaves
7777
7878 function readWant(abort, cb) {
7979 if (abort) return
8080 // read upload request (wants list) from client
8181 readWantHave(null, function next(end, want) {
8282 if (end || want.type == 'flush-pkt') {
83- gotWants = true
84- readHave(end === true ? null : end, cb)
83+ cb(end || true, cb)
8584 return
8685 }
8786 if (want.type == 'want') {
8887 wants[want.hash] = true
@@ -102,17 +101,17 @@
102101 // On first obj-id that we have, ACK
103102 // If we have none, NAK.
104103 // TODO: implement multi_ack_detailed
105104 if (abort) return
105+ if (gotHaves) return cb(true)
106106 readWantHave(null, function next(end, have) {
107107 if (end === true) {
108108 gotHaves = true
109109 if (!acked) {
110110 cb(null, 'NAK')
111111 } else {
112112 cb(true)
113113 }
114- cb(true)
115114 } else if (have.type === 'flush-pkt') {
116115 // found no common object
117116 if (!acked) {
118117 cb(null, 'NAK')
@@ -136,37 +135,39 @@
136135 })
137136 })
138137 }
139138
139+ function readPack(abort, cb) {
140+ if (abort || aborted) return console.error('abrt', abort || aborted), cb(abort || aborted)
141+ if (sendPack) return sendPack(abort, cb)
142+ // send pack file to client
143+ if (!hasWants) return cb(true)
144+ if (options.verbosity >= 2) {
145+ console.error('common', commonHash, 'wants', wants)
146+ }
147+ getObjects(repo, commonHash, wants, shallows,
148+ function (err, numObjects, readObjects) {
149+ if (err) return cb(err)
150+ var progress = progressObjects(options)
151+ progress.setNumObjects(numObjects)
152+ sendPack = pack.encode(options, numObjects, progress(readObjects))
153+ if (options.verbosity >= 1) {
154+ console.error('retrieving', numObjects, 'git objects')
155+ }
156+ sendPack(null, cb)
157+ }
158+ )
159+ }
160+
140161 // Packfile negotiation
141162 return cat([
142163 pktLine.encode(cat([
143164 sendRefs,
144165 pull.once(''),
145- function (abort, cb) {
146- if (!gotWants) readWant(abort, cb)
147- else if (!gotHaves) readHave(abort, cb)
148- else cb(true)
149- }
166+ readWant,
167+ readHave
150168 ])),
151-
152- function (abort, cb) {
153- if (abort || aborted) return cb(abort || aborted)
154- // send pack file to client
155- if (sendPack)
156- return sendPack(abort, cb)
157- if (!hasWants) return cb(true)
158- getObjects(repo, commonHash, wants, shallows,
159- function (err, numObjects, readObjects) {
160- if (err) return cb(err)
161- var progress = progressObjects(options)
162- progress.setNumObjects(numObjects)
163- sendPack = pack.encode(options, numObjects,
164- progress(readObjects))
165- cb(null, '')
166- }
167- )
168- }
169+ readPack
169170 ])
170171 }
171172
172173 // through stream to show a progress bar for objects being read
@@ -245,8 +246,9 @@
245246 }
246247
247248 done(function (err) {
248249 if (err) return cb(err)
250+ // console.error(objects.reduce(function (n, obj) { return obj.length + n}, 0) + ' bytes')
249251 cb(null, objects.length, pull.values(objects))
250252 })
251253 }
252254

Built with git-ssb-web