index.jsView |
---|
1463 | 1463 | return cat([ |
1464 | 1464 | pull( |
1465 | 1465 | Repo.diffTrees(repos, treeIds, true), |
1466 | 1466 | pull.map(function (item) { |
1467 | | - var filename = item.filename = escapeHTML(item.path.join('/')) |
| 1467 | + var filename = escapeHTML(item.filename = item.path.join('/')) |
1468 | 1468 | var oldId = item.id && item.id[0] |
1469 | 1469 | var newId = item.id && item.id[lastI] |
1470 | 1470 | var oldMode = item.mode && item.mode[0] |
1471 | 1471 | var newMode = item.mode && item.mode[lastI] |
1477 | 1477 | ' to ' + newMode.toString(8) : |
1478 | 1478 | 'changed' |
1479 | 1479 | if (item.id) |
1480 | 1480 | changedFiles.push(item) |
| 1481 | + var commitId = item.id[lastI] ? id : treeIds.filter(Boolean)[0] |
| 1482 | + var blobsPath = treeIds[1] |
| 1483 | + ? [repos[1].id, 'blob', treeIds[1]] |
| 1484 | + : [repos[0].id, 'blob', treeIds[0]] |
| 1485 | + var rawsPath = treeIds[1] |
| 1486 | + ? [repos[1].id, 'raw', treeIds[1]] |
| 1487 | + : [repos[0].id, 'raw', treeIds[0]] |
| 1488 | + item.blobPath = blobsPath.concat(item.path) |
| 1489 | + item.rawPath = rawsPath.concat(item.path) |
1481 | 1490 | var fileHref = item.id ? |
1482 | 1491 | '#' + encodeURIComponent(item.path.join('/')) : |
1483 | | - encodeLink([repos[0].id, 'blob', id].concat(item.path)) |
| 1492 | + encodeLink(item.blobPath) |
1484 | 1493 | return ['<a href="' + fileHref + '">' + filename + '</a>', action] |
1485 | 1494 | }), |
1486 | 1495 | table() |
1487 | 1496 | ), |
1488 | 1497 | pull( |
1489 | 1498 | pull.values(changedFiles), |
1490 | 1499 | paramap(function (item, cb) { |
| 1500 | + var extension = getExtension(item.filename) |
| 1501 | + if (extension in imgMimes) { |
| 1502 | + var filename = escapeHTML(item.filename) |
| 1503 | + return cb(null, |
| 1504 | + '<pre><table class="code">' + |
| 1505 | + '<tr><th id="' + escapeHTML(item.filename) + '">' + |
| 1506 | + filename + '</th></tr>' + |
| 1507 | + '<tr><td><img src="' + encodeLink(item.rawPath) + '"' + |
| 1508 | + ' alt="' + filename + '"/></td></tr>' + |
| 1509 | + '</table></pre>') |
| 1510 | + } |
1491 | 1511 | var done = multicb({ pluck: 1, spread: true }) |
1492 | 1512 | getRepoObjectString(repos[0], item.id[0], done()) |
1493 | 1513 | getRepoObjectString(repos[1], item.id[lastI], done()) |
1494 | 1514 | done(function (err, strOld, strNew) { |
1495 | 1515 | if (err) return cb(err) |
1496 | | - var commitId = item.id[lastI] ? id : treeIds.filter(Boolean)[0] |
1497 | 1516 | cb(null, htmlLineDiff(item.filename, item.filename, |
1498 | 1517 | strOld, strNew, |
1499 | | - encodeLink([repos[0].id, 'blob', commitId].concat(item.path)))) |
| 1518 | + encodeLink(item.blobPath))) |
1500 | 1519 | }) |
1501 | 1520 | }, 4) |
1502 | 1521 | ) |
1503 | 1522 | ]) |
1504 | 1523 | } |
1505 | 1524 | |
1506 | | - function htmlLineDiff(filename, anchor, oldStr, newStr, blobHref, rawHref) { |
| 1525 | + function htmlLineDiff(filename, anchor, oldStr, newStr, blobHref) { |
1507 | 1526 | var diff = JsDiff.structuredPatch('', '', oldStr, newStr) |
1508 | 1527 | var groups = diff.hunks.map(function (hunk) { |
1509 | 1528 | var oldLine = hunk.oldStart |
1510 | 1529 | var newLine = hunk.newStart |
1528 | 1547 | '<td class="code-text">' + html + '</td></tr>' |
1529 | 1548 | })) |
1530 | 1549 | }) |
1531 | 1550 | return '<pre><table class="code">' + |
1532 | | - '<tr><th colspan=3 id="' + anchor + '">' + filename + |
| 1551 | + '<tr><th colspan=3 id="' + escapeHTML(anchor) + '">' + filename + |
1533 | 1552 | '<span class="right-bar">' + |
1534 | 1553 | '<a href="' + blobHref + '">View</a> ' + |
1535 | 1554 | '</span></th></tr>' + |
1536 | 1555 | [].concat.apply([], groups).join('') + |