git ssb

0+

cel / pull-git-remote-helper



Tree: b390ecc4bf4d610b201252d8a8a0cd1ad8cd2748

Files: b390ecc4bf4d610b201252d8a8a0cd1ad8cd2748 / test / remote / git-remote-full.js

1494 bytesRaw
1#!/usr/bin/env node
2
3var toPull = require('stream-to-pull-stream')
4var pull = require('pull-stream')
5var repo = require('../repo')
6
7process.on('uncaughtException', function (err) {
8 if (err.stack)
9 err = {stack: err.stack, message: err.message}
10 process.send({error: err})
11 process.exit(1)
12})
13
14var HEAD = 'edb5b50e8019797925820007d318870f8c346726'
15var refs = [
16 {name: 'refs/heads/master', value: HEAD},
17 {name: 'HEAD', value: HEAD}
18]
19
20var objects = [
21 {type: 'commit', object: repo.commit},
22 {type: 'tree', object: repo.tree},
23 {type: 'blob', object: repo.file}
24]
25
26var hashes = {}
27hashes[repo.commit.hash] = 1
28hashes[repo.tree.hash] = 1
29hashes[repo.file.hash] = 1
30
31function streamObject(read) {
32 var ended
33 return function readObject(abort, cb) {
34 read(abort, function (end, item) {
35 if (ended = end) return cb(end)
36 var data = item.object.data
37 cb(null, {
38 type: item.type,
39 length: data.length,
40 read: pull.once(data)
41 })
42 })
43 }
44}
45
46pull(
47 toPull(process.stdin),
48 require('../../')({
49 refSource: pull.values(refs),
50 wantSink: pull.drain(function (want) {
51 process.send({want: want})
52 }),
53 hasObject: function (hash, cb) {
54 cb(hash in hashes)
55 },
56 getObjects: function (ancestorHash, cb) {
57 cb(null, objects.length, pull(
58 pull.values(objects),
59 streamObject
60 ))
61 }
62 }),
63 toPull(process.stdout, function (err) {
64 if (err)
65 throw err
66 process.disconnect()
67 })
68)
69

Built with git-ssb-web