##// END OF EJS Templates
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman -
r7310:bd522d09 default
parent child Browse files
Show More
@@ -112,12 +112,6 b' def paritygen(stripecount, offset=0):'
112 parity = 1 - parity
112 parity = 1 - parity
113 count = 0
113 count = 0
114
114
115 def countgen(start=0, step=1):
116 """count forever -- useful for line numbers"""
117 while True:
118 yield start
119 start += step
120
121 def get_contact(config):
115 def get_contact(config):
122 """Return repo contact information or empty string.
116 """Return repo contact information or empty string.
123
117
@@ -9,9 +9,9 b''
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
@@ -276,48 +276,6 b' class hgweb(object):'
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),
@@ -224,24 +224,23 b' def shortlog(web, req, tmpl):'
224
224
225 def changeset(web, req, tmpl):
225 def changeset(web, req, tmpl):
226 ctx = webutil.changectx(web.repo, req)
226 ctx = webutil.changectx(web.repo, req)
227 n = ctx.node()
227 showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node())
228 showtags = webutil.showtag(web.repo, tmpl, 'changesettag', n)
229 parents = ctx.parents()
228 parents = ctx.parents()
230 p1 = parents[0].node()
231
229
232 files = []
230 files = []
233 parity = paritygen(web.stripecount)
231 parity = paritygen(web.stripecount)
234 for f in ctx.files():
232 for f in ctx.files():
235 template = f in ctx and 'filenodelink' or 'filenolink'
233 template = f in ctx and 'filenodelink' or 'filenolink'
236 files.append(tmpl(template,
234 files.append(tmpl(template,
237 node=hex(n), file=f,
235 node=ctx.hex(), file=f,
238 parity=parity.next()))
236 parity=parity.next()))
239
237
240 diffs = web.diff(tmpl, p1, n, None)
238 parity = paritygen(web.stripecount)
239 diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity)
241 return tmpl('changeset',
240 return tmpl('changeset',
242 diff=diffs,
241 diff=diffs,
243 rev=ctx.rev(),
242 rev=ctx.rev(),
244 node=hex(n),
243 node=ctx.hex(),
245 parent=webutil.siblings(parents),
244 parent=webutil.siblings(parents),
246 child=webutil.siblings(ctx.children()),
245 child=webutil.siblings(ctx.children()),
247 changesettag=showtags,
246 changesettag=showtags,
@@ -249,8 +248,8 b' def changeset(web, req, tmpl):'
249 desc=ctx.description(),
248 desc=ctx.description(),
250 date=ctx.date(),
249 date=ctx.date(),
251 files=files,
250 files=files,
252 archives=web.archivelist(hex(n)),
251 archives=web.archivelist(ctx.hex()),
253 tags=webutil.nodetagsdict(web.repo, n),
252 tags=webutil.nodetagsdict(web.repo, ctx.node()),
254 branch=webutil.nodebranchnodefault(ctx),
253 branch=webutil.nodebranchnodefault(ctx),
255 inbranch=webutil.nodeinbranch(web.repo, ctx),
254 inbranch=webutil.nodeinbranch(web.repo, ctx),
256 branches=webutil.nodebranchdict(web.repo, ctx))
255 branches=webutil.nodebranchdict(web.repo, ctx))
@@ -446,9 +445,9 b' def filediff(web, req, tmpl):'
446 n = ctx.node()
445 n = ctx.node()
447 # path already defined in except clause
446 # path already defined in except clause
448 parents = ctx.parents()
447 parents = ctx.parents()
449 p1 = parents and parents[0].node() or nullid
450
448
451 diffs = web.diff(tmpl, p1, n, [path])
449 parity = paritygen(web.stripecount)
450 diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity)
452 rename = fctx and webutil.renamelink(fctx) or []
451 rename = fctx and webutil.renamelink(fctx) or []
453 ctx = fctx and fctx or ctx
452 ctx = fctx and fctx or ctx
454 return tmpl("filediff",
453 return tmpl("filediff",
@@ -7,6 +7,7 b''
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
9 import os
10 from mercurial import match, patch
10 from mercurial.node import hex, nullid
11 from mercurial.node import hex, nullid
11 from mercurial.repo import RepoError
12 from mercurial.repo import RepoError
12 from mercurial import util
13 from mercurial import util
@@ -141,3 +142,51 b' def filectx(repo, req):'
141 fctx = repo.filectx(path, fileid=changeid)
142 fctx = repo.filectx(path, fileid=changeid)
142
143
143 return fctx
144 return fctx
145
146 def diffs(repo, tmpl, ctx, files, parity):
147
148 def countgen():
149 start = 1
150 while True:
151 yield start
152 start += 1
153
154 blockcount = countgen()
155 def prettyprintlines(diff):
156 blockno = blockcount.next()
157 for lineno, l in enumerate(diff.splitlines(True)):
158 lineno = "%d.%d" % (blockno, lineno + 1)
159 if l.startswith('+'):
160 ltype = "difflineplus"
161 elif l.startswith('-'):
162 ltype = "difflineminus"
163 elif l.startswith('@'):
164 ltype = "difflineat"
165 else:
166 ltype = "diffline"
167 yield tmpl(ltype,
168 line=l,
169 lineid="l%s" % lineno,
170 linenumber="% 8s" % lineno)
171
172 if files:
173 m = match.exact(repo.root, repo.getcwd(), files)
174 else:
175 m = match.always(repo.root, repo.getcwd())
176
177 diffopts = patch.diffopts(repo.ui, untrusted=True)
178 parents = ctx.parents()
179 node1 = parents and parents[0].node() or nullid
180 node2 = ctx.node()
181
182 block = []
183 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
184 if chunk.startswith('diff') and block:
185 yield tmpl('diffblock', parity=parity.next(),
186 lines=prettyprintlines(''.join(block)))
187 block = []
188 if chunk.startswith('diff'):
189 chunk = ''.join(chunk.splitlines(True)[1:])
190 block.append(chunk)
191 yield tmpl('diffblock', parity=parity.next(),
192 lines=prettyprintlines(''.join(block)))
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -56,14 +56,14 b' 200 Script output follows'
56 </table>
56 </table>
57
57
58 <div id="changesetDiff">
58 <div id="changesetDiff">
59 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1" id="l1"> 1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
59 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
60 </span><span class="plusline"><a class="lineno" href="#l2" id="l2"> 2</a>+++ b/a Thu Jan 01 00:00:00 1970 +0000
60 </span><span class="plusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>+++ b/a Thu Jan 01 00:00:00 1970 +0000
61 </span><span class="atline"><a class="lineno" href="#l3" id="l3"> 3</a>@@ -0,0 +1,1 @@
62 </span><span class="plusline"><a class="lineno" href="#l4" id="l4"> 4</a>+a
63 </span></pre><pre class="parity1"><span class="minusline"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
64 </span><span class="plusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>+++ b/b Thu Jan 01 00:00:00 1970 +0000
65 </span><span class="atline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>@@ -0,0 +1,1 @@
61 </span><span class="atline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>@@ -0,0 +1,1 @@
66 </span><span class="plusline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>+b
62 </span><span class="plusline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>+a
63 </span></pre><pre class="parity1"><span class="minusline"><a class="lineno" href="#l2.1" id="l2.1"> 2.1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
64 </span><span class="plusline"><a class="lineno" href="#l2.2" id="l2.2"> 2.2</a>+++ b/b Thu Jan 01 00:00:00 1970 +0000
65 </span><span class="atline"><a class="lineno" href="#l2.3" id="l2.3"> 2.3</a>@@ -0,0 +1,1 @@
66 </span><span class="plusline"><a class="lineno" href="#l2.4" id="l2.4"> 2.4</a>+b
67 </span></pre>
67 </span></pre>
68 </div>
68 </div>
69
69
@@ -116,10 +116,10 b' 200 Script output follows'
116 </table>
116 </table>
117
117
118 <div id="fileDiff">
118 <div id="fileDiff">
119 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1" id="l1"> 1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
119 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>--- /dev/null Thu Jan 01 00:00:00 1970 +0000
120 </span><span class="plusline"><a class="lineno" href="#l2" id="l2"> 2</a>+++ b/a Thu Jan 01 00:00:00 1970 +0000
120 </span><span class="plusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>+++ b/a Thu Jan 01 00:00:00 1970 +0000
121 </span><span class="atline"><a class="lineno" href="#l3" id="l3"> 3</a>@@ -0,0 +1,1 @@
121 </span><span class="atline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>@@ -0,0 +1,1 @@
122 </span><span class="plusline"><a class="lineno" href="#l4" id="l4"> 4</a>+a
122 </span><span class="plusline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>+a
123 </span></pre>
123 </span></pre>
124 </div>
124 </div>
125
125
@@ -188,16 +188,16 b' 200 Script output follows'
188 </table>
188 </table>
189
189
190 <div id="changesetDiff">
190 <div id="changesetDiff">
191 <pre class="parity0"><a class="lineno" href="#l1" id="l1"> 1</a>new file mode 100644
191 <pre class="parity0"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>new file mode 100644
192 <span class="minusline"><a class="lineno" href="#l2" id="l2"> 2</a>--- /dev/null
193 </span><span class="plusline"><a class="lineno" href="#l3" id="l3"> 3</a>+++ b/a
194 </span><span class="atline"><a class="lineno" href="#l4" id="l4"> 4</a>@@ -0,0 +1,1 @@
195 </span><span class="plusline"><a class="lineno" href="#l5" id="l5"> 5</a>+a
196 </span></pre><pre class="parity1"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>new file mode 100644
197 <span class="minusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>--- /dev/null
192 <span class="minusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>--- /dev/null
198 </span><span class="plusline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>+++ b/b
193 </span><span class="plusline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>+++ b/a
199 </span><span class="atline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>@@ -0,0 +1,1 @@
194 </span><span class="atline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>@@ -0,0 +1,1 @@
200 </span><span class="plusline"><a class="lineno" href="#l1.5" id="l1.5"> 1.5</a>+b
195 </span><span class="plusline"><a class="lineno" href="#l1.5" id="l1.5"> 1.5</a>+a
196 </span></pre><pre class="parity1"><a class="lineno" href="#l2.1" id="l2.1"> 2.1</a>new file mode 100644
197 <span class="minusline"><a class="lineno" href="#l2.2" id="l2.2"> 2.2</a>--- /dev/null
198 </span><span class="plusline"><a class="lineno" href="#l2.3" id="l2.3"> 2.3</a>+++ b/b
199 </span><span class="atline"><a class="lineno" href="#l2.4" id="l2.4"> 2.4</a>@@ -0,0 +1,1 @@
200 </span><span class="plusline"><a class="lineno" href="#l2.5" id="l2.5"> 2.5</a>+b
201 </span></pre>
201 </span></pre>
202 </div>
202 </div>
203
203
@@ -250,11 +250,11 b' 200 Script output follows'
250 </table>
250 </table>
251
251
252 <div id="fileDiff">
252 <div id="fileDiff">
253 <pre class="parity0"><a class="lineno" href="#l1" id="l1"> 1</a>new file mode 100755
253 <pre class="parity0"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>new file mode 100755
254 <span class="minusline"><a class="lineno" href="#l2" id="l2"> 2</a>--- /dev/null
254 <span class="minusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>--- /dev/null
255 </span><span class="plusline"><a class="lineno" href="#l3" id="l3"> 3</a>+++ b/a
255 </span><span class="plusline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>+++ b/a
256 </span><span class="atline"><a class="lineno" href="#l4" id="l4"> 4</a>@@ -0,0 +1,1 @@
256 </span><span class="atline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>@@ -0,0 +1,1 @@
257 </span><span class="plusline"><a class="lineno" href="#l5" id="l5"> 5</a>+a
257 </span><span class="plusline"><a class="lineno" href="#l1.5" id="l1.5"> 1.5</a>+a
258 </span></pre>
258 </span></pre>
259 </div>
259 </div>
260
260
@@ -54,10 +54,10 b' 200 Script output follows'
54 </table>
54 </table>
55
55
56 <div id="changesetDiff">
56 <div id="changesetDiff">
57 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1" id="l1"> 1</a>--- a/a Thu Jan 01 00:00:00 1970 +0000
57 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>--- a/a Thu Jan 01 00:00:00 1970 +0000
58 </span><span class="plusline"><a class="lineno" href="#l2" id="l2"> 2</a>+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
58 </span><span class="plusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
59 </span><span class="atline"><a class="lineno" href="#l3" id="l3"> 3</a>@@ -1,1 +0,0 @@
59 </span><span class="atline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>@@ -1,1 +0,0 @@
60 </span><span class="minusline"><a class="lineno" href="#l4" id="l4"> 4</a>-a
60 </span><span class="minusline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>-a
61 </span></pre>
61 </span></pre>
62 </div>
62 </div>
63
63
@@ -110,10 +110,10 b' 200 Script output follows'
110 </table>
110 </table>
111
111
112 <div id="fileDiff">
112 <div id="fileDiff">
113 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1" id="l1"> 1</a>--- a/a Thu Jan 01 00:00:00 1970 +0000
113 <pre class="parity0"><span class="minusline"><a class="lineno" href="#l1.1" id="l1.1"> 1.1</a>--- a/a Thu Jan 01 00:00:00 1970 +0000
114 </span><span class="plusline"><a class="lineno" href="#l2" id="l2"> 2</a>+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
114 </span><span class="plusline"><a class="lineno" href="#l1.2" id="l1.2"> 1.2</a>+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
115 </span><span class="atline"><a class="lineno" href="#l3" id="l3"> 3</a>@@ -1,1 +0,0 @@
115 </span><span class="atline"><a class="lineno" href="#l1.3" id="l1.3"> 1.3</a>@@ -1,1 +0,0 @@
116 </span><span class="minusline"><a class="lineno" href="#l4" id="l4"> 4</a>-a
116 </span><span class="minusline"><a class="lineno" href="#l1.4" id="l1.4"> 1.4</a>-a
117 </span></pre>
117 </span></pre>
118 </div>
118 </div>
119
119
General Comments 0
You need to be logged in to leave comments. Login now