Files: b390ecc4bf4d610b201252d8a8a0cd1ad8cd2748 / test / remote / git-remote-full.js
1494 bytesRaw
1 | |
2 | |
3 | var toPull = require('stream-to-pull-stream') |
4 | var pull = require('pull-stream') |
5 | var repo = require('../repo') |
6 | |
7 | process.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 | |
14 | var HEAD = 'edb5b50e8019797925820007d318870f8c346726' |
15 | var refs = [ |
16 | {name: 'refs/heads/master', value: HEAD}, |
17 | {name: 'HEAD', value: HEAD} |
18 | ] |
19 | |
20 | var objects = [ |
21 | {type: 'commit', object: repo.commit}, |
22 | {type: 'tree', object: repo.tree}, |
23 | {type: 'blob', object: repo.file} |
24 | ] |
25 | |
26 | var hashes = {} |
27 | hashes[repo.commit.hash] = 1 |
28 | hashes[repo.tree.hash] = 1 |
29 | hashes[repo.file.hash] = 1 |
30 | |
31 | function 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 | |
46 | pull( |
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