aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 18:00:41 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 18:32:14 -1000
commitdd3e70672100b33e373e0fa69e56767b600bb6ec (patch)
treefe041fde1f2b12f5384a9ba73f15e98293eb5345
parent00d61405ca36e8d160cc992acc3660d1cf73e2f3 (diff)
downloadpatchfoo-dd3e70672100b33e373e0fa69e56767b600bb6ec.tar.gz
patchfoo-dd3e70672100b33e373e0fa69e56767b600bb6ec.zip
factor out getting git object links
-rw-r--r--lib/serve.js76
1 files changed, 34 insertions, 42 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 64aa82b..9d907e0 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -1406,33 +1406,11 @@ Serve.prototype.gitCommit = function (rev) {
]) : '',
commit.parents.length ? ph('div', ['parents: ', pull(
pull.values(commit.parents),
- paramap(function (id, cb) {
- self.app.git.getObjectMsg({
- obj: id,
- headMsgId: obj.msg.key,
- }, function (err, msg) {
- var path = '/git/commit/' + id
- + '?msg=' + encodeURIComponent(msg.key)
- cb(null, [ph('code', ph('a', {
- href: self.app.render.toUrl(path)
- }, id.substr(0, 8))), ' '])
- })
- }, 4)
+ self.gitObjectLinks(obj.msg.key, 'commit')
)]) : '',
commit.tree ? ph('div', ['tree: ', pull(
pull.once(commit.tree),
- pull.asyncMap(function (id, cb) {
- self.app.git.getObjectMsg({
- obj: id,
- headMsgId: obj.msg.key,
- }, function (err, msg) {
- var path = '/git/tree/' + id
- + '?msg=' + encodeURIComponent(msg.key)
- cb(null, [ph('code', ph('a', {
- href: self.app.render.toUrl(path)
- }, id.substr(0, 8))), ' '])
- })
- })
+ self.gitObjectLinks(obj.msg.key, 'tree')
)]) : '',
h('pre', self.app.render.linkify(commit.body)).outerHTML,
]
@@ -1501,19 +1479,7 @@ Serve.prototype.gitTag = function (rev) {
tag.type, ' ',
pull(
pull.once(tag.object),
- pull.asyncMap(function (id, cb) {
- self.app.git.getObjectMsg({
- obj: id,
- type: tag.type,
- headMsgId: obj.msg.key,
- }, function (err, msg) {
- var path = '/git/' + tag.type + '/' + id
- + '?msg=' + encodeURIComponent(msg.key)
- cb(null, [ph('code', ph('a', {
- href: self.app.render.toUrl(path)
- }, id.substr(0, 8))), ' '])
- })
- })
+ self.gitObjectLinks(obj.msg.key, tag.type)
), ' ',
ph('code', u.escapeHTML(tag.tag)),
h('pre', self.app.render.linkify(tag.body)).outerHTML,
@@ -1581,21 +1547,26 @@ Serve.prototype.gitTree = function (rev) {
pull.map(function (item) {
var type = item.mode === 0040000 ? 'tree' :
item.mode === 0160000 ? 'commit' : 'blob'
+ if (!item.msg) return ph('tr', [
+ ph('td',
+ u.escapeHTML(item.name) + (type === 'tree' ? '/' : '')),
+ ph('td', 'missing')
+ ])
var path = '/git/' + type + '/' + item.hash
+ '?msg=' + encodeURIComponent(item.msg.key)
var fileDate = new Date(item.msg.value.timestamp)
return ph('tr', [
ph('td',
ph('a', {href: self.app.render.toUrl(path)},
- item.name + (type === 'tree' ? '/' : ''))),
- item.msg ? ph('td',
- self.phIdLink(item.msg.value.author)) : '',
- item.msg ? ph('td',
+ u.escapeHTML(item.name) + (type === 'tree' ? '/' : ''))),
+ ph('td',
+ self.phIdLink(item.msg.value.author)),
+ ph('td',
ph('a', {
href: self.app.render.toUrl(item.msg.key),
title: fileDate.toLocaleString(),
}, htime(fileDate))
- ) : '',
+ ),
])
})
)
@@ -1666,6 +1637,27 @@ Serve.prototype.gitBlob = function (rev) {
})
}
+Serve.prototype.gitObjectLinks = function (headMsgId, type) {
+ var self = this
+ return paramap(function (id, cb) {
+ self.app.git.getObjectMsg({
+ obj: id,
+ headMsgId: headMsgId,
+ type: type,
+ }, function (err, msg) {
+ if (err && err.name === 'ObjectNotFoundError')
+ return cb(null, [
+ ph('code', u.escapeHTML(id.substr(0, 8))), '(missing)'])
+ if (err) return cb(err)
+ var path = '/git/' + type + '/' + id
+ + '?msg=' + encodeURIComponent(msg.key)
+ cb(null, [ph('code', ph('a', {
+ href: self.app.render.toUrl(path)
+ }, u.escapeHTML(id.substr(0, 8)))), ' '])
+ })
+ }, 8)
+}
+
// wrap a binary source and render it or turn into an embed
Serve.prototype.wrapBinary = function (opts) {
var self = this