1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 | diff --git a/src/plugins/git.py b/src/plugins/git.py
index 00e6b84..7b510b4 100644
--- a/src/plugins/git.py
+++ b/src/plugins/git.py
@@ -171,6 +171,15 @@ def _load_refs(path: str) -> list[Ref]:
Ref(name="tags", refs=_load_single_ref(path, "refs/tags")),
Ref(name="remotes", refs=_load_single_ref(path, "refs/remotes")),
]
+def compute_bars(changed_files: list[ChangedFile], max_width: int = 30) -> list[dict]:
+ max_changes = max((f.added_lines + f.removed_lines for f in changed_files), default=1) or 1
+ bars = []
+ for f in changed_files:
+ total = f.added_lines + f.removed_lines
+ width = round((total / max_changes) * max_width) if total else 0
+ add_w = round(width * f.added_lines / total) if total else 0
+ bars.append({"file": f, "total": total, "add_width": add_w, "del_width": width - add_w})
+ return bars
def _load_commits(path: str) -> list[Commit]:
@@ -179,6 +188,7 @@ def _load_commits(path: str) -> list[Commit]:
"log",
"--date=format:%Y-%m-%d %H:%M",
"--numstat",
+ "--raw",
"--no-merges",
"--format=%x1e%H%x1f%an%x1f%ad%x1f%s",
)
@@ -197,27 +207,29 @@ def _load_commits(path: str) -> list[Commit]:
continue
commit_hash, author, date, message = parts
+ statuses: dict[str, str] = {}
+ numstats: list[tuple[str, str, str]] = []
- changed_files: list[ChangedFile] = []
for line in lines[1:]:
- file_parts = line.split("\t")
- if len(file_parts) != 3:
- continue
-
- added, removed, filename = file_parts
- try:
- added_int = int(added)
- except ValueError:
- added_int = 0
-
- try:
- removed_int = int(removed)
- except ValueError:
- removed_int = 0
-
- changed_files.append(
- ChangedFile(name=filename, added_lines=added_int, removed_lines=removed_int)
+ if line.startswith(":"):
+ raw_parts = line.split("\t")
+ meta = raw_parts[0].split()
+ if len(meta) >= 5 and len(raw_parts) >= 2:
+ statuses[raw_parts[-1]] = meta[4][0]
+ else:
+ fields = line.split("\t")
+ if len(fields) == 3:
+ numstats.append(tuple(fields))
+
+ changed_files: list[ChangedFile] = [
+ ChangedFile(
+ name=filename,
+ added_lines=int(added) if added.isdigit() else 0,
+ removed_lines=int(removed) if removed.isdigit() else 0,
+ status=statuses.get(filename, "M"),
)
+ for added, removed, filename in numstats
+ ]
if not changed_files:
continue
diff --git a/src/plugins/log_builder.py b/src/plugins/log_builder.py
index b66119b..db26658 100644
--- a/src/plugins/log_builder.py
+++ b/src/plugins/log_builder.py
@@ -1,6 +1,7 @@
import os
from models import Repo
from dataclasses import asdict
+from git import compute_bars
from progress import progress, progress_done
@@ -37,6 +38,7 @@ def _create_commit_page(api, repo_name, repo_desc, commit):
"commit_author": commit.author,
"changed_files": [asdict(f) for f in commit.files],
"diff_content": patch_html,
+ "bars":compute_bars(commit.files),
})
api.save_html(html, dest)
diff --git a/src/plugins/models.py b/src/plugins/models.py
index 6435efe..6895b7b 100644
--- a/src/plugins/models.py
+++ b/src/plugins/models.py
@@ -6,6 +6,7 @@ class ChangedFile:
name: str
added_lines: int
removed_lines: int
+ status: str = "M"
@dataclass
diff --git a/src/templates/Log-commit.html b/src/templates/Log-commit.html
index ee9e722..aca5195 100644
--- a/src/templates/Log-commit.html
+++ b/src/templates/Log-commit.html
@@ -5,30 +5,24 @@
<h1>{{commit_message}}</h1>
-<blockquote>
+<blockquote class="flex justify-between py-5">
<p>
<strong>author:</strong> {{commit_author}} <br>
<strong>date:</strong> {{commit_date}} <br>
<strong>hash:</strong> {{commit_hash}} <br>
</p>
-</blockquote>
+</blockquote>
-<table class="!w-full !table-fixed !border-1 ">
- <thead>
- <tr>
- <th>File</th>
- <th>+</th>
- <th>-</th>
- </tr>
- </thead>
+<table class="diffstat ![direction:ltr] !w-full !table-fixed !border-0 px-6">
<tbody>
-
-{% for file in changed_files %}
+{% for b in bars %}
<tr>
- <td>{{file.name}}</td>
- <td class="!text-green-500 text-right">{{file.added_lines}}</td>
- <td class="!text-red-500 text-right">{{file.removed_lines}}</td>
+ <td class="!text-gray-400 flex gap-2.5"><p class="flex gap-2.5"><strong>{{b.file.status}}</strong></p> {{b.file.name}}</td>
+ <td class="!text-right !text-gray-400">{{b.total}}</td>
+ <td>
+ <span class="!text-green-500">{{ "+" * b.add_width }}</span><span class="!text-red-500">{{ "-" * b.del_width }}</span>
+ </td>
</tr>
{% endfor %}
</tbody>
|