lib/repos/index.jsView |
---|
1 | 1 … | var url = require('url') |
2 | 2 … | var pull = require('pull-stream') |
| 3 … | +var once = pull.once |
3 | 4 … | var cat = require('pull-cat') |
4 | 5 … | var paramap = require('pull-paramap') |
5 | 6 … | var multicb = require('multicb') |
6 | 7 … | var JsDiff = require('diff') |
12 | 13 … | var forms = require('../forms') |
13 | 14 … | var ssbRef = require('ssb-ref') |
14 | 15 … | var zlib = require('zlib') |
15 | 16 … | var toPull = require('stream-to-pull-stream') |
| 17 … | +var h = require('pull-hyperscript') |
16 | 18 … | |
17 | 19 … | module.exports = function (web) { |
18 | 20 … | return new RepoRoutes(web) |
19 | 21 … | } |
35 | 37 … | u.readObjectString(obj, cb) |
36 | 38 … | }) |
37 | 39 … | } |
38 | 40 … | |
39 | | -function table(props) { |
40 | | - return function (read) { |
41 | | - return cat([ |
42 | | - pull.once('<table' + (props ? ' ' + props : '') + '>'), |
43 | | - pull( |
44 | | - read, |
45 | | - pull.map(function (row) { |
46 | | - return row ? '<tr>' + row.map(function (cell, i) { |
47 | | - return '<td>' + cell + '</td>' |
48 | | - }).join('') + '</tr>' : '' |
49 | | - }) |
50 | | - ), |
51 | | - pull.once('</table>') |
52 | | - ]) |
53 | | - } |
54 | | -} |
55 | | - |
56 | 41 … | function ul(props) { |
57 | 42 … | return function (read) { |
58 | 43 … | return cat([ |
59 | 44 … | pull.once('<ul' + (props ? ' ' + props : '') + '>'), |
504 | 489 … | }).concat(last).join(' / ') |
505 | 490 … | } |
506 | 491 … | |
507 | 492 … | function renderRepoTree(req, repo, rev, path) { |
| 493 … | + var source = repo.readDir(rev,path) |
508 | 494 … | var pathLinks = path.length === 0 ? '' : |
509 | 495 … | ': ' + linkPath([repo.id, 'tree'], [rev].concat(path)) |
| 496 … | + |
| 497 … | + var location = once('') |
| 498 … | + if (path.length !== 0) { |
|
| 499 … | + var link = linkPath([repo.id, 'tree'], [rev].concat(path)) |
| 500 … | + location = h('div', {class: 'fileLocation'}, `${req._t('Files')}: ${link}`) |
| 501 … | + } |
| 502 … | + |
510 | 503 … | return cat([ |
511 | | - pull.once(pathLinks ? '<div class="fileLocation">' + req._t('Files') + pathLinks + '</div>' : ''), |
512 | | - pull( |
513 | | - repo.readDir(rev, path), |
514 | | - pull.map(function (file) { |
515 | | - var type = (file.mode === 040000) ? 'tree' : |
516 | | - (file.mode === 0160000) ? 'commit' : 'blob' |
517 | | - if (type == 'commit') |
518 | | - return [ |
519 | | - '<span title="' + req._t('gitCommitLink') + '">🖈</span>', |
520 | | - '<span title="' + u.escape(file.id) + '">' + |
521 | | - u.escape(file.name) + '</span>'] |
522 | | - var filePath = [repo.id, type, rev].concat(path, file.name) |
523 | | - return ['<i>' + (type == 'tree' ? '📁' : '📄') + '</i>', |
524 | | - u.link(filePath, file.name)] |
525 | | - }), |
526 | | - table('class="files w-100"') |
527 | | - ) |
| 504 … | + location, |
| 505 … | + h('table', {class: "files w-100"}, u.sourceMap(source, file => |
| 506 … | + h('tr', [ |
| 507 … | + h('td', [ |
| 508 … | + h('i', fileIcon(file)) |
| 509 … | + ]), |
| 510 … | + h('td', u.link(filePath(file), file.name)) |
| 511 … | + ]) |
| 512 … | + )) |
528 | 513 … | ]) |
| 514 … | + |
| 515 … | + function fileIcon(file) { |
| 516 … | + return fileType(file) === 'tree' ? '📁' : '📄' |
| 517 … | + } |
| 518 … | + |
| 519 … | + function filePath(file) { |
| 520 … | + var type = fileType(file) |
| 521 … | + return [repo.id, type, rev].concat(path, file.name) |
| 522 … | + } |
| 523 … | + |
| 524 … | + function fileType(file) { |
| 525 … | + if (file.mode === 040000) return 'tree' |
| 526 … | + else if (file.mode === 0160000) return 'commit' |
| 527 … | + else return 'blob' |
| 528 … | + } |
529 | 529 … | } |
530 | 530 … | |
531 | 531 … | |
532 | 532 … | |
644 | 644 … | var id = treeIds[0] |
645 | 645 … | var lastI = treeIds.length - 1 |
646 | 646 … | var oldTree = treeIds[0] |
647 | 647 … | var changedFiles = [] |
| 648 … | + var source = GitRepo.diffTrees(repos, treeIds, true) |
| 649 … | + |
648 | 650 … | return cat([ |
| 651 … | + h('table', u.sourceMap(source, item => { |
| 652 … | + var filename = u.escape(item.filename = item.path.join('/')) |
| 653 … | + var oldId = item.id && item.id[0] |
| 654 … | + var newId = item.id && item.id[lastI] |
| 655 … | + var oldMode = item.mode && item.mode[0] |
| 656 … | + var newMode = item.mode && item.mode[lastI] |
| 657 … | + var action = |
| 658 … | + !oldId && newId ? req._t('action.added') : |
| 659 … | + oldId && !newId ? req._t('action.deleted') : |
| 660 … | + oldMode != newMode ? req._t('action.changedMode', { |
| 661 … | + old: oldMode.toString(8), |
| 662 … | + new: newMode.toString(8) |
| 663 … | + }) : req._t('changed') |
| 664 … | + if (item.id) |
| 665 … | + changedFiles.push(item) |
| 666 … | + var blobsPath = item.id[1] |
| 667 … | + ? [repos[1].id, 'blob', treeIds[1]] |
| 668 … | + : [repos[0].id, 'blob', treeIds[0]] |
| 669 … | + var rawsPath = item.id[1] |
| 670 … | + ? [repos[1].id, 'raw', treeIds[1]] |
| 671 … | + : [repos[0].id, 'raw', treeIds[0]] |
| 672 … | + item.blobPath = blobsPath.concat(item.path) |
| 673 … | + item.rawPath = rawsPath.concat(item.path) |
| 674 … | + var fileHref = item.id ? |
| 675 … | + '#' + encodeURIComponent(item.path.join('/')) : |
| 676 … | + u.encodeLink(item.blobPath) |
| 677 … | + |
| 678 … | + return h('tr', [ |
| 679 … | + h('td', [ |
| 680 … | + h('a', {href: fileHref}, filename) |
| 681 … | + ]), |
| 682 … | + h('td', action) |
| 683 … | + ]) |
| 684 … | + })), |
649 | 685 … | pull( |
650 | | - GitRepo.diffTrees(repos, treeIds, true), |
651 | | - pull.map(function (item) { |
652 | | - var filename = u.escape(item.filename = item.path.join('/')) |
653 | | - var oldId = item.id && item.id[0] |
654 | | - var newId = item.id && item.id[lastI] |
655 | | - var oldMode = item.mode && item.mode[0] |
656 | | - var newMode = item.mode && item.mode[lastI] |
657 | | - var action = |
658 | | - !oldId && newId ? req._t('action.added') : |
659 | | - oldId && !newId ? req._t('action.deleted') : |
660 | | - oldMode != newMode ? req._t('action.changedMode', { |
661 | | - old: oldMode.toString(8), |
662 | | - new: newMode.toString(8) |
663 | | - }) : req._t('changed') |
664 | | - if (item.id) |
665 | | - changedFiles.push(item) |
666 | | - var blobsPath = item.id[1] |
667 | | - ? [repos[1].id, 'blob', treeIds[1]] |
668 | | - : [repos[0].id, 'blob', treeIds[0]] |
669 | | - var rawsPath = item.id[1] |
670 | | - ? [repos[1].id, 'raw', treeIds[1]] |
671 | | - : [repos[0].id, 'raw', treeIds[0]] |
672 | | - item.blobPath = blobsPath.concat(item.path) |
673 | | - item.rawPath = rawsPath.concat(item.path) |
674 | | - var fileHref = item.id ? |
675 | | - '#' + encodeURIComponent(item.path.join('/')) : |
676 | | - u.encodeLink(item.blobPath) |
677 | | - return ['<a href="' + fileHref + '">' + filename + '</a>', action] |
678 | | - }), |
679 | | - table() |
680 | | - ), |
681 | | - pull( |
682 | 686 … | pull.values(changedFiles), |
683 | 687 … | paramap(function (item, cb) { |
684 | 688 … | var extension = u.getExtension(item.filename) |
685 | 689 … | if (extension in u.imgMimes) { |