Skip to content

Commit 7129981

Browse files
Merge branch 'main' into fix-16804-report-the-len
2 parents f36ad45 + 28ac4a7 commit 7129981

File tree

98 files changed

+334
-84
lines changed

Some content is hidden

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

98 files changed

+334
-84
lines changed

build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//+build vendor
5+
//go:build vendor
6+
// +build vendor
67

78
package main
89

build/generate-bindata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build ignore
56
// +build ignore
67

78
package main

build/generate-emoji.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build ignore
67
// +build ignore
78

89
package main

build/generate-gitignores.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
package main

build/generate-licenses.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
package main

build/gocovmerge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// gocovmerge takes the results from multiple `go test -coverprofile` runs and
77
// merges them into one profile
88

9+
//go:build ignore
910
// +build ignore
1011

1112
package main

cmd/embedded.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build bindata
56
// +build bindata
67

78
package cmd

cmd/embedded_stub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !bindata
56
// +build !bindata
67

78
package cmd

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ INTERNAL_TOKEN=
392392
;; Enables OAuth2 provider
393393
ENABLE = true
394394
;;
395-
;; Algorithm used to sign OAuth2 tokens. Valid values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512
395+
;; Algorithm used to sign OAuth2 tokens. Valid values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, EdDSA
396396
;JWT_SIGNING_ALGORITHM = RS256
397397
;;
398398
;; Private key file path used to sign OAuth2 tokens. The path is relative to APP_DATA_PATH.

models/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// ResourceIndex represents a resource index which could be used as issue/release and others
1515
// We can create different tables i.e. issue_index, release_index and etc.
1616
type ResourceIndex struct {
17-
GroupID int64 `xorm:"unique"`
17+
GroupID int64 `xorm:"pk"`
1818
MaxIndex int64 `xorm:"index"`
1919
}
2020

models/issue_label.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package models
88
import (
99
"fmt"
1010
"html/template"
11+
"math"
1112
"regexp"
1213
"strconv"
1314
"strings"
@@ -138,19 +139,44 @@ func (label *Label) BelongsToRepo() bool {
138139
return label.RepoID > 0
139140
}
140141

142+
// SrgbToLinear converts a component of an sRGB color to its linear intensity
143+
// See: https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation_(sRGB_to_CIE_XYZ)
144+
func SrgbToLinear(color uint8) float64 {
145+
flt := float64(color) / 255
146+
if flt <= 0.04045 {
147+
return flt / 12.92
148+
}
149+
return math.Pow((flt+0.055)/1.055, 2.4)
150+
}
151+
152+
// Luminance returns the luminance of an sRGB color
153+
func Luminance(color uint32) float64 {
154+
r := SrgbToLinear(uint8(0xFF & (color >> 16)))
155+
g := SrgbToLinear(uint8(0xFF & (color >> 8)))
156+
b := SrgbToLinear(uint8(0xFF & color))
157+
158+
// luminance ratios for sRGB
159+
return 0.2126*r + 0.7152*g + 0.0722*b
160+
}
161+
162+
// LuminanceThreshold is the luminance at which white and black appear to have the same contrast
163+
// i.e. x such that 1.05 / (x + 0.05) = (x + 0.05) / 0.05
164+
// i.e. math.Sqrt(1.05*0.05) - 0.05
165+
const LuminanceThreshold float64 = 0.179
166+
141167
// ForegroundColor calculates the text color for labels based
142168
// on their background color.
143169
func (label *Label) ForegroundColor() template.CSS {
144170
if strings.HasPrefix(label.Color, "#") {
145171
if color, err := strconv.ParseUint(label.Color[1:], 16, 64); err == nil {
146-
r := float32(0xFF & (color >> 16))
147-
g := float32(0xFF & (color >> 8))
148-
b := float32(0xFF & color)
149-
luminance := (0.2126*r + 0.7152*g + 0.0722*b) / 255
172+
// NOTE: see web_src/js/components/ContextPopup.vue for similar implementation
173+
luminance := Luminance(uint32(color))
150174

151-
if luminance < 0.66 {
175+
// prefer white or black based upon contrast
176+
if luminance < LuminanceThreshold {
152177
return template.CSS("#fff")
153178
}
179+
return template.CSS("#000")
154180
}
155181
}
156182

models/migrations/migrations.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ var migrations = []Migration{
336336
NewMigration("Add agit flow pull request support", addAgitFlowPullRequest),
337337
// v191 -> v192
338338
NewMigration("Alter issue/comment table TEXT fields to LONGTEXT", alterIssueAndCommentTextFieldsToLongText),
339+
// v192 -> v193
340+
NewMigration("RecreateIssueResourceIndexTable to have a primary key instead of an unique index", recreateIssueResourceIndexTable),
339341
}
340342

341343
// GetCurrentDBVersion returns the current db version
@@ -429,7 +431,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
429431
// Reset the mapper between each migration - migrations are not supposed to depend on each other
430432
x.SetMapper(names.GonicMapper{})
431433
if err = m.Migrate(x); err != nil {
432-
return fmt.Errorf("do migrate: %v", err)
434+
return fmt.Errorf("migration[%d]: %s failed: %v", v+int64(i), m.Description(), err)
433435
}
434436
currentVersion.Version = v + int64(i) + 1
435437
if _, err = x.ID(1).Update(currentVersion); err != nil {

models/migrations/v182.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
func addIssueResourceIndexTable(x *xorm.Engine) error {
1212
type ResourceIndex struct {
13-
GroupID int64 `xorm:"index unique(s)"`
14-
MaxIndex int64 `xorm:"index unique(s)"`
13+
GroupID int64 `xorm:"pk"`
14+
MaxIndex int64 `xorm:"index"`
1515
}
1616

1717
sess := x.NewSession()

models/migrations/v182_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func Test_addIssueResourceIndexTable(t *testing.T) {
3333
}
3434

3535
type ResourceIndex struct {
36-
GroupID int64 `xorm:"index unique(s)"`
37-
MaxIndex int64 `xorm:"index unique(s)"`
36+
GroupID int64 `xorm:"pk"`
37+
MaxIndex int64 `xorm:"index"`
3838
}
3939

4040
var start = 0

models/migrations/v192.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func recreateIssueResourceIndexTable(x *xorm.Engine) error {
12+
type IssueIndex struct {
13+
GroupID int64 `xorm:"pk"`
14+
MaxIndex int64 `xorm:"index"`
15+
}
16+
17+
return RecreateTables(new(IssueIndex))(x)
18+
}

models/user.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
16191619
}
16201620

16211621
if opts.Actor != nil {
1622-
var exprCond builder.Cond
1623-
if setting.Database.UseMySQL {
1624-
exprCond = builder.Expr("org_user.org_id = user.id")
1625-
} else if setting.Database.UseMSSQL {
1626-
exprCond = builder.Expr("org_user.org_id = [user].id")
1627-
} else {
1628-
exprCond = builder.Expr("org_user.org_id = \"user\".id")
1629-
}
1622+
var exprCond builder.Cond = builder.Expr("org_user.org_id = `user`.id")
16301623

16311624
// If Admin - they see all users!
16321625
if !opts.Actor.IsAdmin {

modules/auth/pam/pam.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// +build pam
2-
31
// Copyright 2014 The Gogs Authors. All rights reserved.
42
// Use of this source code is governed by a MIT-style
53
// license that can be found in the LICENSE file.
64

5+
//go:build pam
6+
// +build pam
7+
78
package pam
89

910
import (

modules/auth/pam/pam_stub.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// +build !pam
2-
31
// Copyright 2014 The Gogs Authors. All rights reserved.
42
// Use of this source code is governed by a MIT-style
53
// license that can be found in the LICENSE file.
64

5+
//go:build !pam
6+
// +build !pam
7+
78
package pam
89

910
import (

modules/auth/pam/pam_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pam
12
// +build pam
23

34
// Copyright 2021 The Gitea Authors. All rights reserved.

modules/git/blob_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/blob_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/command_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build race
56
// +build race
67

78
package git

modules/git/commit_convert_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/commit_info_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/last_commit_cache_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/last_commit_cache_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/log_name_status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int
167167
return nil, err
168168
}
169169
}
170+
if len(g.next) == 0 {
171+
return &ret, nil
172+
}
170173
if g.next[0] == '\x00' {
171174
g.buffull = false
172175
g.next, err = g.rd.ReadSlice('\x00')

modules/git/notes_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/notes_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/parse_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/parse_gogit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/parse_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/parse_nogogit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/pipeline/lfs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package pipeline

modules/git/pipeline/lfs_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package pipeline

0 commit comments

Comments
 (0)