aboutsummaryrefslogtreecommitdiff
path: root/gittorrentd
diff options
context:
space:
mode:
Diffstat (limited to 'gittorrentd')
-rwxr-xr-xgittorrentd63
1 files changed, 20 insertions, 43 deletions
diff --git a/gittorrentd b/gittorrentd
index 0ac810d..aa043d1 100755
--- a/gittorrentd
+++ b/gittorrentd
@@ -15,6 +15,7 @@ var ut_metadata = require('ut_metadata')
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:
@@ -83,55 +84,31 @@ dht.on('ready', function () {
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')
- lines.forEach(function (line) {
- var arr = line.toString().split(' ')
- if (arr.length < 2) {
- return
- }
- var sha = arr[0].toString()
- // First four chars are git-upload-pack's length-of-line metadata.
- sha = sha.substring(4)
- if (arr.length == 2) {
- var ref = arr[1].toString()
- 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
- dht.announce(sha, config.dht.announce, function (err) {
- if (err !== null) {
- console.log('Announced ' + sha)
- }
- })
+ var ls = git.ls(repo, function (sha, ref) {
+ // FIXME: Can't pull in too many branches, so only do heads for now.
+ if (ref !== 'HEAD' && !ref.match(/^refs\/heads\//)) {
+ return
+ }
+ userProfile.repositories[reponame][ref] = sha
+ if (!announcedRefs[sha]) {
+ console.log('Announcing ' + sha + ' for ' + ref + ' on repo ' + repo)
+ announcedRefs[sha] = repo
+ dht.announce(sha, config.dht.announce, function (err) {
+ if (err !== null) {
+ console.log('Announced ' + sha)
}
- } else if (arr.length > 2 && arr[1].search(/^HEAD/) !== -1) {
- // Probably the first line; line[0] has the hash, line[1] has HEAD,
- // and beyond are the supported features.
- userProfile.repositories[reponame]['HEAD'] = sha
- }
- })
- // Callback counting for repos
+ })
+ }
+ })
+ ls.stdout.on('end', function () {
count--
if (count <= 0) {
publish_mutable_key()
}
})
- upload.stdout.on('end', function () {
- console.log('end')
- })
- upload.on('exit', function (code) {
- if (code !== 0) {
- die('Failed: ' + code)
+ ls.on('exit', function (err) {
+ if (err) {
+ die(err)
}
})
})