##// END OF EJS Templates
fixes #326 some html special chars where not escaped in diffs + code garden in helpers
marcink -
r1781:089c81cf beta
parent child Browse files
Show More
@@ -30,10 +30,10 b' import difflib'
30
30
31 from itertools import tee, imap
31 from itertools import tee, imap
32
32
33 from mercurial.match import match
34
35 from vcs.exceptions import VCSError
33 from vcs.exceptions import VCSError
36 from vcs.nodes import FileNode
34 from vcs.nodes import FileNode
35 import markupsafe
36
37
37
38 def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3):
38 def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3):
39 """
39 """
@@ -95,7 +95,7 b' class DiffProcessor(object):'
95 self.differ = self._highlight_line_udiff
95 self.differ = self._highlight_line_udiff
96
96
97 def escaper(self, string):
97 def escaper(self, string):
98 return string.replace('<', '&lt;').replace('>', '&gt;')
98 return markupsafe.escape(string)
99
99
100 def copy_iterator(self):
100 def copy_iterator(self):
101 """
101 """
@@ -153,15 +153,15 b' class DiffProcessor(object):'
153
153
154 raise Exception('wrong size of diff %s' % size)
154 raise Exception('wrong size of diff %s' % size)
155
155
156 def _highlight_line_difflib(self, line, next):
156 def _highlight_line_difflib(self, line, next_):
157 """
157 """
158 Highlight inline changes in both lines.
158 Highlight inline changes in both lines.
159 """
159 """
160
160
161 if line['action'] == 'del':
161 if line['action'] == 'del':
162 old, new = line, next
162 old, new = line, next_
163 else:
163 else:
164 old, new = next, line
164 old, new = next_, line
165
165
166 oldwords = re.split(r'(\W)', old['line'])
166 oldwords = re.split(r'(\W)', old['line'])
167 newwords = re.split(r'(\W)', new['line'])
167 newwords = re.split(r'(\W)', new['line'])
@@ -183,17 +183,17 b' class DiffProcessor(object):'
183 old['line'] = "".join(oldfragments)
183 old['line'] = "".join(oldfragments)
184 new['line'] = "".join(newfragments)
184 new['line'] = "".join(newfragments)
185
185
186 def _highlight_line_udiff(self, line, next):
186 def _highlight_line_udiff(self, line, next_):
187 """
187 """
188 Highlight inline changes in both lines.
188 Highlight inline changes in both lines.
189 """
189 """
190 start = 0
190 start = 0
191 limit = min(len(line['line']), len(next['line']))
191 limit = min(len(line['line']), len(next_['line']))
192 while start < limit and line['line'][start] == next['line'][start]:
192 while start < limit and line['line'][start] == next_['line'][start]:
193 start += 1
193 start += 1
194 end = -1
194 end = -1
195 limit -= start
195 limit -= start
196 while -end <= limit and line['line'][end] == next['line'][end]:
196 while -end <= limit and line['line'][end] == next_['line'][end]:
197 end -= 1
197 end -= 1
198 end += 1
198 end += 1
199 if start or end:
199 if start or end:
@@ -211,7 +211,7 b' class DiffProcessor(object):'
211 l['line'][last:]
211 l['line'][last:]
212 )
212 )
213 do(line)
213 do(line)
214 do(next)
214 do(next_)
215
215
216 def _parse_udiff(self):
216 def _parse_udiff(self):
217 """
217 """
@@ -302,7 +302,7 b' class DiffProcessor(object):'
302 pass
302 pass
303
303
304 # highlight inline changes
304 # highlight inline changes
305 for file in files:
305 for _ in files:
306 for chunk in chunks:
306 for chunk in chunks:
307 lineiter = iter(chunk)
307 lineiter = iter(chunk)
308 #first = True
308 #first = True
@@ -214,13 +214,16 b' def pygmentize(filenode, **kwargs):'
214 return literal(code_highlight(filenode.content,
214 return literal(code_highlight(filenode.content,
215 filenode.lexer, CodeHtmlFormatter(**kwargs)))
215 filenode.lexer, CodeHtmlFormatter(**kwargs)))
216
216
217
217 def pygmentize_annotation(repo_name, filenode, **kwargs):
218 def pygmentize_annotation(repo_name, filenode, **kwargs):
218 """pygmentize function for annotation
219 """
220 pygmentize function for annotation
219
221
220 :param filenode:
222 :param filenode:
221 """
223 """
222
224
223 color_dict = {}
225 color_dict = {}
226
224 def gen_color(n=10000):
227 def gen_color(n=10000):
225 """generator for getting n of evenly distributed colors using
228 """generator for getting n of evenly distributed colors using
226 hsv color and golden ratio. It always return same order of colors
229 hsv color and golden ratio. It always return same order of colors
@@ -229,19 +232,26 b' def pygmentize_annotation(repo_name, fil'
229 """
232 """
230
233
231 def hsv_to_rgb(h, s, v):
234 def hsv_to_rgb(h, s, v):
232 if s == 0.0: return v, v, v
235 if s == 0.0:
236 return v, v, v
233 i = int(h * 6.0) # XXX assume int() truncates!
237 i = int(h * 6.0) # XXX assume int() truncates!
234 f = (h * 6.0) - i
238 f = (h * 6.0) - i
235 p = v * (1.0 - s)
239 p = v * (1.0 - s)
236 q = v * (1.0 - s * f)
240 q = v * (1.0 - s * f)
237 t = v * (1.0 - s * (1.0 - f))
241 t = v * (1.0 - s * (1.0 - f))
238 i = i % 6
242 i = i % 6
239 if i == 0: return v, t, p
243 if i == 0:
240 if i == 1: return q, v, p
244 return v, t, p
241 if i == 2: return p, v, t
245 if i == 1:
242 if i == 3: return p, q, v
246 return q, v, p
243 if i == 4: return t, p, v
247 if i == 2:
244 if i == 5: return v, p, q
248 return p, v, t
249 if i == 3:
250 return p, q, v
251 if i == 4:
252 return t, p, v
253 if i == 5:
254 return v, p, q
245
255
246 golden_ratio = 0.618033988749895
256 golden_ratio = 0.618033988749895
247 h = 0.22717784590367374
257 h = 0.22717784590367374
@@ -256,7 +266,7 b' def pygmentize_annotation(repo_name, fil'
256 cgenerator = gen_color()
266 cgenerator = gen_color()
257
267
258 def get_color_string(cs):
268 def get_color_string(cs):
259 if color_dict.has_key(cs):
269 if cs in color_dict:
260 col = color_dict[cs]
270 col = color_dict[cs]
261 else:
271 else:
262 col = color_dict[cs] = cgenerator.next()
272 col = color_dict[cs] = cgenerator.next()
@@ -291,6 +301,7 b' def pygmentize_annotation(repo_name, fil'
291
301
292 return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs))
302 return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs))
293
303
304
294 def is_following_repo(repo_name, user_id):
305 def is_following_repo(repo_name, user_id):
295 from rhodecode.model.scm import ScmModel
306 from rhodecode.model.scm import ScmModel
296 return ScmModel().is_following_repo(repo_name, user_id)
307 return ScmModel().is_following_repo(repo_name, user_id)
@@ -325,6 +336,7 b' def email_or_none(author):'
325 # No valid email, not a valid user in the system, none!
336 # No valid email, not a valid user in the system, none!
326 return None
337 return None
327
338
339
328 def person(author):
340 def person(author):
329 # attr to return from fetched user
341 # attr to return from fetched user
330 person_getter = lambda usr: usr.username
342 person_getter = lambda usr: usr.username
General Comments 0
You need to be logged in to leave comments. Login now