Skip to content

Commit a12c2c6

Browse files
authored
Merge branch 'main' into fix-tmpl
2 parents c8bb25e + 2a828e2 commit a12c2c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+485
-496
lines changed

modules/git/repo_compare.go

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -233,72 +233,34 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
233233
return numFiles, totalAdditions, totalDeletions, err
234234
}
235235

236-
// GetDiffOrPatch generates either diff or formatted patch data between given revisions
237-
func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, binary bool) error {
238-
if patch {
239-
return repo.GetPatch(base, head, w)
240-
}
241-
if binary {
242-
return repo.GetDiffBinary(base, head, w)
243-
}
244-
return repo.GetDiff(base, head, w)
245-
}
246-
247236
// GetDiff generates and returns patch data between given revisions, optimized for human readability
248-
func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
237+
func (repo *Repository) GetDiff(compareArg string, w io.Writer) error {
249238
stderr := new(bytes.Buffer)
250-
err := NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(base + "..." + head).
239+
return NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(compareArg).
251240
Run(&RunOpts{
252241
Dir: repo.Path,
253242
Stdout: w,
254243
Stderr: stderr,
255244
})
256-
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
257-
return NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(base, head).
258-
Run(&RunOpts{
259-
Dir: repo.Path,
260-
Stdout: w,
261-
})
262-
}
263-
return err
264245
}
265246

266247
// GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
267-
func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error {
268-
stderr := new(bytes.Buffer)
269-
err := NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(base + "..." + head).
270-
Run(&RunOpts{
271-
Dir: repo.Path,
272-
Stdout: w,
273-
Stderr: stderr,
274-
})
275-
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
276-
return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(base, head).
277-
Run(&RunOpts{
278-
Dir: repo.Path,
279-
Stdout: w,
280-
})
281-
}
282-
return err
248+
func (repo *Repository) GetDiffBinary(compareArg string, w io.Writer) error {
249+
return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(compareArg).Run(&RunOpts{
250+
Dir: repo.Path,
251+
Stdout: w,
252+
})
283253
}
284254

285255
// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
286-
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
256+
func (repo *Repository) GetPatch(compareArg string, w io.Writer) error {
287257
stderr := new(bytes.Buffer)
288-
err := NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(base + "..." + head).
258+
return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(compareArg).
289259
Run(&RunOpts{
290260
Dir: repo.Path,
291261
Stdout: w,
292262
Stderr: stderr,
293263
})
294-
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
295-
return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(base, head).
296-
Run(&RunOpts{
297-
Dir: repo.Path,
298-
Stdout: w,
299-
})
300-
}
301-
return err
302264
}
303265

304266
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
@@ -329,21 +291,6 @@ func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, err
329291
return split, err
330292
}
331293

332-
// GetDiffFromMergeBase generates and return patch data from merge base to head
333-
func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error {
334-
stderr := new(bytes.Buffer)
335-
err := NewCommand(repo.Ctx, "diff", "-p", "--binary").AddDynamicArguments(base + "..." + head).
336-
Run(&RunOpts{
337-
Dir: repo.Path,
338-
Stdout: w,
339-
Stderr: stderr,
340-
})
341-
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
342-
return repo.GetDiffBinary(base, head, w)
343-
}
344-
return err
345-
}
346-
347294
// ReadPatchCommit will check if a diff patch exists and return stats
348295
func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error) {
349296
// Migrated repositories download patches to "pulls" location

modules/git/repo_compare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGetFormatPatch(t *testing.T) {
2828
defer repo.Close()
2929

3030
rd := &bytes.Buffer{}
31-
err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
31+
err = repo.GetPatch("8d92fc95^...8d92fc95", rd)
3232
if err != nil {
3333
assert.NoError(t, err)
3434
return

modules/setting/setting.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,9 @@ func checkOverlappedPath(name, path string) {
235235
}
236236
configuredPaths[path] = name
237237
}
238+
239+
func PanicInDevOrTesting(msg string, a ...any) {
240+
if !IsProd || IsInTesting {
241+
panic(fmt.Sprintf(msg, a...))
242+
}
243+
}

modules/templates/helper.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,5 @@ func QueryBuild(a ...any) template.URL {
331331
}
332332

333333
func panicIfDevOrTesting() {
334-
if !setting.IsProd || setting.IsInTesting {
335-
panic("legacy template functions are for backward compatibility only, do not use them in new code")
336-
}
334+
setting.PanicInDevOrTesting("legacy template functions are for backward compatibility only, do not use them in new code")
337335
}

routers/api/v1/admin/adopt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func AdoptRepository(ctx *context.APIContext) {
8080
// "$ref": "#/responses/notFound"
8181
// "403":
8282
// "$ref": "#/responses/forbidden"
83-
ownerName := ctx.PathParam(":username")
84-
repoName := ctx.PathParam(":reponame")
83+
ownerName := ctx.PathParam("username")
84+
repoName := ctx.PathParam("reponame")
8585

8686
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
8787
if err != nil {
@@ -142,8 +142,8 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
142142
// "$ref": "#/responses/empty"
143143
// "403":
144144
// "$ref": "#/responses/forbidden"
145-
ownerName := ctx.PathParam(":username")
146-
repoName := ctx.PathParam(":reponame")
145+
ownerName := ctx.PathParam("username")
146+
repoName := ctx.PathParam("reponame")
147147

148148
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
149149
if err != nil {

routers/api/v1/admin/cron.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func PostCronTask(ctx *context.APIContext) {
7474
// "$ref": "#/responses/empty"
7575
// "404":
7676
// "$ref": "#/responses/notFound"
77-
task := cron.GetTask(ctx.PathParam(":task"))
77+
task := cron.GetTask(ctx.PathParam("task"))
7878
if task == nil {
7979
ctx.NotFound()
8080
return

routers/api/v1/admin/email.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func GetAllEmails(ctx *context.APIContext) {
3838
listOptions := utils.GetListOptions(ctx)
3939

4040
emails, maxResults, err := user_model.SearchEmails(ctx, &user_model.SearchEmailOptions{
41-
Keyword: ctx.PathParam(":email"),
41+
Keyword: ctx.PathParam("email"),
4242
ListOptions: listOptions,
4343
})
4444
if err != nil {
@@ -82,6 +82,6 @@ func SearchEmail(ctx *context.APIContext) {
8282
// "403":
8383
// "$ref": "#/responses/forbidden"
8484

85-
ctx.SetPathParam(":email", ctx.FormTrim("q"))
85+
ctx.SetPathParam("email", ctx.FormTrim("q"))
8686
GetAllEmails(ctx)
8787
}

routers/api/v1/admin/hooks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func GetHook(ctx *context.APIContext) {
7373
// "200":
7474
// "$ref": "#/responses/Hook"
7575

76-
hookID := ctx.PathParamInt64(":id")
76+
hookID := ctx.PathParamInt64("id")
7777
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
7878
if err != nil {
7979
if errors.Is(err, util.ErrNotExist) {
@@ -142,7 +142,7 @@ func EditHook(ctx *context.APIContext) {
142142
form := web.GetForm(ctx).(*api.EditHookOption)
143143

144144
// TODO in body params
145-
hookID := ctx.PathParamInt64(":id")
145+
hookID := ctx.PathParamInt64("id")
146146
utils.EditSystemHook(ctx, form, hookID)
147147
}
148148

@@ -164,7 +164,7 @@ func DeleteHook(ctx *context.APIContext) {
164164
// "204":
165165
// "$ref": "#/responses/empty"
166166

167-
hookID := ctx.PathParamInt64(":id")
167+
hookID := ctx.PathParamInt64("id")
168168
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
169169
if errors.Is(err, util.ErrNotExist) {
170170
ctx.NotFound()

routers/api/v1/admin/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
375375
// "404":
376376
// "$ref": "#/responses/notFound"
377377

378-
if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64(":id")); err != nil {
378+
if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64("id")); err != nil {
379379
if asymkey_model.IsErrKeyNotExist(err) {
380380
ctx.NotFound()
381381
} else if asymkey_model.IsErrKeyAccessDenied(err) {

routers/api/v1/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,12 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
596596

597597
var err error
598598
if assignOrg {
599-
ctx.Org.Organization, err = organization.GetOrgByName(ctx, ctx.PathParam(":org"))
599+
ctx.Org.Organization, err = organization.GetOrgByName(ctx, ctx.PathParam("org"))
600600
if err != nil {
601601
if organization.IsErrOrgNotExist(err) {
602-
redirectUserID, err := user_model.LookupUserRedirect(ctx, ctx.PathParam(":org"))
602+
redirectUserID, err := user_model.LookupUserRedirect(ctx, ctx.PathParam("org"))
603603
if err == nil {
604-
context.RedirectToUser(ctx.Base, ctx.PathParam(":org"), redirectUserID)
604+
context.RedirectToUser(ctx.Base, ctx.PathParam("org"), redirectUserID)
605605
} else if user_model.IsErrUserRedirectNotExist(err) {
606606
ctx.NotFound("GetOrgByName", err)
607607
} else {
@@ -616,7 +616,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
616616
}
617617

618618
if assignTeam {
619-
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64(":teamid"))
619+
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64("teamid"))
620620
if err != nil {
621621
if organization.IsErrTeamNotExist(err) {
622622
ctx.NotFound()

0 commit comments

Comments
 (0)