diff options
| author | Scott Prager <splinterofchaos@gmail.com> | 2015-06-01 18:37:51 -0400 |
|---|---|---|
| committer | Scott Prager <splinterofchaos@gmail.com> | 2015-06-03 13:34:16 -0400 |
| commit | bb100e41ab357e5a991db6496c7cbec4b26c4848 (patch) | |
| tree | 3c29dbdfbb628fbe5370282ea2b8d31dcc92b91a /gittorrentd | |
| parent | 61579b5ee99d9a51ad94ec14a205d4f96cefa6b5 (diff) | |
support branches
git-remote-gittorrent:
Call `git ls-remote` without the 'HEAD' argument to get all references and
build a list of them. Use a different swarm for each ref and don't quit until
we have them all.
gittorrentd:
Parse the branch name out of references and store the sha's in
userProfile[reponame][branch] instead of userProfile[reponame].master.
Diffstat (limited to 'gittorrentd')
| -rwxr-xr-x | gittorrentd | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/gittorrentd b/gittorrentd index 130731f..5e8808e 100755 --- a/gittorrentd +++ b/gittorrentd @@ -36,7 +36,6 @@ var dht = new DHT({ dht.listen(6881) var announcedRefs = { - master: {} } var userProfile = { repositories: {} @@ -79,37 +78,49 @@ dht.on('ready', function () { var repos = glob.sync('*/{,.git/}git-daemon-export-ok', {strict: false}) var count = repos.length repos.forEach(function (repo) { + count-- console.log('in repo ' + repo) repo = repo.replace(/git-daemon-export-ok$/, '') console.log(repo) + + var reponame = repo.replace(/\/.git\/$/, '') + userProfile.repositories[reponame] = {} + var upload = spawn('git-upload-pack', ['--strict', repo]) upload.stdout.on('data', function (line) { var lines = line.toString().split('\n') + var linecount = lines.length lines.forEach(function (line) { + linecount-- var arr = line.toString().split(' ') - if (arr.length === 2) { + if (arr.length == 2) { var sha = arr[0].toString() // First four chars are git-upload-pack's length-of-line metadata. sha = sha.substring(4) var ref = arr[1].toString() - if (ref.search(/^refs\/heads\//) !== -1 || ref.search(/^refs\/remotes\//) !== -1) { - if (!announcedRefs.master[sha]) { - console.log('Announcing ' + sha + ' for ref ' + ref + ' on repo ' + repo) - announcedRefs.master[sha] = repo - var reponame = repo.replace(/\/.git\/$/, '') - userProfile.repositories[reponame] = {} - userProfile.repositories[reponame].master = sha - // Callback counting for repos - count-- - if (count <= 0) { - publish_mutable_key() - } - dht.announce(sha, 30000, function (err) { - if (err !== null) { - console.log('Announced ' + sha) - } - }) + var branch = ref.match(/^refs\/heads\/(.*)/) + // FIXME: Can't pull in too many branches. + // if (!branch) { + // branch = ref.match(/^refs\/remotes\/(.*)/) + // } + if (branch) { + userProfile.repositories[reponame][ref] = sha + } + if (branch && !announcedRefs[sha]) { + branch = branch[1] + console.log('Announcing ' + sha + ' for ' + branch + ' on repo ' + repo) + announcedRefs[sha] = repo + userProfile.repositories[reponame][branch] = sha + // Callback counting for repos + // TODO: count == 0 too soon! + if (count <= 0) { + publish_mutable_key() } + dht.announce(sha, 30000, function (err) { + if (err !== null) { + console.log('Announced ' + sha) + } + }) } } }) @@ -154,7 +165,7 @@ dht.on('ready', function () { wire.use(ut_metadata()) socket.pipe(wire).pipe(socket) wire.on('handshake', function (infoHash, peerId) { - console.log('Received handshake for ' + infoHash) + console.log('Received handshake for ' + infoHash.toString('hex')) var myPeerId = new Buffer('-WW' + VERSION + '-' + hat(48), 'utf8') wire.handshake(new Buffer(infoHash), new Buffer(myPeerId)) }) @@ -162,10 +173,11 @@ dht.on('ready', function () { console.error('calling git pack-objects') var filename = sha + '.pack' var stream = fs.createWriteStream(filename) - if (!announcedRefs.master[sha]) { - console.error('Asked for an unknown sha!') + if (!announcedRefs[sha]) { + console.error('Asked for an unknown sha: ' + sha) + return } - var directory = announcedRefs.master[sha] + 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) { |
