git ssb

0+

cel / pull-git-remote-helper



Commit b2cf98073f3c52efa61e1a9d9a2a6b4af4944906

Add haveObject to API

Charles Lehner committed on 2/8/2016, 4:37:24 AM
Parent: bed0b983a87d456d6c072f88bb5f7081614d4ed1

Files changed

index.jschanged
test/remote/git-remote-full.jschanged
index.jsView
@@ -62,9 +62,9 @@
6262 }
6363 }
6464
6565 // upload-pack: fetch to client
66-function uploadPack(read, getObjects, refSource, wantSink, options) {
66+function uploadPack(read, haveObject, getObjects, refSource, wantSink, options) {
6767 /* multi_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress
6868 * include-tag multi_ack_detailed symref=HEAD:refs/heads/master
6969 * agent=git/2.7.0 */
7070 var sendRefs = receivePackHeader([
@@ -76,13 +76,8 @@
7676 var commonHash
7777 var sendPack
7878 var earlyDisconnect
7979
80- function haveObject(hash, cb) {
81- cb(/* TODO */)
82- // cb(true)
83- }
84-
8580 // Packfile negotiation
8681 return cat([
8782 packLineEncode(cat([
8883 sendRefs,
@@ -253,30 +248,8 @@
253248 })
254249 }
255250 }
256251
257- /*
258- function readWant(abort, cb) {
259- readPackLine(abort, function (end, line) {
260- if (end) return cb(end)
261- if (options.verbosity >= 2)
262- console.error('line', line.toString('ascii'))
263- if (!line.length || line == 'done') {
264- console.error('WANTS done', line, line.length)
265- return cb(true)
266- }
267- var args = split3(line.toString('ascii'))
268- var caps = args[2]
269- if (caps && options.verbosity >= 2)
270- console.error('want capabilities:', caps)
271- cb(null, {
272- type: args[0],
273- hash: args[1].replace(/\n$/, ''),
274- })
275- })
276- }
277- */
278-
279252 b.packLines = readPackLine
280253 b.updates = readUpdate
281254 b.wants = b.haves = havesWants
282255
@@ -378,8 +351,9 @@
378351
379352 module.exports = function (opts) {
380353 var ended
381354 var objectSink = opts.objectSink
355+ var haveObject = opts.haveObject || function (hash, cb) { cb(false) }
382356 var getObjects = opts.getObjects || function (id, cb) {
383357 cb(null, 0, pull.empty())
384358 }
385359 var refSource = opts.refSource || pull.empty()
@@ -394,9 +368,9 @@
394368 function handleConnect(cmd, read) {
395369 var args = split2(cmd)
396370 switch (args[0]) {
397371 case 'git-upload-pack':
398- return prepend('\n', uploadPack(read, getObjects, refSource,
372+ return prepend('\n', uploadPack(read, haveObject, getObjects, refSource,
399373 wantSink, options))
400374 case 'git-receive-pack':
401375 return prepend('\n', receivePack(read, objectSink, refSource,
402376 refSink, options))
test/remote/git-remote-full.jsView
@@ -22,8 +22,13 @@
2222 {type: 'tree', object: repo.tree},
2323 {type: 'blob', object: repo.file}
2424 ]
2525
26+var hashes = {}
27+hashes[repo.commit.hash] = 1
28+hashes[repo.tree.hash] = 1
29+hashes[repo.file.hash] = 1
30+
2631 function streamObject(read) {
2732 var ended
2833 return function readObject(abort, cb) {
2934 read(abort, function (end, item) {
@@ -40,8 +45,11 @@
4045 refSource: pull.values(refs),
4146 wantSink: pull.drain(function (want) {
4247 process.send({want: want})
4348 }),
49+ haveObject: function (hash, cb) {
50+ cb(hash in hashes)
51+ },
4452 getObjects: function (ancestorHash, cb) {
4553 cb(null, objects.length, pull(
4654 pull.values(objects),
4755 streamObject

Built with git-ssb-web