loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Expand code diffs against the commits repo' (#3765) from algernon/forgejo:<del>300</del>500 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3765
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+49 -6
+3 -3
templates/repo/diff/section_split.tmpl
··· 18 18 <td class="lines-num lines-num-old"> 19 19 <div class="tw-flex"> 20 20 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} 21 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 21 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 22 22 {{svg "octicon-fold-down"}} 23 23 </button> 24 24 {{end}} 25 25 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} 26 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 26 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 27 27 {{svg "octicon-fold-up"}} 28 28 </button> 29 29 {{end}} 30 30 {{if eq $line.GetExpandDirection 2}} 31 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 31 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 32 32 {{svg "octicon-fold"}} 33 33 </button> 34 34 {{end}}
+3 -3
templates/repo/diff/section_unified.tmpl
··· 14 14 <td colspan="2" class="lines-num"> 15 15 <div class="tw-flex"> 16 16 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} 17 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 17 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 18 18 {{svg "octicon-fold-down"}} 19 19 </button> 20 20 {{end}} 21 21 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} 22 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 22 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 23 23 {{svg "octicon-fold-up"}} 24 24 </button> 25 25 {{end}} 26 26 {{if eq $line.GetExpandDirection 2}} 27 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 27 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 28 28 {{svg "octicon-fold"}} 29 29 </button> 30 30 {{end}}
+43
tests/integration/compare_test.go
··· 15 15 repo_model "code.gitea.io/gitea/models/repo" 16 16 unit_model "code.gitea.io/gitea/models/unit" 17 17 "code.gitea.io/gitea/models/unittest" 18 + user_model "code.gitea.io/gitea/models/user" 18 19 "code.gitea.io/gitea/modules/gitrepo" 20 + "code.gitea.io/gitea/modules/optional" 19 21 repo_service "code.gitea.io/gitea/services/repository" 22 + files_service "code.gitea.io/gitea/services/repository/files" 20 23 "code.gitea.io/gitea/tests" 21 24 22 25 "github.com/stretchr/testify/assert" ··· 213 216 }) 214 217 }) 215 218 } 219 + 220 + func TestCompareCodeExpand(t *testing.T) { 221 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 222 + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) 223 + 224 + // Create a new repository, with a file that has many lines 225 + repo, _, f := CreateDeclarativeRepoWithOptions(t, owner, DeclarativeRepoOptions{ 226 + Files: optional.Some([]*files_service.ChangeRepoFile{ 227 + { 228 + Operation: "create", 229 + TreePath: "docs.md", 230 + ContentReader: strings.NewReader("01\n02\n03\n04\n05\n06\n07\n08\n09\n0a\n0b\n0c\n0d\n0e\n0f\n10\n11\n12\n12\n13\n14\n15\n16\n17\n18\n19\n1a\n1b\n1c\n1d\n1e\n1f\n20\n"), 231 + }, 232 + }), 233 + }) 234 + defer f() 235 + 236 + // Fork the repository 237 + forker := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 238 + session := loginUser(t, forker.Name) 239 + testRepoFork(t, session, owner.Name, repo.Name, forker.Name, repo.Name+"-copy") 240 + testCreateBranch(t, session, forker.Name, repo.Name+"-copy", "branch/main", "code-expand", http.StatusSeeOther) 241 + 242 + // Edit the file, insert a line somewhere in the middle 243 + testEditFile(t, session, forker.Name, repo.Name+"-copy", "code-expand", "docs.md", 244 + "01\n02\n03\n04\n05\n06\n07\n08\n09\n0a\n0b\n0c\n0d\n0e\n0f\n10\n11\nHELLO WORLD!\n12\n12\n13\n14\n15\n16\n17\n18\n19\n1a\n1b\n1c\n1d\n1e\n1f\n20\n", 245 + ) 246 + 247 + t.Run("code expander targets the fork", func(t *testing.T) { 248 + defer tests.PrintCurrentTest(t)() 249 + 250 + req := NewRequestf(t, "GET", "%s/%s/compare/main...%s/%s:code-expand", 251 + owner.Name, repo.Name, forker.Name, repo.Name+"-copy") 252 + resp := session.MakeRequest(t, req, http.StatusOK) 253 + htmlDoc := NewHTMLParser(t, resp.Body) 254 + htmlDoc.AssertElement(t, fmt.Sprintf("button.code-expander-button[hx-get^='/%s/%s/blob_excerpt/'] svg.octicon-fold-up", forker.Name, repo.Name+"-copy"), true) 255 + htmlDoc.AssertElement(t, fmt.Sprintf("button.code-expander-button[hx-get^='/%s/%s/blob_excerpt/'] svg.octicon-fold-down", forker.Name, repo.Name+"-copy"), true) 256 + }) 257 + }) 258 + }