diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 219ee99..f7d4047 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -248,7 +248,9 @@ {% endif %} {% if diff %} + {% set count = 0 %} {% for patch in diff %} + {% set count = count+1 %} {% if patch |hasattr('new_id') %} {% set patch_new_id = patch.new_id %} {% elif patch |hasattr('delta') %} @@ -256,7 +258,6 @@ {% else %} {% set patch_new_id = patch.new_oid %} {% endif %} - {% if patch | hasattr('new_file_path') %} {% set patch_new_file_path = patch.new_file_path -%} {% if patch.new_file_path != patch.old_file_path %} @@ -269,38 +270,101 @@ {%- endif -%} {%- endif -%} -
-
+ +
+
- {%- if patch_new_file_path == patch_old_file_path -%} - {{ patch_new_file_path }} (Renamed from "{{ patch_old_file_path }}") - {%- else -%} - {{ patch_new_file_path }} - {%- endif -%} + {% if patch | hasattr('additions') %} + {# Version of pygit2 -0.21.4 -- F21/EL7 #} + {% set linesadded = patch.additions %} + {% set linesremoved = patch.deletions %} + {% else %} + {# Version of pygit2 -0.23.0 -- F23 #} + {% set linesadded = patch.line_stats[1] %} + {% set linesremoved = patch.line_stats[2] %} + {% endif %} + + {% macro lineschanged(added, removed) -%} + {%if added%} + +{{linesadded}} + {%endif%} + {%if removed%} + -{{linesremoved}} + {%endif%} + {%endmacro%} + {% macro viewfilelink(filepath)%} {% if pull_request %} - View + title="View file as of {{ patch_new_id|short }}">{{filepath}} + {% endmacro %} + + {% if patch | hasattr('new_file_path') %} + {%- if patch.new_file_path == patch.old_file_path -%} + {{ viewfilelink(patch.new_file_path)}} {{lineschanged(True, True)}} + {%- else -%} + {{lineschanged(True, True)}} +
+ {{patch.old_file_path}}
+ {{viewfilelink(patch.new_file_path)}} +
+
file removed
+ {%- endif -%} + {%- elif patch | hasattr('delta') -%} + {%- if patch.delta.new_file.path == patch.delta.old_file.path -%} + {%- if patch.delta.new_file.mode == 0 and patch.delta.old_file.mode == 33188 -%} + {% set patchtype = "removed"%} +
{{viewfilelink(patch.delta.new_file.path)}} {{lineschanged(False, True)}}
+
file removed
+ {%-elif patch.delta.new_file.mode == 33188 and patch.delta.old_file.mode == 0 -%} + {% set patchtype = "added"%} +
{{viewfilelink(patch.delta.new_file.path)}} {{lineschanged(True, False)}}
+
file added
+ {%-elif patch.delta.new_file.mode == 33188 and patch.delta.old_file.mode == 33188 -%} + {% set patchtype = "changed"%} +
+ {{ viewfilelink(patch.delta.new_file.path)}} {{lineschanged(True, True)}} +
+
file changed
+ {%-endif-%} + {%- else -%} + {% set patchtype = "moved"%} + {{lineschanged(True, True)}} +
+ {{patch.delta.old_file.path}}
+ {{viewfilelink(patch.delta.new_file.path)}} +
+
file moved
+ {%- endif -%} + {%- endif -%}
- + {% if patchtype == "moved" and linesadded == 0 and linesremoved == 0%} +
+
file was moved with no change to the file
+
+ {% elif patchtype == "added" and linesadded == 0 %} +
+
empty file added
+
+ {% else %} {% autoescape false %} {{ patch | patch_to_diff | html_diff | format_loc( filename=patch_new_file_path, @@ -309,6 +373,7 @@ index=loop.index, tree_id=diff_commits[0].tree.id)}} {% endautoescape %} + {% endif %}
@@ -505,46 +570,47 @@
Changes summary
- - - {% macro changeschangedfile(filepath, added, removed) -%} + {% macro changeschangedfile(filepath, added, removed, diffanchor) -%}
+{{added}} -{{removed}}
file changed
- {{filepath}} + {{filepath}}
{%- endmacro %} - {% macro changesrenamedfile(oldfilepath, newfilepath, added, removed) -%} + {% macro changesrenamedfile(oldfilepath, newfilepath, added, removed, diffanchor) -%}
+{{added}} -{{removed}}
file renamed
- {{oldfilepath}}
{{newfilepath}} + {{oldfilepath}}
+ {{newfilepath}}
{%- endmacro %} - {% macro changesdeletedfile(filepath, added, removed) -%} + {% macro changesdeletedfile(filepath, added, removed, diffanchor) -%}
-{{removed}}
-
file deleted
+
file removed
- {{filepath}} + {{filepath}}
{%- endmacro %} - {% macro changesaddedfile(filepath, added, removed) -%} + {% macro changesaddedfile(filepath, added, removed, diffanchor) -%}
+{{added}}
file added
- {{filepath}} + {{filepath}}
{%- endmacro %}
+ {% set count = 0 %} {% for patch in diff %} + {% set count = count+1 %}
{% if patch | hasattr('additions') %} @@ -559,21 +625,21 @@ {% if patch | hasattr('new_file_path') %} {%- if patch.new_file_path == patch.old_file_path -%} - {{ changeschangedfile(patch.new_file_path, linesadded, linesremoved) }} + {{ changeschangedfile(patch.new_file_path, linesadded, linesremoved, count) }} {%- else -%} - {{changesrenamedfile(patch.old_file_path, patch.new_file_path, linesadded, linesremoved)}} + {{changesrenamedfile(patch.old_file_path, patch.new_file_path, linesadded, linesremoved, count)}} {%- endif -%} {%- elif patch | hasattr('delta') -%} {%- if patch.delta.new_file.path == patch.delta.old_file.path -%} {%- if patch.delta.new_file.mode == 0 and patch.delta.old_file.mode == 33188 -%} - {{ changesdeletedfile(patch.delta.new_file.path, linesadded, linesremoved) }} + {{ changesdeletedfile(patch.delta.new_file.path, linesadded, linesremoved, count) }} {%-elif patch.delta.new_file.mode == 33188 and patch.delta.old_file.mode == 0 -%} - {{ changesaddedfile(patch.delta.new_file.path, linesadded, linesremoved) }} + {{ changesaddedfile(patch.delta.new_file.path, linesadded, linesremoved, count) }} {%-elif patch.delta.new_file.mode == 33188 and patch.delta.old_file.mode == 33188 -%} - {{ changeschangedfile(patch.delta.new_file.path, linesadded, linesremoved) }} + {{ changeschangedfile(patch.delta.new_file.path, linesadded, linesremoved, count) }} {%-endif-%} {%- else -%} - {{changesrenamedfile(patch.delta.old_file.path, patch.delta.new_file.path, linesadded, linesremoved)}} + {{changesrenamedfile(patch.delta.old_file.path, patch.delta.new_file.path, linesadded, linesremoved, count)}} {%- endif -%} {%- endif -%}