FossilRepo

Add line numbers to diff view (old + new columns) - Parse @@ hunk headers to track old/new line counters - Show old line number (left gutter) and new line number (right gutter) - Context lines show both, additions show only new, deletions show only old - Matches GitHub/GitLab diff line number display

lmata 2026-04-06 14:35 trunk
Commit 5a04a5733693ed246bd700e0959b6813d4e7e51be4e3920f7d04f448d81cc7f1
+19 -1
--- fossil/views.py
+++ fossil/views.py
@@ -302,23 +302,41 @@
302302
fromfile=f"a/{f['name']}",
303303
tofile=f"b/{f['name']}",
304304
lineterm="",
305305
n=3,
306306
)
307
+ old_line = 0
308
+ new_line = 0
307309
for line in diff:
308310
line_type = "context"
311
+ old_num = ""
312
+ new_num = ""
309313
if line.startswith("+++") or line.startswith("---"):
310314
line_type = "header"
311315
elif line.startswith("@@"):
312316
line_type = "hunk"
317
+ # Parse @@ -old_start,old_count +new_start,new_count @@
318
+ hunk_match = re.match(r"@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@", line)
319
+ if hunk_match:
320
+ old_line = int(hunk_match.group(1))
321
+ new_line = int(hunk_match.group(2))
313322
elif line.startswith("+"):
314323
line_type = "add"
315324
additions += 1
325
+ new_num = new_line
326
+ new_line += 1
316327
elif line.startswith("-"):
317328
line_type = "del"
318329
deletions += 1
319
- diff_lines.append({"text": line, "type": line_type})
330
+ old_num = old_line
331
+ old_line += 1
332
+ else:
333
+ old_num = old_line
334
+ new_num = new_line
335
+ old_line += 1
336
+ new_line += 1
337
+ diff_lines.append({"text": line, "type": line_type, "old_num": old_num, "new_num": new_num})
320338
321339
ext = f["name"].rsplit(".", 1)[-1] if "." in f["name"] else ""
322340
file_diffs.append(
323341
{
324342
"name": f["name"],
325343
--- fossil/views.py
+++ fossil/views.py
@@ -302,23 +302,41 @@
302 fromfile=f"a/{f['name']}",
303 tofile=f"b/{f['name']}",
304 lineterm="",
305 n=3,
306 )
 
 
307 for line in diff:
308 line_type = "context"
 
 
309 if line.startswith("+++") or line.startswith("---"):
310 line_type = "header"
311 elif line.startswith("@@"):
312 line_type = "hunk"
 
 
 
 
 
313 elif line.startswith("+"):
314 line_type = "add"
315 additions += 1
 
 
316 elif line.startswith("-"):
317 line_type = "del"
318 deletions += 1
319 diff_lines.append({"text": line, "type": line_type})
 
 
 
 
 
 
 
320
321 ext = f["name"].rsplit(".", 1)[-1] if "." in f["name"] else ""
322 file_diffs.append(
323 {
324 "name": f["name"],
325
--- fossil/views.py
+++ fossil/views.py
@@ -302,23 +302,41 @@
302 fromfile=f"a/{f['name']}",
303 tofile=f"b/{f['name']}",
304 lineterm="",
305 n=3,
306 )
307 old_line = 0
308 new_line = 0
309 for line in diff:
310 line_type = "context"
311 old_num = ""
312 new_num = ""
313 if line.startswith("+++") or line.startswith("---"):
314 line_type = "header"
315 elif line.startswith("@@"):
316 line_type = "hunk"
317 # Parse @@ -old_start,old_count +new_start,new_count @@
318 hunk_match = re.match(r"@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@", line)
319 if hunk_match:
320 old_line = int(hunk_match.group(1))
321 new_line = int(hunk_match.group(2))
322 elif line.startswith("+"):
323 line_type = "add"
324 additions += 1
325 new_num = new_line
326 new_line += 1
327 elif line.startswith("-"):
328 line_type = "del"
329 deletions += 1
330 old_num = old_line
331 old_line += 1
332 else:
333 old_num = old_line
334 new_num = new_line
335 old_line += 1
336 new_line += 1
337 diff_lines.append({"text": line, "type": line_type, "old_num": old_num, "new_num": new_num})
338
339 ext = f["name"].rsplit(".", 1)[-1] if "." in f["name"] else ""
340 file_diffs.append(
341 {
342 "name": f["name"],
343
--- templates/fossil/checkin_detail.html
+++ templates/fossil/checkin_detail.html
@@ -115,11 +115,12 @@
115115
{% elif fd.diff_lines %}
116116
<table class="diff-table">
117117
<tbody>
118118
{% for dl in fd.diff_lines %}
119119
<tr class="diff-line-{{ dl.type }}">
120
- <td class="diff-gutter"></td>
120
+ <td class="diff-gutter">{{ dl.old_num }}</td>
121
+ <td class="diff-gutter">{{ dl.new_num }}</td>
121122
<td>{{ dl.text }}</td>
122123
</tr>
123124
{% endfor %}
124125
</tbody>
125126
</table>
126127
--- templates/fossil/checkin_detail.html
+++ templates/fossil/checkin_detail.html
@@ -115,11 +115,12 @@
115 {% elif fd.diff_lines %}
116 <table class="diff-table">
117 <tbody>
118 {% for dl in fd.diff_lines %}
119 <tr class="diff-line-{{ dl.type }}">
120 <td class="diff-gutter"></td>
 
121 <td>{{ dl.text }}</td>
122 </tr>
123 {% endfor %}
124 </tbody>
125 </table>
126
--- templates/fossil/checkin_detail.html
+++ templates/fossil/checkin_detail.html
@@ -115,11 +115,12 @@
115 {% elif fd.diff_lines %}
116 <table class="diff-table">
117 <tbody>
118 {% for dl in fd.diff_lines %}
119 <tr class="diff-line-{{ dl.type }}">
120 <td class="diff-gutter">{{ dl.old_num }}</td>
121 <td class="diff-gutter">{{ dl.new_num }}</td>
122 <td>{{ dl.text }}</td>
123 </tr>
124 {% endfor %}
125 </tbody>
126 </table>
127

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button