git ssb

0+

cel / pull-git-remote-helper



Commit 447d29c36ed45ee032fa6a0992dbfe00cde5c370

Improve handling fetch

Attempt to fix "protocol error: bad line length character: PACK"

%qthVDhsG8K9D+Gxu7Tfv80zaqWZRRVQ6cKsHaH13EjI=.sha256
%MLgz/gNze1DuaaxAdkwSFuYMCN9muuFzeXThIaIV6PE=.sha256
Charles Lehner committed on 7/30/2016, 8:14:26 PM
Parent: c6fc135c4c7adad4f6abd11c17e4b23ae6544228

Files changed

index.jschanged
lib/pkt-line.jschanged
index.jsView
@@ -64,72 +64,81 @@
6464 'thin-pack',
6565 ], repo.refs(), repo.symrefs(), false)
6666
6767 var lines = pktLine.decode(read, options)
68- var readHave = lines.haves()
68+ var readWantHave = lines.haves()
6969 var acked
7070 var commonHash
7171 var sendPack
7272 var wants = {}
7373 var shallows = {}
7474 var aborted
75+ var gotWants
7576
77+ function readWant(abort, cb) {
78+ if (abort) return
79+ // read upload request (wants list) from client
80+ readWantHave(null, function next(end, want) {
81+ if (end || want.type == 'flush-pkt') {
82+ gotWants = true
83+ readHave(end === true ? null : end, cb)
84+ return
85+ }
86+ if (want.type == 'want') {
87+ wants[want.hash] = true
88+ } else if (want.type == 'shallow') {
89+ shallows[want.hash] = true
90+ } else {
91+ var err = new Error("Unknown thing", want.type, want.hash)
92+ return readWantHave(err, function (e) { cb(e || err) })
93+ }
94+ readWantHave(null, next)
95+ })
96+ }
97+
98+ function readHave(abort, cb) {
99+ // Read upload haves (haves list).
100+ // On first obj-id that we have, ACK
101+ // If we have none, NAK.
102+ // TODO: implement multi_ack_detailed
103+ if (abort) return
104+ readWantHave(null, function next(end, have) {
105+ if (end === true) {
106+ cb(true)
107+ } else if (have.type === 'flush-pkt') {
108+ // found no common object
109+ if (!acked) {
110+ cb(null, 'NAK')
111+ } else {
112+ readWantHave(null, next)
113+ }
114+ } else if (end)
115+ cb(end)
116+ else if (have.type != 'have')
117+ cb(new Error('Unknown have' + JSON.stringify(have)))
118+ else if (acked)
119+ readWantHave(null, next)
120+ else
121+ repo.hasObjectFromAny(have.hash, function (err, haveIt) {
122+ if (err) return cb(err)
123+ if (!haveIt)
124+ return readWantHave(null, next)
125+ commonHash = haveIt
126+ acked = true
127+ cb(null, 'ACK ' + have.hash)
128+ })
129+ })
130+ }
131+
76132 // Packfile negotiation
77133 return cat([
78134 pktLine.encode(cat([
79135 sendRefs,
80136 pull.once(''),
81137 function (abort, cb) {
82- if (abort) return
83- if (acked) return cb(true)
84-
85- // read upload request (wants list) from client
86- var readWant = lines.wants()
87- readWant(null, function (end, want) {
88- if (end === true) return cb(aborted = true) // early client disconnect
89- else if (end) cb(end)
90- else nextWant(null, want)
91- })
92- function nextWant(end, want) {
93- if (end) return wantsDone(end === true ? null : end)
94- if (want.type == 'want') {
95- wants[want.hash] = true
96- } else if (want.type == 'shallow') {
97- shallows[want.hash] = true
98- } else {
99- var err = new Error("Unknown thing", want.type, want.hash)
100- return readWant(err, function (e) { cb(e || err) })
101- }
102- readWant(null, nextWant)
103- }
104-
105- function wantsDone(err) {
106- if (err) return cb(err)
107- // Read upload haves (haves list).
108- // On first obj-id that we have, ACK
109- // If we have none, NAK.
110- // TODO: implement multi_ack_detailed
111- readHave(null, function next(end, have) {
112- if (end === true) {
113- // found no common object
114- acked = true
115- cb(null, 'NAK')
116- } else if (end)
117- cb(end)
118- else if (have.type != 'have')
119- cb(new Error('Unknown have' + JSON.stringify(have)))
120- else
121- repo.hasObjectFromAny(have.hash, function (err, haveIt) {
122- if (err) return cb(err)
123- if (!haveIt)
124- return readHave(null, next)
125- commonHash = haveIt
126- acked = true
127- cb(null, 'ACK ' + have.hash)
128- })
129- })
130- }
131- },
138+ if (!gotWants) readWant(abort, cb)
139+ else readHave(abort, cb)
140+ }
132141 ])),
133142
134143 function havesDone(abort, cb) {
135144 if (abort || aborted) return cb(abort || aborted)
@@ -142,9 +151,9 @@
142151 var progress = progressObjects(options)
143152 progress.setNumObjects(numObjects)
144153 sendPack = pack.encode(options, numObjects,
145154 progress(readObjects))
146- havesDone(abort, cb)
155+ cb(null, '')
147156 }
148157 )
149158 }
150159 ])
lib/pkt-line.jsView
@@ -90,10 +90,10 @@
9090 readPackLineStr(abort, function (end, line) {
9191 if (end) return abortCb(cb, end, onEnd)
9292 if (options.verbosity >= 2)
9393 console.error('line', line)
94- if (!line.length || line == 'done')
95- return abortCb(cb, true, onEnd)
94+ if (line === 'done') return abortCb(cb, true, onEnd)
95+ if (line.length === 0) return cb(null, {type: 'flush-pkt'})
9696 var args = util.split3(line)
9797 var caps = args[2]
9898 if (caps && options.verbosity >= 2)
9999 console.error('want capabilities:', caps)

Built with git-ssb-web