From 873328278481f6bf1baa8f249d6f144643f4d849 Mon Sep 17 00:00:00 2001 From: zPlus Date: Wed, 10 Aug 2022 07:04:23 +0200 Subject: [PATCH] Use pygit2.DiffDelta.status_char() insead of pygit2.DiffDelta.status .status_char() returns the single character abbreviation for a delta status code, so we prefer this over the raw .status integer. --- templates/repository/commit.html | 44 ++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/templates/repository/commit.html b/templates/repository/commit.html index cada978..56667ce 100644 --- a/templates/repository/commit.html +++ b/templates/repository/commit.html @@ -157,19 +157,25 @@ {% else %} {% for patch in diff %} - + + {# The following status values are defined in the git_delta_t enum + # in libgit2. See https://github.com/libgit2/libgit2/blob/main/include/git2/diff.h + # Looks like pygit2 also has a pygit2.DiffDelta.status_char() functions that + # returns the single-char abbreviation of the delta status, so we can use this + # instead of the raw integer. + # 0 = UNCHANGED + # 1 = ADDED (does not exist in old version) + # 2 = DELETED (does not exist in new version) + # 3 = MODIFIED (content changed between old and new versions) + # 4 = RENAMED + # 5 = COPIED + # ... (there are other codes that we don't use) + #} + + {% set delta_char = patch.delta.status_char() %} +
- {# The following status values are defined in the git_delta_t enum - # in libgit2. See https://github.com/libgit2/libgit2/blob/main/include/git2/diff.h - # 0 = UNCHANGED - # 1 = ADDED (does not exist in old version) - # 2 = DELETED (does not exist in new version) - # 3 = MODIFIED (content changed between old and new versions) - # 4 = RENAMED - # 5 = COPIED - # ... (there are other codes that we don't use) - #} {% if patch.line_stats[1] + patch.line_stats[2] > 0 %} {% set color_border = patch.line_stats[1] / ( patch.line_stats[1] + patch.line_stats[2] ) * 100 %} @@ -181,24 +187,24 @@ +{{ patch.line_stats[1] }}/-{{ patch.line_stats[2] }} - {% if patch.delta.status == 1 %} + {% if delta_char == 'A' %} A   {{ patch.delta.new_file.path }} {% endif %} - {% if patch.delta.status == 2 %} + {% if delta_char == 'D' %} D   {{ patch.delta.old_file.path }} {% endif %} - {% if patch.delta.status == 3 %} + {% if delta_char == 'M' %} M   {{ patch.delta.new_file.path }} {% endif %} - {% if patch.delta.status == 4 %} + {% if delta_char == 'R' %} R   {{ patch.delta.old_file.path }} -> {{ patch.delta.new_file.path }} {% endif %} - {% if patch.delta.status == 5 %} - C   {{ patch.delta.old_file.path }} {{ patch.delta.new_file.path }} + {% if delta_char == 'C' %} + C   {{ patch.delta.old_file.path }} -> {{ patch.delta.new_file.path }} {% endif %} @@ -216,9 +222,9 @@
- {% if patch.delta.status == 1 %} + {% if delta_char == 'A' %} new file mode: {{ patch.delta.new_file.mode|filemode }} - {% elif patch.delta.status == 2 %} + {% elif delta_char == 'D' %} deleted file mode: {{ patch.delta.old_file.mode|filemode }} {% elif patch.delta.old_file.mode != patch.delta.new_file.mode %} old mode: {{ patch.delta.old_file.mode|filemode }}