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