aboutsummaryrefslogtreecommitdiff
path: root/git-remote-gittorrent
diff options
context:
space:
mode:
Diffstat (limited to 'git-remote-gittorrent')
-rwxr-xr-xgit-remote-gittorrent43
1 files changed, 11 insertions, 32 deletions
diff --git a/git-remote-gittorrent b/git-remote-gittorrent
index aeffc90..bb76dc8 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)
})
})
}
@@ -140,13 +125,6 @@ dht.on('peer', function (addr, hash, from) {
goal.swarm.addPeer(addr)
})
-function update_ref (sha) {
- fetching[sha].branches.forEach(function (branch) {
- branch = remotename + '/' + branch
- spawn('git', ['update-ref', branch, sha])
- })
-}
-
function get_infohash (sha, branch) {
branch = branch.replace(/^refs\/(heads\/)?/, '')
branch = branch.replace(/\/head$/, '')
@@ -185,8 +163,10 @@ function get_infohash (sha, branch) {
tracker: false
})
client.download(infoHash, function (torrent) {
- console.warn('Downloading git pack with infohash: ' + chalk.green(infoHash) + '\n')
+ console.warn('Downloading ' + chalk.green(torrent.files[0].path) +
+ ' with infohash: ' + chalk.green(infoHash) + '\n')
torrent.on('done', function (done) {
+ console.warn('done downloading: ' + chalk.green(torrent.files[0].path))
fetching[sha].got = true
var stream = torrent.files[0].createReadStream()
@@ -194,7 +174,6 @@ function get_infohash (sha, branch) {
stream.pipe(unpack.stdin)
unpack.stderr.pipe(process.stderr)
unpack.on('exit', function (code) {
- update_ref(sha)
todo--
if (todo <= 0) {
// These writes are actually necessary for git to finish