diff options
| author | Scott Prager <splinterofchaos@gmail.com> | 2015-06-05 13:15:36 -0400 |
|---|---|---|
| committer | Scott Prager <splinterofchaos@gmail.com> | 2015-06-06 19:00:15 -0400 |
| commit | ff2e993343f689312a51c1bbbf620c05e41a4f62 (patch) | |
| tree | 8867b88441a2a11e38d023df8c47a0b8280a3133 /git-remote-gittorrent | |
| parent | 5b990d68094cd1390cb8e729d36a7974d9a0aa84 (diff) | |
Use `git ls-remote` to get local refs.
`git ls-remote` gives us the same info as `git-upload-pack`, but in an
easier to parse format. We can also share the code for interpreting
`git ls-remote` between git-remote-gittorrent and gittorrentd.
This also fixes the problem of `publish_mutable_key()` being called too
soon.
Diffstat (limited to 'git-remote-gittorrent')
| -rwxr-xr-x | git-remote-gittorrent | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/git-remote-gittorrent b/git-remote-gittorrent index aeffc90..ad9825b 100755 --- a/git-remote-gittorrent +++ b/git-remote-gittorrent @@ -12,6 +12,7 @@ var ut_gittorrent = require('ut_gittorrent') var WebTorrent = require('webtorrent') var zeroFill = require('zero-fill') var config = require('./config') +var git = require('./git') // BitTorrent client version string (used in peer ID). // Generated from package.json major and minor version. For example: @@ -99,31 +100,15 @@ if (matches) { }) } else { url = url.replace(/^gittorrent:/i, 'git:') - exec('git ls-remote ' + url, function (err, stdout, stderr) { - if (err !== null) { + var ls = git.ls(url, function (sha, branch) { + refs[branch] = sha + }) + ls.on('exit', function (err) { + if (err) { die(err) } - var lines = stdout.split('\n') - if (lines.length < 2) { - die("Didn't get back a single HEAD ref: " + lines) - } - lines.forEach(function (line) { - if (line === '') { - // Last line: publish - dht.on('ready', function () { - talk_to_git(refs) - }) - return - } - - line = line.split('\t') - var sha = line[0] - var branch = line[1] - if (sha.length !== 40) { - console.warn('Was expecting a 40-byte sha: ' + sha + '\n') - console.warn('on line: ' + line.join('\t')) - } - refs[branch] = sha + dht.on('ready', function () { + talk_to_git(refs) }) }) } |
