Show More
@@ -4,12 +4,12 b'' | |||||
4 | ~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | Set of diffing helpers, previously part of vcs |
|
6 | Set of diffing helpers, previously part of vcs | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | :created_on: Dec 4, 2011 |
|
9 | :created_on: Dec 4, 2011 | |
10 | :author: marcink |
|
10 | :author: marcink | |
11 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
|
11 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> | |
12 |
:original copyright: 2007-2008 by Armin Ronacher |
|
12 | :original copyright: 2007-2008 by Armin Ronacher | |
13 | :license: GPLv3, see COPYING for more details. |
|
13 | :license: GPLv3, see COPYING for more details. | |
14 | """ |
|
14 | """ | |
15 | # This program is free software: you can redistribute it and/or modify |
|
15 | # This program is free software: you can redistribute it and/or modify | |
@@ -30,15 +30,15 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 | """ | |
40 | Returns git style diff between given ``filenode_old`` and ``filenode_new``. |
|
40 | Returns git style diff between given ``filenode_old`` and ``filenode_new``. | |
41 |
|
41 | |||
42 | :param ignore_whitespace: ignore whitespaces in diff |
|
42 | :param ignore_whitespace: ignore whitespaces in diff | |
43 | """ |
|
43 | """ | |
44 |
|
44 | |||
@@ -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('<', '<').replace('>', '>') |
|
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 |
|
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: |
|
235 | if s == 0.0: | |
233 | i = int(h * 6.0) # XXX assume int() truncates! |
|
236 | return v, v, v | |
|
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: |
|
243 | if i == 0: | |
240 |
|
|
244 | return v, t, p | |
241 |
if i == |
|
245 | if i == 1: | |
242 |
|
|
246 | return q, v, p | |
243 |
if i == |
|
247 | if i == 2: | |
244 |
|
|
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 | |
@@ -251,12 +261,12 b' def pygmentize_annotation(repo_name, fil' | |||||
251 | h %= 1 |
|
261 | h %= 1 | |
252 | HSV_tuple = [h, 0.95, 0.95] |
|
262 | HSV_tuple = [h, 0.95, 0.95] | |
253 | RGB_tuple = hsv_to_rgb(*HSV_tuple) |
|
263 | RGB_tuple = hsv_to_rgb(*HSV_tuple) | |
254 | yield map(lambda x:str(int(x * 256)), RGB_tuple) |
|
264 | yield map(lambda x: str(int(x * 256)), RGB_tuple) | |
255 |
|
265 | |||
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 |
|
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) | |
@@ -304,7 +315,7 b' from vcs.utils import author_name, autho' | |||||
304 | from rhodecode.lib import credentials_filter, age as _age |
|
315 | from rhodecode.lib import credentials_filter, age as _age | |
305 | from rhodecode.model.db import User |
|
316 | from rhodecode.model.db import User | |
306 |
|
317 | |||
307 | age = lambda x:_age(x) |
|
318 | age = lambda x: _age(x) | |
308 | capitalize = lambda x: x.capitalize() |
|
319 | capitalize = lambda x: x.capitalize() | |
309 | email = author_email |
|
320 | email = author_email | |
310 | short_id = lambda x: x[:12] |
|
321 | short_id = lambda x: x[:12] | |
@@ -325,10 +336,11 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 | |
331 |
|
343 | |||
332 | # Valid email in the attribute passed, see if they're in the system |
|
344 | # Valid email in the attribute passed, see if they're in the system | |
333 | _email = email(author) |
|
345 | _email = email(author) | |
334 | if _email != '': |
|
346 | if _email != '': |
General Comments 0
You need to be logged in to leave comments.
Login now