detached 925a4ec

fix(web): send the split layout of large diffs when the URL asks for it

commit
925a4ec81b7aa34e22be0542cf7209c90631b594
author
brice · · 2026-10-10 14:21 UTC
parent
dbe8671
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +32 -2
M cmd/ermite/web_commit_test.go +30 -0
@@ -3,6 +3,9 @@
33 package main
44
55 import (
6+ "fmt"
7+ "os"
8+ "path/filepath"
69 "strings"
710 "testing"
811
@@ -134,6 +137,33 @@ func TestWebCommit(t *testing.T) {
134137 })
135138 }
136139
140+// Over 4,000 lines only one layout is sent, the one the URL asks for.
141+func TestWebCommitLargeDiffView(t *testing.T) {
142+ h := newHarness(t, harnessOpts{})
143+ h.seed("large", domain.VisibilityPublic)
144+ wt := h.workTree("main", "README")
145+ var lines strings.Builder
146+ for i := range 1500 {
147+ fmt.Fprintf(&lines, "line %d\n", i)
148+ }
149+ for _, name := range []string{"a.txt", "b.txt", "c.txt"} {
150+ require.NoError(t, os.WriteFile(filepath.Join(wt, name), []byte(lines.String()), 0o644))
151+ }
152+ h.mustGit(wt, "add", ".")
153+ h.mustGit(wt, "commit", "-q", "-m", "three big files")
154+ h.mustGit(wt, "push", "-q", h.urlAuth(adminToken, "/large.git"), "main")
155+ sha := strings.TrimSpace(h.mustGit(wt, "rev-parse", "HEAD"))
156+
157+ _, _, unified := h.get("/large/commit/" + sha)
158+ assert.True(t, strings.Contains(unified, `<table class="dt uni"`), "unified by default")
159+ assert.False(t, strings.Contains(unified, `<table class="dt spl"`), "one layout only")
160+
161+ _, _, split := h.get("/large/commit/" + sha + "?view=split")
162+ assert.True(t, strings.Contains(split, `<table class="dt spl"`), "the split layout is sent")
163+ assert.False(t, strings.Contains(split, `<table class="dt uni"`), "and only it")
164+ assert.True(t, strings.Contains(split, `<div id="diffs" data-view="split">`))
165+}
166+
137167 // AC2: the commit pages of a private repository are the 404 page of a
138168 // repository that does not exist.
139169 func TestWebCommitPrivate(t *testing.T) {
@@ -3,6 +3,9 @@
3 package main3 package main
4 4
5 import (5 import (
6+ "fmt"
7+ "os"
8+ "path/filepath"
6 "strings"9 "strings"
7 "testing"10 "testing"
8 11
@@ -134,6 +137,33 @@ func TestWebCommit(t *testing.T) {
134 })137 })
135 }138 }
136 139
140+// Over 4,000 lines only one layout is sent, the one the URL asks for.
141+func TestWebCommitLargeDiffView(t *testing.T) {
142+ h := newHarness(t, harnessOpts{})
143+ h.seed("large", domain.VisibilityPublic)
144+ wt := h.workTree("main", "README")
145+ var lines strings.Builder
146+ for i := range 1500 {
147+ fmt.Fprintf(&lines, "line %d\n", i)
148+ }
149+ for _, name := range []string{"a.txt", "b.txt", "c.txt"} {
150+ require.NoError(t, os.WriteFile(filepath.Join(wt, name), []byte(lines.String()), 0o644))
151+ }
152+ h.mustGit(wt, "add", ".")
153+ h.mustGit(wt, "commit", "-q", "-m", "three big files")
154+ h.mustGit(wt, "push", "-q", h.urlAuth(adminToken, "/large.git"), "main")
155+ sha := strings.TrimSpace(h.mustGit(wt, "rev-parse", "HEAD"))
156+
157+ _, _, unified := h.get("/large/commit/" + sha)
158+ assert.True(t, strings.Contains(unified, `<table class="dt uni"`), "unified by default")
159+ assert.False(t, strings.Contains(unified, `<table class="dt spl"`), "one layout only")
160+
161+ _, _, split := h.get("/large/commit/" + sha + "?view=split")
162+ assert.True(t, strings.Contains(split, `<table class="dt spl"`), "the split layout is sent")
163+ assert.False(t, strings.Contains(split, `<table class="dt uni"`), "and only it")
164+ assert.True(t, strings.Contains(split, `<div id="diffs" data-view="split">`))
165+}
166+
137 // AC2: the commit pages of a private repository are the 404 page of a167 // AC2: the commit pages of a private repository are the 404 page of a
138 // repository that does not exist.168 // repository that does not exist.
139 func TestWebCommitPrivate(t *testing.T) {169 func TestWebCommitPrivate(t *testing.T) {
M internal/adapters/web/commit.go +2 -2
@@ -114,14 +114,14 @@ func (s *Server) commit(ctx context.Context, r *http.Request) (templ.Component,
114114 p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker)
115115 }
116116 }
117- p.Both = lines <= bothViewsLines
118- p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split"
119117 switch r.URL.Query().Get("view") {
120118 case "split":
121119 p.View, p.Pinned = "split", true
122120 case "unified":
123121 p.Pinned = true
124122 }
123+ p.Both = lines <= bothViewsLines
124+ p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split"
125125 base := repoHref(d.name(), "commit", c.GetId())
126126 p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split"
127127
@@ -114,14 +114,14 @@ func (s *Server) commit(ctx context.Context, r *http.Request) (templ.Component,
114 p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker)114 p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker)
115 }115 }
116 }116 }
117- p.Both = lines <= bothViewsLines
118- p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split"
119 switch r.URL.Query().Get("view") {117 switch r.URL.Query().Get("view") {
120 case "split":118 case "split":
121 p.View, p.Pinned = "split", true119 p.View, p.Pinned = "split", true
122 case "unified":120 case "unified":
123 p.Pinned = true121 p.Pinned = true
124 }122 }
123+ p.Both = lines <= bothViewsLines
124+ p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split"
125 base := repoHref(d.name(), "commit", c.GetId())125 base := repoHref(d.name(), "commit", c.GetId())
126 p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split"126 p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split"
127 127

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 45

↑↓ moveenter openesc close