aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js70
1 files changed, 67 insertions, 3 deletions
diff --git a/lib/serve.js b/lib/serve.js
index aaf558f..4923667 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -24,6 +24,8 @@ var jpeg = require('jpeg-autorotate')
var unzip = require('unzip')
var Catch = require('pull-catch')
var Diff = require('diff')
+var split = require('pull-split')
+var utf8 = require('pull-utf8-decoder')
module.exports = Serve
@@ -2032,6 +2034,7 @@ Serve.prototype.gitBlob = function (rev) {
missingBlobs ? self.askWantBlobsForm(missingBlobs) : pull(
self.app.git.readObject(obj),
self.wrapBinary({
+ obj: obj,
rawUrl: self.app.render.toUrl('/git/raw/' + rev
+ '?msg=' + encodeURIComponent(msg.key)),
ext: self.query.ext
@@ -2624,6 +2627,7 @@ Serve.prototype.zip = function (url) {
Serve.prototype.wrapBinary = function (opts) {
var self = this
var ext = opts.ext
+ var hash = opts.obj.hash
return function (read) {
var readRendered, type
read = ident(function (_ext) {
@@ -2660,9 +2664,69 @@ Serve.prototype.wrapBinary = function (opts) {
})(read)
}))
}
- return ph('pre', pull.map(function (buf) {
- return self.app.render.highlight(buf.toString('utf8'), ext)
- })(read))
+ var i = 0
+ var updateMsg = opts.obj.msg
+ var commitId = self.query.commit
+ var filePath = self.query.path
+ var lineComments = opts.lineComments || {}
+ return u.readNext(function (cb) {
+ if (commitId && filePath) {
+ self.app.getLineComments({
+ obj: opts.obj,
+ hash: hash,
+ }, gotLineComments)
+ } else {
+ gotLineComments(null, {})
+ }
+ function gotLineComments(err, lineComments) {
+ if (err) return cb(err)
+ cb(null, ph('table',
+ pull(
+ read,
+ utf8(),
+ split(),
+ pull.map(function (line) {
+ var lineNum = i++
+ var id = hash + '-' + lineNum
+ var idEnc = encodeURIComponent(id)
+ return [
+ ph('tr', [
+ ph('td', ph('a', {
+ name: id,
+ href: '?msg=' + encodeURIComponent(self.query.msg)
+ + '&commit=' + encodeURIComponent(self.query.commit)
+ + '&path=' + encodeURIComponent(self.query.path)
+ + '&comment=' + idEnc
+ + '#' + idEnc
+ }, String(lineNum))),
+ ph('td', ph('pre', self.app.render.highlight(line, ext)))
+ ]),
+ (lineComments[lineNum] ?
+ ph('tr',
+ ph('td', {colspan: 4},
+ self.renderLineCommentThread(lineComments[lineNum], id)
+ )
+ )
+ : self.query.comment === id ?
+ ph('tr',
+ ph('td', {colspan: 4},
+ self.renderLineCommentForm({
+ id: id,
+ line: lineNum,
+ updateId: updateMsg.key,
+ repoId: updateMsg.value.content.repo,
+ commitId: commitId,
+ filePath: filePath,
+ })
+ )
+ )
+ : '')
+ ]
+ })
+ )
+ ))
+ }
+ })
}
}