git ssb

0+

cel / pull-git-remote-helper



Commit 72559d01b2c758ea8f14e5d23a18138cee44a010

Start using packfiles and pack index files

Charles Lehner committed on 3/3/2016, 9:42:40 PM
Parent: 01e73fb890f3f2e30d516751d7063b8da952d463

Files changed

index.jschanged
lib/index-pack.jsadded
package.jsonchanged
test/index-pack.jsadded
index.jsView
@@ -1,9 +1,11 @@
11 var pull = require('pull-stream')
22 var cat = require('pull-cat')
3+var cache = require('pull-cache')
34 var buffered = require('pull-buffered')
45 var pack = require('./lib/pack')
56 var pktLine = require('./lib/pkt-line')
7+var indexPack = require('./lib/index-pack')
68 var util = require('./lib/util')
79 var multicb = require('multicb')
810 var ProgressBar = require('progress')
911
@@ -57,8 +59,9 @@
5759 /* multi_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress
5860 * include-tag multi_ack_detailed
5961 * agent=git/2.7.0 */
6062 var sendRefs = receivePackHeader([
63+ 'thin-pack',
6164 ], repo.refs(), repo.symrefs(), false)
6265
6366 var lines = pktLine.decode(read, options)
6467 var readHave = lines.haves()
@@ -366,18 +369,29 @@
366369 pull.collect(function (err, updates) {
367370 if (err) return cb(err)
368371 if (updates.length === 0) return cb(true)
369372 var progress = progressObjects(options)
370- repo.update(pull.values(updates), pull(
371- lines.passthrough,
372- pack.decode({
373- verbosity: options.verbosity,
374- onHeader: function (numObjects) {
375- progress.setNumObjects(numObjects)
376- }
377- }, repo, done()),
378- progress
379- ), done())
373+
374+ if (repo.uploadPack) {
375+ var idxCb = done()
376+ var packfile = cache(lines.passthrough)
377+ indexPack(packfile(), function (err, idx) {
378+ if (err) return idxCb(err)
379+ repo.uploadPack(pull.values(updates), packfile(), idx, idxCb)
380+ })
381+ } else {
382+ repo.update(pull.values(updates), pull(
383+ lines.passthrough,
384+ pack.decode({
385+ verbosity: options.verbosity,
386+ onHeader: function (numObjects) {
387+ progress.setNumObjects(numObjects)
388+ }
389+ }, repo, done()),
390+ progress
391+ ), done())
392+ }
393+
380394 done(function (err) {
381395 cb(err || true)
382396 })
383397 })
lib/index-pack.jsView
@@ -1,0 +1,27 @@
1+var pull = require('pull-stream')
2+var toPull = require('stream-to-pull-stream')
3+var cp = require('child_process')
4+var fs = require('fs')
5+var path = require('path')
6+var os = require('os')
7+
8+module.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 args = ['index-pack', '--stdin', '-o', indexFilename, packFilename]
14+ var child = cp.spawn('git', args, {
15+ stdio: ['pipe', 'pipe', 'inherit']
16+ })
17+ pull(packFile, toPull.sink(child.stdin))
18+ child.on('close', function (err) {
19+ if (err) return cb(err)
20+ fs.unlink(packFilename, function (err) {
21+ if (err) return cb(err)
22+ cb(null, toPull(fs.createReadStream(indexFilename), function (err) {
23+ if (err) return console.error(err)
24+ }))
25+ })
26+ })
27+}
package.jsonView
@@ -27,8 +27,9 @@
2727 "progress": "^1.1.8",
2828 "pull-buffered": "^0.3.0",
2929 "pull-cat": "^1.1.8",
3030 "pull-stream": "^3.1.0",
31+ "pull-cache": "^0.0.0",
3132 "stream-to-pull-stream": "^1.6.6"
3233 },
3334 "devDependencies": {
3435 "mktemp": "^0.4.0",
test/index-pack.jsView
@@ -1,0 +1,21 @@
1+var tape = require('tape')
2+var indexPack = require('../lib/index-pack')
3+var pull = require('pull-stream')
4+var toPull = require('stream-to-pull-stream')
5+var cp = require('child_process')
6+
7+tape('index-pack produces output', function (t) {
8+ var child = cp.spawn('git', ['pack-objects', '--stdout', '--revs'])
9+ child.stdin.end('HEAD\n')
10+ indexPack(toPull.source(child.stdout), function (err, idx) {
11+ t.error(err, 'index pack')
12+ pull(idx, pull.reduce(function (val, buf) {
13+ return val + buf.length
14+ }, 0, function (err, length) {
15+ t.error(err, 'read index pack')
16+ t.comment('len: ' + length)
17+ t.ok(length > 0, 'length')
18+ t.end()
19+ }))
20+ })
21+})

Built with git-ssb-web