lib/repos/index.jsView |
---|
1 | 1 … | var url = require('url') |
2 | 2 … | var pull = require('pull-stream') |
3 | 3 … | var once = pull.once |
4 | 4 … | var cat = require('pull-cat') |
5 | | -var catMap = require('pull-cat-map') |
6 | 5 … | var paramap = require('pull-paramap') |
7 | 6 … | var multicb = require('multicb') |
8 | 7 … | var JsDiff = require('diff') |
9 | 8 … | var GitRepo = require('pull-git-repo') |
14 | 13 … | var forms = require('../forms') |
15 | 14 … | var ssbRef = require('ssb-ref') |
16 | 15 … | var zlib = require('zlib') |
17 | 16 … | var toPull = require('stream-to-pull-stream') |
18 | | -var h = require('pull-hyperscript') |
| 17 … | +var h = require('pull-hyperscript') |
19 | 18 … | |
20 | 19 … | module.exports = function (web) { |
21 | 20 … | return new RepoRoutes(web) |
22 | 21 … | } |
502 | 501 … | } |
503 | 502 … | |
504 | 503 … | return cat([ |
505 | 504 … | location, |
506 | | - h('table', {class: "files w-100"}, sourceMap(source, file => |
| 505 … | + h('table', {class: "files w-100"}, u.sourceMap(source, file => |
507 | 506 … | h('tr', [ |
508 | 507 … | h('td', [ |
509 | 508 … | h('i', fileIcon(file)) |
510 | 509 … | ]), |
512 | 511 … | ]) |
513 | 512 … | )) |
514 | 513 … | ]) |
515 | 514 … | |
516 | | - function sourceMap (source, fn) { |
517 | | - return pull( |
518 | | - source, |
519 | | - pull.filter(Boolean), |
520 | | - catMap(fn) |
521 | | - ) |
522 | | - } |
523 | | - |
524 | 515 … | function fileIcon(file) { |
525 | 516 … | return fileType(file) === 'tree' ? '📁' : '📄' |
526 | 517 … | } |
527 | 518 … | |
653 | 644 … | var id = treeIds[0] |
654 | 645 … | var lastI = treeIds.length - 1 |
655 | 646 … | var oldTree = treeIds[0] |
656 | 647 … | var changedFiles = [] |
| 648 … | + var source = GitRepo.diffTrees(repos, treeIds, true) |
| 649 … | + |
657 | 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 … | + })), |
658 | 685 … | pull( |
659 | | - GitRepo.diffTrees(repos, treeIds, true), |
660 | | - pull.map(function (item) { |
661 | | - var filename = u.escape(item.filename = item.path.join('/')) |
662 | | - var oldId = item.id && item.id[0] |
663 | | - var newId = item.id && item.id[lastI] |
664 | | - var oldMode = item.mode && item.mode[0] |
665 | | - var newMode = item.mode && item.mode[lastI] |
666 | | - var action = |
667 | | - !oldId && newId ? req._t('action.added') : |
668 | | - oldId && !newId ? req._t('action.deleted') : |
669 | | - oldMode != newMode ? req._t('action.changedMode', { |
670 | | - old: oldMode.toString(8), |
671 | | - new: newMode.toString(8) |
672 | | - }) : req._t('changed') |
673 | | - if (item.id) |
674 | | - changedFiles.push(item) |
675 | | - var blobsPath = item.id[1] |
676 | | - ? [repos[1].id, 'blob', treeIds[1]] |
677 | | - : [repos[0].id, 'blob', treeIds[0]] |
678 | | - var rawsPath = item.id[1] |
679 | | - ? [repos[1].id, 'raw', treeIds[1]] |
680 | | - : [repos[0].id, 'raw', treeIds[0]] |
681 | | - item.blobPath = blobsPath.concat(item.path) |
682 | | - item.rawPath = rawsPath.concat(item.path) |
683 | | - var fileHref = item.id ? |
684 | | - '#' + encodeURIComponent(item.path.join('/')) : |
685 | | - u.encodeLink(item.blobPath) |
686 | | - return ['<a href="' + fileHref + '">' + filename + '</a>', action] |
687 | | - }), |
688 | | - table() |
689 | | - ), |
690 | | - pull( |
691 | 686 … | pull.values(changedFiles), |
692 | 687 … | paramap(function (item, cb) { |
693 | 688 … | var extension = u.getExtension(item.filename) |
694 | 689 … | if (extension in u.imgMimes) { |