aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/serve.js70
-rw-r--r--package-lock.json20
-rw-r--r--package.json2
3 files changed, 87 insertions, 5 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,
+ })
+ )
+ )
+ : '')
+ ]
+ })
+ )
+ ))
+ }
+ })
}
}
diff --git a/package-lock.json b/package-lock.json
index 3a9bf62..905c326 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -182,7 +182,8 @@
},
"diff": {
"version": "3.3.1",
- "resolved": "http://localhost:8989/blobs/get/&+6G9mvp4Q/5bujMKlbFdbrub2IXMPleXIqTqyyvY5Ww=.sha256"
+ "resolved": "http://localhost:8989/blobs/get/&+6G9mvp4Q/5bujMKlbFdbrub2IXMPleXIqTqyyvY5Ww=.sha256",
+ "integrity": "sha1-qoVnpu7QPFMfyJ0/cRzQ5SWd7HU="
},
"ed2curve": {
"version": "0.1.4",
@@ -879,6 +880,14 @@
"resolved": "http://localhost:8989/blobs/get/&fFOPAd5Js7mJkEU4XHeJ6vE6H7nsTOegHpjY0hpTu00=.sha256",
"integrity": "sha256-fFOPAd5Js7mJkEU4XHeJ6vE6H7nsTOegHpjY0hpTu00="
},
+ "pull-split": {
+ "version": "0.2.0",
+ "resolved": "http://localhost:8989/blobs/get/&OWAh7XbI03yih8UH5Vu0qrYM6TGx0q8uah06dm22CJo=.sha256",
+ "integrity": "sha256-OWAh7XbI03yih8UH5Vu0qrYM6TGx0q8uah06dm22CJo=",
+ "requires": {
+ "pull-through": "1.0.18"
+ }
+ },
"pull-stream": {
"version": "3.6.1",
"resolved": "http://localhost:8989/blobs/get/&xEhoJll+9Z5EYr7s7MUgCbBhdF1nekcqnIdIKV4z2SU=.sha256",
@@ -899,6 +908,11 @@
}
}
},
+ "pull-utf8-decoder": {
+ "version": "1.0.2",
+ "resolved": "http://localhost:8989/blobs/get/&JHBdLm6x7Rsu08/eLVWYKq+YpGna4xnvqM44ucX2tpk=.sha256",
+ "integrity": "sha256-JHBdLm6x7Rsu08/eLVWYKq+YpGna4xnvqM44ucX2tpk="
+ },
"pull-ws": {
"version": "3.3.0",
"resolved": "http://localhost:8989/blobs/get/&xe26a32xW10OFqKs+xdyUTSobJPCAGdnv7yIAjoqmlk=.sha256",
@@ -1213,11 +1227,13 @@
"dependencies": {
"is-valid-domain": {
"version": "0.0.2",
- "resolved": "http://localhost:8989/blobs/get/&phjiap+k1lGC5LPVba/w4Caomw5o0NQp2Hol+u/YAzE=.sha256"
+ "resolved": "http://localhost:8989/blobs/get/&phjiap+k1lGC5LPVba/w4Caomw5o0NQp2Hol+u/YAzE=.sha256",
+ "integrity": "sha1-PnqUI/98Oy/hFmOvvW04N6JR+3c="
},
"ssb-ref": {
"version": "2.7.1",
"resolved": "http://localhost:8989/blobs/get/&wLimOD3785KVj7kBIAbjN6GH8EMhKRkcZSPrEMhdhks=.sha256",
+ "integrity": "sha1-XU7/xUXsD/1/wVuieCmmQLiir7o=",
"requires": {
"ip": "1.1.5",
"is-valid-domain": "0.0.2"
diff --git a/package.json b/package.json
index 65ae820..37d3ca4 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,9 @@
"pull-paginate": "^1.0.0",
"pull-paramap": "^1.2.1",
"pull-reader": "^1.2.9",
+ "pull-split": "^0.2.0",
"pull-stream": "^3.5.0",
+ "pull-utf8-decoder": "^1.0.2",
"ssb-client": "http://localhost:8989/blobs/get/&EAaUpI+wrJM5/ly1RqZW0GAEF4PmCAmABBj7e6UIrL0=.sha256",
"ssb-contact": "^1.2.0",
"ssb-git": "^0.6.0",