aboutsummaryrefslogtreecommitdiff
path: root/gittorrentd
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2015-06-06 16:17:35 -0400
committerScott Prager <splinterofchaos@gmail.com>2015-06-06 19:00:15 -0400
commit25bcaeaa0c66cdb9219517dc479444f4d7938c83 (patch)
tree0171d1334128b8e77403321610de7e0437c6556d /gittorrentd
parentff2e993343f689312a51c1bbbf620c05e41a4f62 (diff)
gittorrentd: Use git-upload-pack for pack files.
Add `upload_pack` to the git module to (partially) implement the pack protocol, then use this in gittorrentd instead of `git pack-objects`. This lets us generate packs based off HEAD instead of packing the whole tree each time.
Diffstat (limited to 'gittorrentd')
-rwxr-xr-xgittorrentd39
1 files changed, 22 insertions, 17 deletions
diff --git a/gittorrentd b/gittorrentd
index aa043d1..d498590 100755
--- a/gittorrentd
+++ b/gittorrentd
@@ -72,6 +72,8 @@ function bpad (n, buf) {
}
}
+var head = ''
+
dht.on('ready', function () {
// Spider all */.git dirs and announce all refs.
var repos = glob.sync('*/{,.git/}git-daemon-export-ok', {strict: false})
@@ -89,6 +91,9 @@ dht.on('ready', function () {
if (ref !== 'HEAD' && !ref.match(/^refs\/heads\//)) {
return
}
+ if (ref === 'refs/heads/master') {
+ head = sha
+ }
userProfile.repositories[reponame][ref] = sha
if (!announcedRefs[sha]) {
console.log('Announcing ' + sha + ' for ' + ref + ' on repo ' + repo)
@@ -148,19 +153,23 @@ dht.on('ready', function () {
wire.handshake(new Buffer(infoHash), new Buffer(myPeerId))
})
wire.ut_gittorrent.on('generatePack', function (sha) {
- console.error('calling git pack-objects')
- var filename = sha + '.pack'
- var stream = fs.createWriteStream(filename)
+ console.error('calling git pack-objects for ' + sha)
if (!announcedRefs[sha]) {
console.error('Asked for an unknown sha: ' + sha)
return
}
var directory = announcedRefs[sha]
- var pack = spawn('git', ['pack-objects', '--revs', '--thin', '--stdout', '--delta-base-offset'], {cwd: directory})
- pack.on('close', function (code) {
- if (code !== 0) {
- console.error('git pack-objects process exited with code ' + code)
- } else {
+ var have = null
+ if (sha !== head) {
+ have = head
+ }
+ var pack = git.upload_pack(directory, sha, have)
+ pack.stderr.pipe(process.stderr)
+ pack.on('ready', function () {
+ var filename = sha + '.pack'
+ var stream = fs.createWriteStream(filename)
+ pack.stdout.pipe(stream)
+ stream.on('close', function () {
console.error('Finished writing ' + filename)
var webtorrent = new WebTorrent({
dht: {bootstrap: config.dht.bootstrap},
@@ -170,17 +179,13 @@ dht.on('ready', function () {
console.error(torrent.infoHash)
wire.ut_gittorrent.sendTorrent(torrent.infoHash)
})
- }
- })
- pack.stdout.pipe(stream)
- pack.stderr.on('data', function (data) {
- console.error(data.toString())
+ })
})
- pack.on('exit', function () {
- console.log('exited')
+ pack.on('exit', function (code) {
+ if (code !== 0) {
+ console.error('git-upload-pack process exited with code ' + code)
+ }
})
- pack.stdin.write(sha + '\n')
- pack.stdin.write('--not\n\n')
})
}).listen(config.dht.announce)
})