# HG changeset patch # User Dirkjan Ochtman # Date 1225741308 -3600 # Node ID bd522d09d5e3b2fa8e0e001537f930c0d7c77bac # Parent e74a9173c2d7a30dbee833890a83c4dc80980228 hgweb: move the diffs() generator into webutil diff -r e74a9173c2d7 -r bd522d09d5e3 mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py Mon Nov 03 20:05:03 2008 +0100 +++ b/mercurial/hgweb/common.py Mon Nov 03 20:41:48 2008 +0100 @@ -112,12 +112,6 @@ parity = 1 - parity count = 0 -def countgen(start=0, step=1): - """count forever -- useful for line numbers""" - while True: - yield start - start += step - def get_contact(config): """Return repo contact information or empty string. diff -r e74a9173c2d7 -r bd522d09d5e3 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Mon Nov 03 20:05:03 2008 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Mon Nov 03 20:41:48 2008 +0100 @@ -9,9 +9,9 @@ import os, mimetypes from mercurial.node import hex, nullid from mercurial.repo import RepoError -from mercurial import ui, hg, util, patch, hook, match +from mercurial import ui, hg, util, hook from mercurial import revlog, templater, templatefilters -from common import get_mtime, style_map, paritygen, countgen, ErrorResponse +from common import get_mtime, style_map, ErrorResponse from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED from request import wsgirequest @@ -276,48 +276,6 @@ if len(files) > self.maxfiles: yield tmpl("fileellipses") - def diff(self, tmpl, node1, node2, files): - - blockcount = countgen() - def prettyprintlines(diff): - blockno = blockcount.next() - for lineno, l in enumerate(diff.splitlines(True)): - if blockno == 0: - lineno = lineno + 1 - else: - lineno = "%d.%d" % (blockno, lineno + 1) - if l.startswith('+'): - ltype = "difflineplus" - elif l.startswith('-'): - ltype = "difflineminus" - elif l.startswith('@'): - ltype = "difflineat" - else: - ltype = "diffline" - yield tmpl(ltype, - line=l, - lineid="l%s" % lineno, - linenumber="% 8s" % lineno) - - if files: - m = match.exact(self.repo.root, self.repo.getcwd(), files) - else: - m = match.always(self.repo.root, self.repo.getcwd()) - - block = [] - parity = paritygen(self.stripecount) - diffopts = patch.diffopts(self.repo.ui, untrusted=True) - for chunk in patch.diff(self.repo, node1, node2, m, opts=diffopts): - if chunk.startswith('diff') and block: - yield tmpl('diffblock', parity=parity.next(), - lines=prettyprintlines(''.join(block))) - block = [] - if chunk.startswith('diff'): - chunk = ''.join(chunk.splitlines(True)[1:]) - block.append(chunk) - yield tmpl('diffblock', parity=parity.next(), - lines=prettyprintlines(''.join(block))) - archive_specs = { 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None), 'gz': ('application/x-tar', 'tgz', '.tar.gz', None), diff -r e74a9173c2d7 -r bd522d09d5e3 mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py Mon Nov 03 20:05:03 2008 +0100 +++ b/mercurial/hgweb/webcommands.py Mon Nov 03 20:41:48 2008 +0100 @@ -224,24 +224,23 @@ def changeset(web, req, tmpl): ctx = webutil.changectx(web.repo, req) - n = ctx.node() - showtags = webutil.showtag(web.repo, tmpl, 'changesettag', n) + showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node()) parents = ctx.parents() - p1 = parents[0].node() files = [] parity = paritygen(web.stripecount) for f in ctx.files(): template = f in ctx and 'filenodelink' or 'filenolink' files.append(tmpl(template, - node=hex(n), file=f, + node=ctx.hex(), file=f, parity=parity.next())) - diffs = web.diff(tmpl, p1, n, None) + parity = paritygen(web.stripecount) + diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity) return tmpl('changeset', diff=diffs, rev=ctx.rev(), - node=hex(n), + node=ctx.hex(), parent=webutil.siblings(parents), child=webutil.siblings(ctx.children()), changesettag=showtags, @@ -249,8 +248,8 @@ desc=ctx.description(), date=ctx.date(), files=files, - archives=web.archivelist(hex(n)), - tags=webutil.nodetagsdict(web.repo, n), + archives=web.archivelist(ctx.hex()), + tags=webutil.nodetagsdict(web.repo, ctx.node()), branch=webutil.nodebranchnodefault(ctx), inbranch=webutil.nodeinbranch(web.repo, ctx), branches=webutil.nodebranchdict(web.repo, ctx)) @@ -446,9 +445,9 @@ n = ctx.node() # path already defined in except clause parents = ctx.parents() - p1 = parents and parents[0].node() or nullid - diffs = web.diff(tmpl, p1, n, [path]) + parity = paritygen(web.stripecount) + diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity) rename = fctx and webutil.renamelink(fctx) or [] ctx = fctx and fctx or ctx return tmpl("filediff", diff -r e74a9173c2d7 -r bd522d09d5e3 mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py Mon Nov 03 20:05:03 2008 +0100 +++ b/mercurial/hgweb/webutil.py Mon Nov 03 20:41:48 2008 +0100 @@ -7,6 +7,7 @@ # of the GNU General Public License, incorporated herein by reference. import os +from mercurial import match, patch from mercurial.node import hex, nullid from mercurial.repo import RepoError from mercurial import util @@ -141,3 +142,51 @@ fctx = repo.filectx(path, fileid=changeid) return fctx + +def diffs(repo, tmpl, ctx, files, parity): + + def countgen(): + start = 1 + while True: + yield start + start += 1 + + blockcount = countgen() + def prettyprintlines(diff): + blockno = blockcount.next() + for lineno, l in enumerate(diff.splitlines(True)): + lineno = "%d.%d" % (blockno, lineno + 1) + if l.startswith('+'): + ltype = "difflineplus" + elif l.startswith('-'): + ltype = "difflineminus" + elif l.startswith('@'): + ltype = "difflineat" + else: + ltype = "diffline" + yield tmpl(ltype, + line=l, + lineid="l%s" % lineno, + linenumber="% 8s" % lineno) + + if files: + m = match.exact(repo.root, repo.getcwd(), files) + else: + m = match.always(repo.root, repo.getcwd()) + + diffopts = patch.diffopts(repo.ui, untrusted=True) + parents = ctx.parents() + node1 = parents and parents[0].node() or nullid + node2 = ctx.node() + + block = [] + for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): + if chunk.startswith('diff') and block: + yield tmpl('diffblock', parity=parity.next(), + lines=prettyprintlines(''.join(block))) + block = [] + if chunk.startswith('diff'): + chunk = ''.join(chunk.splitlines(True)[1:]) + block.append(chunk) + yield tmpl('diffblock', parity=parity.next(), + lines=prettyprintlines(''.join(block))) diff -r e74a9173c2d7 -r bd522d09d5e3 tests/test-hgweb-commands.out Binary file tests/test-hgweb-commands.out has changed diff -r e74a9173c2d7 -r bd522d09d5e3 tests/test-hgweb-diffs.out --- a/tests/test-hgweb-diffs.out Mon Nov 03 20:05:03 2008 +0100 +++ b/tests/test-hgweb-diffs.out Mon Nov 03 20:41:48 2008 +0100 @@ -56,14 +56,14 @@
-
       1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-       2+++ b/a	Thu Jan 01 00:00:00 1970 +0000
-       3@@ -0,0 +1,1 @@
-       4+a
-
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-     1.2+++ b/b	Thu Jan 01 00:00:00 1970 +0000
+
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+     1.2+++ b/a	Thu Jan 01 00:00:00 1970 +0000
      1.3@@ -0,0 +1,1 @@
-     1.4+b
+     1.4+a
+
     2.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+     2.2+++ b/b	Thu Jan 01 00:00:00 1970 +0000
+     2.3@@ -0,0 +1,1 @@
+     2.4+b
 
@@ -116,10 +116,10 @@
-
       1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-       2+++ b/a	Thu Jan 01 00:00:00 1970 +0000
-       3@@ -0,0 +1,1 @@
-       4+a
+
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+     1.2+++ b/a	Thu Jan 01 00:00:00 1970 +0000
+     1.3@@ -0,0 +1,1 @@
+     1.4+a
 
@@ -188,16 +188,16 @@
-
       1new file mode 100644
-       2--- /dev/null
-       3+++ b/a
-       4@@ -0,0 +1,1 @@
-       5+a
-
     1.1new file mode 100644
+
     1.1new file mode 100644
      1.2--- /dev/null
-     1.3+++ b/b
+     1.3+++ b/a
      1.4@@ -0,0 +1,1 @@
-     1.5+b
+     1.5+a
+
     2.1new file mode 100644
+     2.2--- /dev/null
+     2.3+++ b/b
+     2.4@@ -0,0 +1,1 @@
+     2.5+b
 
@@ -250,11 +250,11 @@
-
       1new file mode 100755
-       2--- /dev/null
-       3+++ b/a
-       4@@ -0,0 +1,1 @@
-       5+a
+
     1.1new file mode 100755
+     1.2--- /dev/null
+     1.3+++ b/a
+     1.4@@ -0,0 +1,1 @@
+     1.5+a
 
diff -r e74a9173c2d7 -r bd522d09d5e3 tests/test-hgweb-removed.out --- a/tests/test-hgweb-removed.out Mon Nov 03 20:05:03 2008 +0100 +++ b/tests/test-hgweb-removed.out Mon Nov 03 20:41:48 2008 +0100 @@ -54,10 +54,10 @@
-
       1--- a/a	Thu Jan 01 00:00:00 1970 +0000
-       2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
-       3@@ -1,1 +0,0 @@
-       4-a
+
     1.1--- a/a	Thu Jan 01 00:00:00 1970 +0000
+     1.2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+     1.3@@ -1,1 +0,0 @@
+     1.4-a
 
@@ -110,10 +110,10 @@
-
       1--- a/a	Thu Jan 01 00:00:00 1970 +0000
-       2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
-       3@@ -1,1 +0,0 @@
-       4-a
+
     1.1--- a/a	Thu Jan 01 00:00:00 1970 +0000
+     1.2+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+     1.3@@ -1,1 +0,0 @@
+     1.4-a