ssb-git-repo
Advanced tools
Comparing version 2.2.0 to 2.2.1
162
lib/repo.js
@@ -6,4 +6,2 @@ var pull = require('pull-stream') | ||
var cache = require('pull-cache') | ||
var reverse = require('pull-reverse') | ||
var pushable = require('pull-pushable') | ||
var ref = require('ssb-ref') | ||
@@ -135,5 +133,5 @@ var createGitHash = require('pull-hash/ext/git') | ||
this.output = options.output | ||
this._objects = {/* sha1: {type, length, key} */} | ||
this._blobs = {/* sha1: [Buffer] */} | ||
this._msgsByObject = {/* sha1: Msg */} | ||
this._packs = [/* {packId: blobId, idxId: blobId} */] | ||
@@ -144,8 +142,4 @@ this.updates = new KVGraph('key') | ||
// queued operations while syncing of old messages | ||
this._hashLookups = {/* sha1: [cb(err, object)] */} | ||
this._syncCbs = [] | ||
this._newPacksPushable = pushable() | ||
this._newPacks = reverse(this._newPacksPushable) | ||
this.pullReqs = PullRequests.init(this.sbot) | ||
@@ -156,3 +150,2 @@ } | ||
Repo.prototype.synced = false | ||
Repo.prototype.syncedRefs = false | ||
@@ -187,3 +180,3 @@ Repo.prototype.close = function (cb) { | ||
if (packId) { | ||
this._oldPacksPushable.push({ | ||
this._packs.push({ | ||
packId: packId, | ||
@@ -221,3 +214,3 @@ idxId: idxId | ||
if (packId) { | ||
this._newPacksPushable.push({ | ||
this._packs.push({ | ||
packId: packId, | ||
@@ -252,17 +245,2 @@ idxId: idxId | ||
Repo.prototype._getBlobCached = function (key, cb) { | ||
var blobs = this._blobs | ||
if (key in blobs) | ||
cb(null, pull.values(blobs[key])) | ||
else | ||
this._getBlob(key, function (err, read) { | ||
if (err) return cb(err) | ||
pull(read, pull.collect(function (err, bufs) { | ||
if (err) return cb(err) | ||
blobs[key] = bufs | ||
cb(null, pull.values(bufs)) | ||
})) | ||
}) | ||
} | ||
Repo.prototype._getBlobCachedOnce = function (key, cb) { | ||
@@ -280,11 +258,2 @@ // use cached blob if it exists (in case of newly pushed data) | ||
Repo.prototype._hashLookup = function hashLookup(sha1, cb) { | ||
if (this.synced || sha1 in this._objects) | ||
cb(null, this._objects[sha1]) | ||
else if (sha1 in this._hashLookups) | ||
this._hashLookups[sha1].push(cb) | ||
else | ||
this._hashLookups[sha1] = [cb] | ||
} | ||
// get refs source({name, hash}) | ||
@@ -318,13 +287,2 @@ Repo.prototype.refs = function (options) { | ||
Repo.prototype._addObject = function (sha1, object) { | ||
this._objects[sha1] = object | ||
// notify listeners waiting for the object | ||
var cbs = this._hashLookups[sha1] | ||
if (cbs) { | ||
while (cbs.length) | ||
cbs.shift()(null, object) | ||
delete this._hashLookups[sha1] | ||
} | ||
} | ||
Repo.prototype._sync = function (live) { | ||
@@ -334,3 +292,3 @@ if (live) | ||
if (this._oldPacks) { | ||
if (this.synced) { | ||
// already synced | ||
@@ -340,5 +298,2 @@ return | ||
this._oldPacksPushable = pushable() | ||
this._oldPacks = cache(this._oldPacksPushable) | ||
pull( | ||
@@ -354,14 +309,6 @@ this._readOld = this.sbot.links({ | ||
pull.drain(this._processOldMsg.bind(this), function (err) { | ||
this._oldPacksPushable.end(err) | ||
this.syncedRefs = true | ||
// complete waiting requests for lookups | ||
this.synced = true | ||
for (var sha1 in this._hashLookups) | ||
this._addObject(sha1, null) | ||
while (this._syncCbs.length) | ||
this._syncCbs.pop().call(this) | ||
if (live) | ||
@@ -406,5 +353,4 @@ this._syncNew() | ||
Repo.prototype.hasObject = function (hash, cb) { | ||
var blobs = this.sbot.blobs | ||
this._hashLookup(hash, function (err, obj) { | ||
cb(err, !!obj) | ||
this.awaitSync(function () { | ||
cb(this.hasObjectQuick(hash)) | ||
}) | ||
@@ -419,20 +365,3 @@ } | ||
Repo.prototype.getObject = function (hash, cb) { | ||
this._hashLookup(hash, function (err, obj) { | ||
if (err) return cb(err) | ||
if (!obj) return cb(new Error('Object not present with hash ' + hash)) | ||
var blobId = obj.link || obj.key | ||
if (!blobId) return cb(new Error('Object is missing blob key')) | ||
if (obj.type == 'blob') | ||
this._getBlob(blobId, gotData) | ||
else | ||
this._getBlobCached(blobId, gotData) | ||
function gotData(err, read) { | ||
if (err) return cb(err) | ||
cb(null, { | ||
type: obj.type, | ||
length: obj.length, | ||
read: read | ||
}) | ||
} | ||
}.bind(this)) | ||
cb() | ||
} | ||
@@ -449,5 +378,10 @@ | ||
Repo.prototype.packs = function (hash) { | ||
if (!this.synced) return readNext.call(this, function (cb) { | ||
this.awaitSync(function () { | ||
cb(null, this.packs(hash)) | ||
}) | ||
}) | ||
// optimization: if the hash is a commit id, look up a message that added it | ||
// and return just the pack for that. also, add the pack to the newPacks | ||
// queue so request for objects contained in that pack get priority | ||
// and return the pack for that first. | ||
if (hash) { | ||
@@ -465,4 +399,9 @@ var msg = this._msgsByObject[hash] | ||
} | ||
this._newPacksPushable.push(pack) | ||
return pull.once(pack) | ||
return pull( | ||
cat([ | ||
pull.once(pack), | ||
pull.values(this._packs) | ||
]), | ||
pull.unique('packId') | ||
) | ||
} | ||
@@ -473,9 +412,3 @@ } | ||
return pull( | ||
cat([ | ||
this._newPacks(), | ||
this._oldPacks ? this._oldPacks() : pull.empty() | ||
]), | ||
pull.unique('packId') | ||
) | ||
return pull.values(this._packs) | ||
} | ||
@@ -507,3 +440,2 @@ | ||
var refsCb = done() | ||
var pullsCb = done() | ||
var commitsInfo = [] | ||
@@ -529,3 +461,3 @@ var numCommitsPushed | ||
// so that decoding deltas in the pack works | ||
self._newPacksPushable.push({ | ||
self._packs.push({ | ||
packId: packId, | ||
@@ -646,7 +578,9 @@ idxId: idxId | ||
// get head revs of open pull requests | ||
// update the base branch of an open PR: check if the PR is merged | ||
var pullsByHead = {/* commitIdMerged: prToClose */} | ||
var pullsByHeadCb = done() | ||
pull( | ||
self.pullReqs.list({ | ||
repo: this.id, | ||
open: true | ||
open: true, | ||
repo: self.id | ||
}), | ||
@@ -656,8 +590,8 @@ pull.asyncMap(function (pr, cb) { | ||
else require('../').getRepo(self.sbot, pr.headRepo, gotRepo) | ||
function gotRepo(err, repo) { | ||
function gotRepo(err, headRepo) { | ||
if (err) return cb(err) | ||
GitRepo(repo).resolveRef(pr.headBranch, function (err, rev) { | ||
GitRepo(headRepo).resolveRef(pr.headBranch, function (err, rev) { | ||
if (err && err.name === 'NotFoundError') rev = null | ||
else if (err) return cb(err) | ||
cb(null, { id: pr.id, head: rev, headBranch: pr.headBranch }) | ||
cb(null, { id: pr.id, headRev: rev }) | ||
}) | ||
@@ -667,15 +601,29 @@ } | ||
pull.filter(), | ||
pull.collect(pullsCb) | ||
pull.drain(function (pr) { | ||
pullsByHead[pr.headRev] = pr.id | ||
}, function (err) { | ||
pullsByHeadCb(err, pullsByHead) | ||
}) | ||
) | ||
done(function (err, packs, indexes, mentions, commits, refUpdatesObj, prForks) { | ||
// update the head branch of an open PR: reply to the PR | ||
var pullsByBranch = {/* branchUpdated: prToReplyTo */} | ||
var pullsByBranchCb = done() | ||
pull( | ||
self.pullReqs.list({ | ||
open: true, | ||
headRepo: self.id | ||
}), | ||
pull.drain(function (pr) { | ||
pullsByBranch[pr.headBranch] = pr.id | ||
}, function (err) { | ||
pullsByBranchCb(err, pullsByBranch) | ||
}) | ||
) | ||
done(function (err, packs, indexes, mentions, commits, refUpdatesObj, | ||
pullsByHead, pullsByBranch) { | ||
if (err) return cb(err) | ||
if (packs.length == 0 && indexes.length == 0) packs = indexes = undefined | ||
var pullsByHead = {}, pullsByBranch = {} | ||
prForks.forEach(function (pull) { | ||
pullsByHead[pull.head] = pull.id | ||
pullsByBranch[pull.headBranch] = pull.id | ||
}) | ||
// get issues and pull requests closed | ||
@@ -871,3 +819,3 @@ var issues = [] | ||
var key = queue.shift() | ||
if (key in haveMsgs || key in seen) continue | ||
if (!key || key in haveMsgs || key in seen) continue | ||
seen[key] = true | ||
@@ -890,3 +838,5 @@ for (repo = this, msg = null; repo && !msg; repo = repo.upstream) | ||
} | ||
// TODO: get links by any property, or build this traversal into kvgraph | ||
queue.push(msg.value.previous) | ||
queue.push(c.branch) | ||
} | ||
@@ -893,0 +843,0 @@ } |
{ | ||
"name": "ssb-git-repo", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "git repos in secure-scuttlebutt", | ||
@@ -27,3 +27,2 @@ "main": "index.js", | ||
"pull-cache": "^0.0.0", | ||
"pull-reverse": "^0.0.0", | ||
"pull-cat": "^1.1.11", | ||
@@ -34,3 +33,2 @@ "pull-git-pack": "^0.2.3", | ||
"pull-hash": "^0.0.0", | ||
"pull-pushable": "^2.0.0", | ||
"pull-stream": "^3.1.0", | ||
@@ -37,0 +35,0 @@ "ssb-mentions": "^0.1.0", |
13
123968
1050
- Removedpull-pushable@^2.0.0
- Removedpull-reverse@^0.0.0
- Removedpull-pushable@2.2.0(transitive)
- Removedpull-reverse@0.0.0(transitive)