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 'Permit to download patch and diff file between tags and branches' (#5385) from mirkoperillo/forgejo:issue-3728 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5385
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

Gusted da5445ac e28bd3c4

+137 -1
+25 -1
routers/web/repo/compare.go
··· 231 231 if infoPath == "" { 232 232 infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} 233 233 } else { 234 + infoPath, isDiff := strings.CutSuffix(infoPath, ".diff") 235 + ctx.Data["ComparingDiff"] = isDiff 236 + if !isDiff { 237 + var isPatch bool 238 + infoPath, isPatch = strings.CutSuffix(infoPath, ".patch") 239 + ctx.Data["ComparingPatch"] = isPatch 240 + } 234 241 infos = strings.SplitN(infoPath, "...", 2) 235 242 if len(infos) != 2 { 236 243 if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 { ··· 717 724 return 718 725 } 719 726 727 + if ctx.Data["ComparingDiff"] != nil && ctx.Data["ComparingDiff"].(bool) { 728 + err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, git.RawDiffNormal, "", ctx.Resp) 729 + if err != nil { 730 + ctx.ServerError("ComparingDiff", err) 731 + return 732 + } 733 + } 734 + 735 + if ctx.Data["ComparingPatch"] != nil && ctx.Data["ComparingPatch"].(bool) { 736 + err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, git.RawDiffPatch, "", ctx.Resp) 737 + if err != nil { 738 + ctx.ServerError("ComparingPatch", err) 739 + return 740 + } 741 + } 742 + 720 743 ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes 721 744 ctx.Data["DirectComparison"] = ci.DirectComparison 722 745 ctx.Data["OtherCompareSeparator"] = ".." ··· 802 825 if ci.DirectComparison { 803 826 separator = ".." 804 827 } 805 - ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID) 828 + ctx.Data["Comparing"] = base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID) 829 + ctx.Data["Title"] = "Comparing " + ctx.Data["Comparing"].(string) 806 830 807 831 ctx.Data["IsDiffCompare"] = true 808 832 _, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
+3
templates/repo/diff/options_dropdown.tmpl
··· 11 11 {{else if .Commit.ID.String}} 12 12 <a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.patch" download="{{ShortSha .Commit.ID.String}}.patch">{{ctx.Locale.Tr "repo.diff.download_patch"}}</a> 13 13 <a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.diff" download="{{ShortSha .Commit.ID.String}}.diff">{{ctx.Locale.Tr "repo.diff.download_diff"}}</a> 14 + {{else if .Diff}} 15 + <a class="item" href="{{$.RepoLink}}/compare/{{.Comparing}}.patch" download="{{.Comparing}}.patch">{{ctx.Locale.Tr "repo.diff.download_patch"}}</a> 16 + <a class="item" href="{{$.RepoLink}}/compare/{{.Comparing}}.diff" download="{{.Comparing}}.diff">{{ctx.Locale.Tr "repo.diff.download_diff"}}</a> 14 17 {{end}} 15 18 <a id="expand-files-btn" class="item">{{ctx.Locale.Tr "repo.pulls.expand_files"}}</a> 16 19 <a id="collapse-files-btn" class="item">{{ctx.Locale.Tr "repo.pulls.collapse_files"}}</a>
+109
tests/integration/compare_test.go
··· 23 23 files_service "code.gitea.io/gitea/services/repository/files" 24 24 "code.gitea.io/gitea/tests" 25 25 26 + "github.com/PuerkitoBio/goquery" 26 27 "github.com/stretchr/testify/assert" 27 28 "github.com/stretchr/testify/require" 28 29 ) ··· 65 66 selection = htmlDoc.doc.Find(fmt.Sprintf("[data-new-filename=\"%s\"]", diffChange)) 66 67 assert.Lenf(t, selection.Nodes, 1, "Expected 1 match for [data-new-filename=\"%s\"], found: %v", diffChange, len(selection.Nodes)) 67 68 } 69 + } 70 + 71 + func TestComparePatchAndDiffMenuEntries(t *testing.T) { 72 + defer tests.PrepareTestEnv(t)() 73 + 74 + session := loginUser(t, "user2") 75 + req := NewRequest(t, "GET", "/user2/repo-release/compare/v1.0...v2.0") 76 + resp := session.MakeRequest(t, req, http.StatusOK) 77 + htmlDoc := NewHTMLParser(t, resp.Body) 78 + downloadOptions := htmlDoc.doc.Find("a.item[download]") 79 + var patchDownloadEntryPresent bool 80 + var diffDownloadEntryPresent bool 81 + downloadOptions.Each(func(idx int, c *goquery.Selection) { 82 + value, exists := c.Attr("download") 83 + if exists && strings.HasSuffix(value, ".patch") { 84 + patchDownloadEntryPresent = true 85 + } 86 + 87 + if exists && strings.HasSuffix(value, ".diff") { 88 + diffDownloadEntryPresent = true 89 + } 90 + }) 91 + 92 + assert.True(t, patchDownloadEntryPresent, "Patch file download entry should be present") 93 + assert.True(t, diffDownloadEntryPresent, "Diff file download entry should be present") 94 + } 95 + 96 + func TestComparePatchDownload(t *testing.T) { 97 + defer tests.PrepareTestEnv(t)() 98 + 99 + session := loginUser(t, "user2") 100 + req := NewRequest(t, "GET", "/user2/repo-release/compare/v1.0...v2.0.patch") 101 + attendedResponse := `From 4380f99290b2b3922733ff82c57afad915ace907 Mon Sep 17 00:00:00 2001 102 + From: user1 <address1@example.com> 103 + Date: Mon, 17 Apr 2023 14:39:35 +0200 104 + Subject: [PATCH 1/3] feature v2 105 + 106 + --- 107 + feature | 0 108 + 1 file changed, 0 insertions(+), 0 deletions(-) 109 + create mode 100644 feature 110 + 111 + diff --git a/feature b/feature 112 + new file mode 100644 113 + index 0000000..e69de29 114 + 115 + From 79f9d88f1b054d650f88da0bd658e21f7b0cf6ec Mon Sep 17 00:00:00 2001 116 + From: user1 <address1@example.com> 117 + Date: Mon, 17 Apr 2023 14:38:53 +0200 118 + Subject: [PATCH 2/3] bugfix 119 + 120 + --- 121 + bugfix | 0 122 + 1 file changed, 0 insertions(+), 0 deletions(-) 123 + create mode 100644 bugfix 124 + 125 + diff --git a/bugfix b/bugfix 126 + new file mode 100644 127 + index 0000000..e69de29 128 + 129 + From 7197b56fdc75b453f47c9110938cb46a303579fd Mon Sep 17 00:00:00 2001 130 + From: user1 <address1@example.com> 131 + Date: Mon, 17 Apr 2023 14:42:34 +0200 132 + Subject: [PATCH 3/3] readme: v2 133 + 134 + --- 135 + README.md | 2 +- 136 + 1 file changed, 1 insertion(+), 1 deletion(-) 137 + 138 + diff --git a/README.md b/README.md 139 + index 6dfe48a..bc7068d 100644 140 + --- a/README.md 141 + +++ b/README.md 142 + @@ -1,3 +1,3 @@ 143 + # Releases test repo 144 + 145 + -With a v1.0 146 + +With a v1.0 and a v2.0 147 + ` 148 + 149 + resp := session.MakeRequest(t, req, http.StatusOK) 150 + assert.Equal(t, attendedResponse, resp.Body.String()) 151 + } 152 + 153 + func TestCompareDiffDownload(t *testing.T) { 154 + defer tests.PrepareTestEnv(t)() 155 + 156 + session := loginUser(t, "user2") 157 + req := NewRequest(t, "GET", "/user2/repo-release/compare/v1.0...v2.0.diff") 158 + attendedResponse := `diff --git a/README.md b/README.md 159 + index 6dfe48a..bc7068d 100644 160 + --- a/README.md 161 + +++ b/README.md 162 + @@ -1,3 +1,3 @@ 163 + # Releases test repo 164 + 165 + -With a v1.0 166 + +With a v1.0 and a v2.0 167 + diff --git a/bugfix b/bugfix 168 + new file mode 100644 169 + index 0000000..e69de29 170 + diff --git a/feature b/feature 171 + new file mode 100644 172 + index 0000000..e69de29 173 + ` 174 + 175 + resp := session.MakeRequest(t, req, http.StatusOK) 176 + assert.Equal(t, attendedResponse, resp.Body.String()) 68 177 } 69 178 70 179 // Git commit graph for repo20