diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-11-30 14:53:52 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-11-30 14:53:52 -1000 |
commit | 328b6ffd8dc1a0cb66111a0ae8b346c5c2aad8f5 (patch) | |
tree | 2e210d8529dc4717030aaa5523a9d5387ff211c8 /lib | |
parent | 35fd4cfba80c0e434d082778e6105629165b33d7 (diff) | |
download | patchfoo-328b6ffd8dc1a0cb66111a0ae8b346c5c2aad8f5.tar.gz patchfoo-328b6ffd8dc1a0cb66111a0ae8b346c5c2aad8f5.zip |
Add git object page
Allows linking to a git object without knowing its type.
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)) { |