index.jsView |
---|
1149 | 1149 | |
1150 | 1150 | function serveRepoCommit(repo, rev) { |
1151 | 1151 | return renderRepoPage(repo, null, rev, cat([ |
1152 | 1152 | pull.once('<h3>Commit ' + rev + '</h3>'), |
1153 | | - readOnce(function (cb) { |
| 1153 | + readNext(function (cb) { |
1154 | 1154 | repo.getCommitParsed(rev, function (err, commit) { |
1155 | 1155 | if (err) return cb(err) |
1156 | 1156 | var commitPath = [repo.id, 'commit', commit.id] |
1157 | 1157 | var treePath = [repo.id, 'tree', commit.tree] |
1158 | | - cb(null, '<section class="collapse">' + |
| 1158 | + cb(null, cat([pull.once('<section class="collapse">' + |
1159 | 1159 | '<strong>' + link(commitPath, commit.title) + '</strong>' + |
1160 | 1160 | (commit.body ? pre(commit.body) : '') + |
1161 | 1161 | '<p>' + |
1162 | 1162 | (commit.separateAuthor ? escapeHTML(commit.author.name) + |
1167 | 1167 | '<p>' + commit.parents.map(function (id) { |
1168 | 1168 | return 'Parent: ' + link([repo.id, 'commit', id], id) |
1169 | 1169 | }).join('<br>') + '</p>' + |
1170 | 1170 | (commit.tree ? 'Tree: ' + link(treePath) : 'No tree') + |
1171 | | - '</section>') |
| 1171 | + '</section>'), |
| 1172 | + renderDiffStat(repo, commit.tree, commit.parents) |
| 1173 | + ])) |
1172 | 1174 | }) |
1173 | 1175 | }) |
1174 | 1176 | ])) |
1175 | 1177 | } |
1176 | 1178 | |
| 1179 | + |
| 1180 | + |
| 1181 | + function renderDiffStat(repo, id, parentIds) { |
| 1182 | + if (parentIds.length == 0) parentIds = [null] |
| 1183 | + var lastI = parentIds.length |
| 1184 | + var oldTree = parentIds[0] |
| 1185 | + return cat([ |
| 1186 | + pull.once('<section><h3>Files changed</h3>'), |
| 1187 | + pull( |
| 1188 | + repo.diffTrees(parentIds.concat(id), true), |
| 1189 | + pull.map(function (item) { |
| 1190 | + var filename = escapeHTML(item.path.join('/')) |
| 1191 | + var oldId = item.id && item.id[0] |
| 1192 | + var newId = item.id && item.id[lastI] |
| 1193 | + var oldMode = item.mode && item.mode[0].toString(8) |
| 1194 | + var newMode = item.mode && item.mode[lastI].toString(8) |
| 1195 | + var action = |
| 1196 | + !oldId && newId ? 'new' : |
| 1197 | + oldId && !newId ? 'deleted' : |
| 1198 | + oldMode != newMode ? |
| 1199 | + 'changed mode from ' + oldMode + ' to ' + newMode : |
| 1200 | + '' |
| 1201 | + var newLink = newId ? |
| 1202 | + link([repo.id, 'blob', id].concat(item.path), 'new') : '' |
| 1203 | + var oldLink = oldId ? |
| 1204 | + link([repo.id, 'blob', oldTree].concat(item.path), 'old') : '' |
| 1205 | + var links = [oldLink, newLink] |
| 1206 | + var fileLink = newLink || oldLink ? filename : |
| 1207 | + link([repo.id, 'blob', id].concat(item.path), filename) |
| 1208 | + return [fileLink, action, links.filter(Boolean).join(', ')] |
| 1209 | + }), |
| 1210 | + table() |
| 1211 | + ), |
| 1212 | + pull.once('</section>'), |
| 1213 | + ]) |
| 1214 | + } |
| 1215 | + |
1177 | 1216 | |
1178 | 1217 | |
1179 | 1218 | function serveRepoSomething(req, repo, id, msg, path) { |
1180 | 1219 | return renderRepoPage(repo, null, null, |