Diff between 602caca00fbc951bda7bd58c78b18f510fb9a5b5 and cf87bb3e294fc839418e8e6f68570a6ced214990

Changed Files

File Additions Deletions Status
git/commit.py +33 -1 modified
templates/commit.html +23 -3 modified

Full Patch

diff --git a/git/commit.py b/git/commit.py
index 6627a7e..34ab713 100644
--- a/git/commit.py
+++ b/git/commit.py
@@ -1,5 +1,19 @@
 import pygit2 as git
 
+# map libgit2 delta status to human readable
+status_map = {
+    git.GIT_DELTA_ADDED: 'added',
+    git.GIT_DELTA_DELETED: 'deleted',
+    git.GIT_DELTA_MODIFIED: 'modified',
+    git.GIT_DELTA_RENAMED: 'renamed',
+    git.GIT_DELTA_COPIED: 'copied',
+    git.GIT_DELTA_IGNORED: 'ignored',
+    git.GIT_DELTA_UNTRACKED: 'untracked',
+    git.GIT_DELTA_TYPECHANGE: 'typechange',
+    git.GIT_DELTA_UNREADABLE: 'unreadable',
+    git.GIT_DELTA_CONFLICTED: 'conflicted'
+}
+
 # retrieves commit history for given repo path and reference
 def get_commits(path, ref="HEAD", max_count=None, skip=0):
     repo = git.Repository(path)
@@ -57,6 +71,22 @@ def get_commit(path, commit_id):
             'deletions': stats.deletions,
             'files_changed': stats.files_changed
         }
+        # detect renames and copies
+        diff.find_similar()
+        patches = list(diff)
+        deltas = diff.deltas
+        changed_files = []
+        for i, delta in enumerate(deltas):
+            patch = patches[i]
+            file_path = delta.new_file.path if delta.new_file.path else delta.old_file.path
+            _, additions, deletions = patch.line_stats
+            status_str = status_map.get(delta.status, 'unknown')
+            changed_files.append({
+                'file': file_path,
+                'additions': additions,
+                'deletions': deletions,
+                'status': status_str
+            })
     else:
         diff_stats = {
             'insertions': 0,
@@ -64,6 +94,7 @@ def get_commit(path, commit_id):
             'files_changed': 0
         }
         diff = None
+        changed_files = []
 
     commit_info = {
         'id': str(commit.id),
@@ -74,6 +105,7 @@ def get_commit(path, commit_id):
         'parent_id': str(commit.parents[0].id) if commit.parents else None,
         'date': commit.commit_time,
         'diff_stats': diff_stats,
-        'diff': diff.patch if diff else None
+        'diff': diff.patch if diff else None,
+        'changed_files': changed_files
     }
     return commit_info
\ No newline at end of file
diff --git a/templates/commit.html b/templates/commit.html
index ff17ef8..48627bf 100644
--- a/templates/commit.html
+++ b/templates/commit.html
@@ -18,10 +18,30 @@
         <li>Insertions: {{ commit.diff_stats.insertions }}</li>
         <li>Deletions: {{ commit.diff_stats.deletions }}</li>
     </ul>
+    <h2>Changed Files</h2>
+    <table>
+        <thead>
+            <tr>
+                <th>File</th>
+                <th>Additions</th>
+                <th>Deletions</th>
+                <th>Status</th>
+            </tr>
+        </thead>
+        <tbody>
+            {% for file in commit.changed_files %}
+            <tr>
+                <td>{{ file.file }}</td>
+                <td style="color: green;">+{{ file.additions }}</td>
+                <td style="color: red;">-{{ file.deletions }}</td>
+                <td>{{ file.status }}</td>
+            </tr>
+            {% endfor %}
+        </tbody>
+    </table>
+    {% if commit.parent_id %}
+    <p><a href="{{ url_for('repo_diff', repo_name=repo_name) }}?id1={{ commit.parent_id }}&id2={{ commit.id }}">View Full Diff</a></p>
     {% endif %}
-    <h2>Diff</h2>
-    {% if commit.diff %}
-    <pre>{{ commit.diff }}</pre>
     {% else %}
     <p>No changes compared to parent</p>
     {% endif %}