git ssb

0+

cel / pull-git-remote-helper



Tree: 3743a50e99ae0400aabf3a4a34e510181b274aea

Files: 3743a50e99ae0400aabf3a4a34e510181b274aea / lib / index-pack.js

1194 bytesRaw
1var pull = require('pull-stream')
2var toPull = require('stream-to-pull-stream')
3var cp = require('child_process')
4var fs = require('fs')
5var path = require('path')
6var os = require('os')
7
8module.exports = function (packFile, cb) {
9 var name = Math.random().toString(36).substr(2)
10 var indexFilename = path.join(os.tmpdir(), name + '.idx')
11 var packFilename = path.join(os.tmpdir(), name + '.pack')
12
13 var child = cp.spawn('git', ['index-pack', '--stdin', '--fix-thin',
14 '-o', indexFilename, packFilename], {
15 stdio: ['pipe', 'pipe', 'inherit']
16 })
17 pull(packFile, toPull.sink(child.stdin))
18 child.on('close', function (err) {
19 if (err) return cb(new Error('git index-pack returned ' + err))
20 cb(null,
21 toPull(fs.createReadStream(indexFilename), function (err) {
22 fs.unlink(indexFilename, function (err) {
23 if (err) return console.error(err)
24 })
25 }),
26 // the output packfile here is the original packfile transformed to make
27 // it not thin.
28 toPull(fs.createReadStream(packFilename), function (err) {
29 fs.unlink(packFilename, function (err) {
30 if (err) return console.error(err)
31 })
32 })
33 )
34 })
35}
36

Built with git-ssb-web