diff --git a/git/commit.py b/git/commit.py
index 6627a7e..34ab713 100644
--- a/git/commit.py
+++ b/git/commit.py
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)
'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,
'files_changed': 0
}
diff = None
+ changed_files = []
commit_info = {
'id': str(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
<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 %}