comparison mercurial/hgweb/hgweb_mod.py @ 7310:bd522d09d5e3

hgweb: move the diffs() generator into webutil
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 03 Nov 2008 20:41:48 +0100
parents e74a9173c2d7
children de9c87fe1620
comparison
equal deleted inserted replaced
7309:e74a9173c2d7 7310:bd522d09d5e3
7 # of the GNU General Public License, incorporated herein by reference. 7 # of the GNU General Public License, incorporated herein by reference.
8 8
9 import os, mimetypes 9 import os, mimetypes
10 from mercurial.node import hex, nullid 10 from mercurial.node import hex, nullid
11 from mercurial.repo import RepoError 11 from mercurial.repo import RepoError
12 from mercurial import ui, hg, util, patch, hook, match 12 from mercurial import ui, hg, util, hook
13 from mercurial import revlog, templater, templatefilters 13 from mercurial import revlog, templater, templatefilters
14 from common import get_mtime, style_map, paritygen, countgen, ErrorResponse 14 from common import get_mtime, style_map, ErrorResponse
15 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR 15 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
16 from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED 16 from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED
17 from request import wsgirequest 17 from request import wsgirequest
18 import webcommands, protocol, webutil 18 import webcommands, protocol, webutil
19 19
274 for f in files[:self.maxfiles]: 274 for f in files[:self.maxfiles]:
275 yield tmpl("filedifflink", node=hex(changeset), file=f) 275 yield tmpl("filedifflink", node=hex(changeset), file=f)
276 if len(files) > self.maxfiles: 276 if len(files) > self.maxfiles:
277 yield tmpl("fileellipses") 277 yield tmpl("fileellipses")
278 278
279 def diff(self, tmpl, node1, node2, files):
280
281 blockcount = countgen()
282 def prettyprintlines(diff):
283 blockno = blockcount.next()
284 for lineno, l in enumerate(diff.splitlines(True)):
285 if blockno == 0:
286 lineno = lineno + 1
287 else:
288 lineno = "%d.%d" % (blockno, lineno + 1)
289 if l.startswith('+'):
290 ltype = "difflineplus"
291 elif l.startswith('-'):
292 ltype = "difflineminus"
293 elif l.startswith('@'):
294 ltype = "difflineat"
295 else:
296 ltype = "diffline"
297 yield tmpl(ltype,
298 line=l,
299 lineid="l%s" % lineno,
300 linenumber="% 8s" % lineno)
301
302 if files:
303 m = match.exact(self.repo.root, self.repo.getcwd(), files)
304 else:
305 m = match.always(self.repo.root, self.repo.getcwd())
306
307 block = []
308 parity = paritygen(self.stripecount)
309 diffopts = patch.diffopts(self.repo.ui, untrusted=True)
310 for chunk in patch.diff(self.repo, node1, node2, m, opts=diffopts):
311 if chunk.startswith('diff') and block:
312 yield tmpl('diffblock', parity=parity.next(),
313 lines=prettyprintlines(''.join(block)))
314 block = []
315 if chunk.startswith('diff'):
316 chunk = ''.join(chunk.splitlines(True)[1:])
317 block.append(chunk)
318 yield tmpl('diffblock', parity=parity.next(),
319 lines=prettyprintlines(''.join(block)))
320
321 archive_specs = { 279 archive_specs = {
322 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None), 280 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None),
323 'gz': ('application/x-tar', 'tgz', '.tar.gz', None), 281 'gz': ('application/x-tar', 'tgz', '.tar.gz', None),
324 'zip': ('application/zip', 'zip', '.zip', None), 282 'zip': ('application/zip', 'zip', '.zip', None),
325 } 283 }