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 | |
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.
-rw-r--r-- | lib/serve.js | 60 | ||||
-rw-r--r-- | package-lock.json | 6 | ||||
-rw-r--r-- | package.json | 2 |
3 files changed, 63 insertions, 5 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)) { diff --git a/package-lock.json b/package-lock.json index e1be009..59d33f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1317,9 +1317,9 @@ } }, "ssb-git": { - "version": "0.7.1", - "resolved": "http://localhost:8989/blobs/get/&sQqSlpG9fBzYqW/kNkcfnEBJ1tQ9N4h+kF2eGVvZLKw=.sha256", - "integrity": "sha256-sQqSlpG9fBzYqW/kNkcfnEBJ1tQ9N4h+kF2eGVvZLKw=", + "version": "1.1.0", + "resolved": "http://localhost:8989/blobs/get/&HEydVBFrhR36PYmxiFJg9ncV+ji/+rt8XZQaC9v3caY=.sha256", + "integrity": "sha256-HEydVBFrhR36PYmxiFJg9ncV+ji/+rt8XZQaC9v3caY=", "requires": { "asyncmemo": "^1.1.0", "hashlru": "^2.1.0", diff --git a/package.json b/package.json index 6b8deaa..c6e3eea 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "pull-split": "^0.2.0", "pull-stream": "^3.5.0", "pull-utf8-decoder": "^1.0.2", - "ssb-git": "^0.7.0", + "ssb-git": "^1.1.0", "ssb-marked": "^0.7.1", "ssb-mentions": "^0.5.0", "ssb-sort": "^1.0.0", |