diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serve.js | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js index db9be20..a28f758 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1863,6 +1863,7 @@ Serve.prototype.wrapUserFeed = function (isScrolled, id) { Serve.prototype.git = function (url) { var m = /^\/?([^\/]*)\/?(.*)?$/.exec(url) switch (m[1]) { + case 'object': return this.gitObject(m[2]) case 'commit': return this.gitCommit(m[2]) case 'tag': return this.gitTag(m[2]) case 'tree': return this.gitTree(m[2]) @@ -1884,7 +1885,7 @@ Serve.prototype.gitRaw = function (rev) { } if (!u.isRef(self.query.msg)) return pull( ph('div.error', 'missing message id'), - self.wrapPage('git tree ' + rev), + self.wrapPage('git object ' + rev), self.respondSink(400) ) @@ -1927,6 +1928,63 @@ Serve.prototype.gitAuthorLink = function (author) { } } +Serve.prototype.gitObject = function (rev) { + var self = this + if (!/[0-9a-f]{24}/.test(rev)) { + return pull( + ph('div.error', 'rev is not a git object id'), + self.wrapPage('git'), + self.respondSink(400) + ) + } + if (!u.isRef(self.query.msg)) return pull( + ph('div.error', 'missing message id'), + self.wrapPage('git object ' + rev), + self.respondSink(400) + ) + + if (self.query.search) { + return self.app.git.getObjectMsg({ + obj: rev, + headMsgId: self.query.msg, + }, function (err, msg) { + if (err && err.name === 'BlobNotFoundError') + return self.askWantBlobs(err.links) + if (err) return pull( + pull.once(u.renderError(err).outerHTML), + self.wrapPage('git object ' + rev), + self.respondSink(400) + ) + var path = '/git/object/' + rev + + '?msg=' + encodeURIComponent(msg.key) + return self.redirect(self.app.render.toUrl(path)) + }) + } + + self.app.git.openObject({ + obj: rev, + msg: self.query.msg, + }, function (err, obj) { + if (err && err.name === 'BlobNotFoundError') + return self.askWantBlobs(err.links) + if (err) return pull( + pull.once(u.renderError(err).outerHTML), + self.wrapPage('git object ' + rev), + self.respondSink(400) + ) + self.app.git.statObject(obj, function (err, stat) { + if (err) return pull( + pull.once(u.renderError(err).outerHTML), + self.wrapPage('git object ' + rev), + self.respondSink(400) + ) + var path = '/git/' + stat.type + '/' + rev + + '?msg=' + encodeURIComponent(self.query.msg) + return self.redirect(self.app.render.toUrl(path)) + }) + }) +} + Serve.prototype.gitCommit = function (rev) { var self = this if (!/[0-9a-f]{24}/.test(rev)) { |