Skip to content

Commit f26e773

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-21957-update-bleve-to-update-zapx
2 parents cce15a4 + cdc4345 commit f26e773

File tree

35 files changed

+455
-320
lines changed

35 files changed

+455
-320
lines changed

docs/content/doc/installation/from-source.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ launched manually from command line, it can be killed by pressing `Ctrl + C`.
145145

146146
Gitea will search for a number of things from the _`CustomPath`_. By default this is
147147
the `custom/` directory in the current working directory when running Gitea. It will also
148-
look for its configuration file _`CustomConf`_ in _`CustomPath`_/conf/app.ini`, and will use the
148+
look for its configuration file _`CustomConf`_ in `$(CustomPath)/conf/app.ini`, and will use the
149149
current working directory as the relative base path _`AppWorkPath`_ for a number configurable
150150
values. Finally the static files will be served from _`StaticRootPath`_ which defaults to the _`AppWorkPath`_.
151151

models/db/iterate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
2525
return nil
2626
})
2727
assert.NoError(t, err)
28-
assert.EqualValues(t, 79, repoCnt)
28+
assert.EqualValues(t, 80, repoCnt)
2929

3030
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3131
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/fixtures/repo_unit.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,9 @@
544544
repo_id: 51
545545
type: 2
546546
created_unix: 946684810
547+
548+
-
549+
id: 80
550+
repo_id: 53
551+
type: 1
552+
created_unix: 946684810

models/fixtures/repository.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,30 @@
15581558
size: 0
15591559
is_fsck_enabled: true
15601560
close_issues_via_commit_in_any_branch: false
1561+
1562+
-
1563+
id: 53
1564+
owner_id: 30
1565+
owner_name: user30
1566+
lower_name: renderer
1567+
name: renderer
1568+
is_archived: false
1569+
is_empty: false
1570+
is_private: false
1571+
num_issues: 0
1572+
num_closed_issues: 0
1573+
num_pulls: 0
1574+
num_closed_pulls: 0
1575+
num_milestones: 0
1576+
num_closed_milestones: 0
1577+
num_watches: 0
1578+
num_projects: 0
1579+
num_closed_projects: 0
1580+
status: 0
1581+
is_fork: false
1582+
fork_id: 0
1583+
is_template: false
1584+
template_id: 0
1585+
size: 0
1586+
is_fsck_enabled: true
1587+
close_issues_via_commit_in_any_branch: false

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@
11021102
num_followers: 0
11031103
num_following: 0
11041104
num_stars: 0
1105-
num_repos: 3
1105+
num_repos: 4
11061106
num_teams: 0
11071107
num_members: 0
11081108
visibility: 0

models/packages/package_version.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,14 @@ func SearchLatestVersions(ctx context.Context, opts *PackageSearchOptions) ([]*P
302302
cond := opts.toConds().
303303
And(builder.Expr("pv2.id IS NULL"))
304304

305+
joinCond := builder.Expr("package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))")
306+
if !opts.IsInternal.IsNone() {
307+
joinCond = joinCond.And(builder.Eq{"pv2.is_internal": opts.IsInternal.IsTrue()})
308+
}
309+
305310
sess := db.GetEngine(ctx).
306311
Table("package_version").
307-
Join("LEFT", "package_version pv2", "package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))").
312+
Join("LEFT", "package_version pv2", joinCond).
308313
Join("INNER", "package", "package.id = package_version.package_id").
309314
Where(cond)
310315

models/repo/repo_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
235235
{
236236
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
237237
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
238-
count: 28,
238+
count: 29,
239239
},
240240
{
241241
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
242242
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
243-
count: 33,
243+
count: 34,
244244
},
245245
{
246246
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
@@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
255255
{
256256
name: "AllPublic/PublicRepositoriesOfOrganization",
257257
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
258-
count: 28,
258+
count: 29,
259259
},
260260
{
261261
name: "AllTemplates",

modules/setting/setting.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ func getAppPath() (string, error) {
465465
appPath, err = exec.LookPath(os.Args[0])
466466
}
467467

468+
if err != nil {
469+
// FIXME: Once we switch to go 1.19 use !errors.Is(err, exec.ErrDot)
470+
if !strings.Contains(err.Error(), "cannot run executable found relative to current directory") {
471+
return "", err
472+
}
473+
appPath, err = filepath.Abs(os.Args[0])
474+
}
468475
if err != nil {
469476
return "", err
470477
}

modules/web/route.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
goctx "context"
88
"fmt"
99
"net/http"
10-
"reflect"
1110
"strings"
1211

1312
"code.gitea.io/gitea/modules/context"
@@ -18,16 +17,9 @@ import (
1817
)
1918

2019
// Bind binding an obj to a handler
21-
func Bind(obj interface{}) http.HandlerFunc {
22-
tp := reflect.TypeOf(obj)
23-
if tp.Kind() == reflect.Ptr {
24-
tp = tp.Elem()
25-
}
26-
if tp.Kind() != reflect.Struct {
27-
panic("Only structs are allowed to bind")
28-
}
20+
func Bind[T any](obj T) http.HandlerFunc {
2921
return Wrap(func(ctx *context.Context) {
30-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
22+
theObj := new(T) // create a new form obj for every request but not use obj directly
3123
binding.Bind(ctx.Req, theObj)
3224
SetForm(ctx, theObj)
3325
middleware.AssignForm(theObj, ctx.Data)

routers/api/packages/npm/npm.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo
405405

406406
func PackageSearch(ctx *context.Context) {
407407
pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
408-
OwnerID: ctx.Package.Owner.ID,
409-
Type: packages_model.TypeNpm,
408+
OwnerID: ctx.Package.Owner.ID,
409+
Type: packages_model.TypeNpm,
410+
IsInternal: util.OptionalBoolFalse,
410411
Name: packages_model.SearchValue{
411412
ExactMatch: false,
412413
Value: ctx.FormTrim("text"),

routers/api/v1/api.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import (
6767
gocontext "context"
6868
"fmt"
6969
"net/http"
70-
"reflect"
7170
"strings"
7271

7372
"code.gitea.io/gitea/models/organization"
@@ -575,13 +574,9 @@ func mustEnableAttachments(ctx *context.APIContext) {
575574
}
576575

577576
// bind binding an obj to a func(ctx *context.APIContext)
578-
func bind(obj interface{}) http.HandlerFunc {
579-
tp := reflect.TypeOf(obj)
580-
for tp.Kind() == reflect.Ptr {
581-
tp = tp.Elem()
582-
}
577+
func bind[T any](obj T) http.HandlerFunc {
583578
return web.Wrap(func(ctx *context.APIContext) {
584-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
579+
theObj := new(T) // create a new form obj for every request but not use obj directly
585580
errs := binding.Bind(ctx.Req, theObj)
586581
if len(errs) > 0 {
587582
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))

routers/private/internal.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package private
66

77
import (
88
"net/http"
9-
"reflect"
109
"strings"
1110

1211
"code.gitea.io/gitea/modules/context"
@@ -39,13 +38,9 @@ func CheckInternalToken(next http.Handler) http.Handler {
3938
}
4039

4140
// bind binding an obj to a handler
42-
func bind(obj interface{}) http.HandlerFunc {
43-
tp := reflect.TypeOf(obj)
44-
for tp.Kind() == reflect.Ptr {
45-
tp = tp.Elem()
46-
}
41+
func bind[T any](obj T) http.HandlerFunc {
4742
return web.Wrap(func(ctx *context.PrivateContext) {
48-
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
43+
theObj := new(T) // create a new form obj for every request but not use obj directly
4944
binding.Bind(ctx.Req, theObj)
5045
web.SetForm(ctx, theObj)
5146
})

0 commit comments

Comments
 (0)