Compress diffs to show only the changes and some context
parent
3cadc652ed
commit
b80e4566f6
|
@ -7,6 +7,7 @@
|
||||||
- Add gravatar url to Users API endpoint.
|
- Add gravatar url to Users API endpoint.
|
||||||
- ProjectTemplates now are sorted by the attribute 'order'.
|
- ProjectTemplates now are sorted by the attribute 'order'.
|
||||||
- Create enpty wiki pages (if not exist) when a new link is created.
|
- Create enpty wiki pages (if not exist) when a new link is created.
|
||||||
|
- Diff messages in history entries now show only the relevant changes (with some context).
|
||||||
- Comments:
|
- Comments:
|
||||||
- Now comment owners and project admins can edit existing comments with the history Entry endpoint.
|
- Now comment owners and project admins can edit existing comments with the history Entry endpoint.
|
||||||
- Add a new permissions to allow add comments instead of use the existent modify permission for this purpose.
|
- Add a new permissions to allow add comments instead of use the existent modify permission for this purpose.
|
||||||
|
|
|
@ -126,16 +126,42 @@ def render_and_extract(project, text):
|
||||||
|
|
||||||
class DiffMatchPatch(diff_match_patch.diff_match_patch):
|
class DiffMatchPatch(diff_match_patch.diff_match_patch):
|
||||||
def diff_pretty_html(self, diffs):
|
def diff_pretty_html(self, diffs):
|
||||||
html = []
|
def _sanitize_text(text):
|
||||||
for (op, data) in diffs:
|
return (text.replace("&", "&").replace("<", "<")
|
||||||
text = (data.replace("&", "&").replace("<", "<")
|
|
||||||
.replace(">", ">").replace("\n", "<br />"))
|
.replace(">", ">").replace("\n", "<br />"))
|
||||||
|
|
||||||
|
def _split_long_text(text, idx, size):
|
||||||
|
splited_text = text.split()
|
||||||
|
|
||||||
|
if len(splited_text) > 25:
|
||||||
|
if idx == 0:
|
||||||
|
# The first is (...)text
|
||||||
|
first = ""
|
||||||
|
else:
|
||||||
|
first = " ".join(splited_text[:10])
|
||||||
|
|
||||||
|
if idx != 0 and idx == size - 1:
|
||||||
|
# The last is text(...)
|
||||||
|
last = ""
|
||||||
|
else:
|
||||||
|
last = " ".join(splited_text[-10:])
|
||||||
|
|
||||||
|
return "{}(...){}".format(first, last)
|
||||||
|
return text
|
||||||
|
|
||||||
|
size = len(diffs)
|
||||||
|
html = []
|
||||||
|
for idx, (op, data) in enumerate(diffs):
|
||||||
if op == self.DIFF_INSERT:
|
if op == self.DIFF_INSERT:
|
||||||
html.append("<ins style=\"background:#e6ffe6;\">%s</ins>" % text)
|
text = _sanitize_text(data)
|
||||||
|
html.append("<ins style=\"background:#e6ffe6;\">{}</ins>".format(text))
|
||||||
elif op == self.DIFF_DELETE:
|
elif op == self.DIFF_DELETE:
|
||||||
html.append("<del style=\"background:#ffe6e6;\">%s</del>" % text)
|
text = _sanitize_text(data)
|
||||||
|
html.append("<del style=\"background:#ffe6e6;\">{}</del>".format(text))
|
||||||
elif op == self.DIFF_EQUAL:
|
elif op == self.DIFF_EQUAL:
|
||||||
html.append("<span>%s</span>" % text)
|
text = _split_long_text(_sanitize_text(data), idx, size)
|
||||||
|
html.append("<span>{}</span>".format(text))
|
||||||
|
|
||||||
return "".join(html)
|
return "".join(html)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue