Commit 72559d01b2c758ea8f14e5d23a18138cee44a010
Start using packfiles and pack index files
Charles Lehner committed on 3/3/2016, 9:42:40 PMParent: 01e73fb890f3f2e30d516751d7063b8da952d463
Files changed
index.js | changed |
lib/index-pack.js | added |
package.json | changed |
test/index-pack.js | added |
index.js | ||
---|---|---|
@@ -1,9 +1,11 @@ | ||
1 | 1 | var pull = require('pull-stream') |
2 | 2 | var cat = require('pull-cat') |
3 | +var cache = require('pull-cache') | |
3 | 4 | var buffered = require('pull-buffered') |
4 | 5 | var pack = require('./lib/pack') |
5 | 6 | var pktLine = require('./lib/pkt-line') |
7 | +var indexPack = require('./lib/index-pack') | |
6 | 8 | var util = require('./lib/util') |
7 | 9 | var multicb = require('multicb') |
8 | 10 | var ProgressBar = require('progress') |
9 | 11 | |
@@ -57,8 +59,9 @@ | ||
57 | 59 | /* multi_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress |
58 | 60 | * include-tag multi_ack_detailed |
59 | 61 | * agent=git/2.7.0 */ |
60 | 62 | var sendRefs = receivePackHeader([ |
63 | + 'thin-pack', | |
61 | 64 | ], repo.refs(), repo.symrefs(), false) |
62 | 65 | |
63 | 66 | var lines = pktLine.decode(read, options) |
64 | 67 | var readHave = lines.haves() |
@@ -366,18 +369,29 @@ | ||
366 | 369 | pull.collect(function (err, updates) { |
367 | 370 | if (err) return cb(err) |
368 | 371 | if (updates.length === 0) return cb(true) |
369 | 372 | 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 | + | |
380 | 394 | done(function (err) { |
381 | 395 | cb(err || true) |
382 | 396 | }) |
383 | 397 | }) |
lib/index-pack.js | ||
---|---|---|
@@ -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.json | ||
---|---|---|
@@ -27,8 +27,9 @@ | ||
27 | 27 | "progress": "^1.1.8", |
28 | 28 | "pull-buffered": "^0.3.0", |
29 | 29 | "pull-cat": "^1.1.8", |
30 | 30 | "pull-stream": "^3.1.0", |
31 | + "pull-cache": "^0.0.0", | |
31 | 32 | "stream-to-pull-stream": "^1.6.6" |
32 | 33 | }, |
33 | 34 | "devDependencies": { |
34 | 35 | "mktemp": "^0.4.0", |
test/index-pack.js | ||
---|---|---|
@@ -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