Skip to content

Commit 2be07ea

Browse files
authored
Merge branch 'main' into lunny/fix_bug
2 parents 3abd282 + efe77ee commit 2be07ea

Some content is hidden

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

45 files changed

+227
-164
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ endif
4343
ifeq ($(OS), Windows_NT)
4444
GOFLAGS := -v -buildmode=exe
4545
EXECUTABLE ?= gitea.exe
46+
else ifeq ($(OS), Windows)
47+
GOFLAGS := -v -buildmode=exe
48+
EXECUTABLE ?= gitea.exe
4649
else
4750
GOFLAGS := -v
4851
EXECUTABLE ?= gitea

cmd/web.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/graceful"
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/modules/setting"
19-
"code.gitea.io/gitea/modules/util"
2019
"code.gitea.io/gitea/routers"
2120
"code.gitea.io/gitea/routers/routes"
2221

@@ -152,19 +151,6 @@ func setPort(port string) error {
152151
case setting.FCGI:
153152
case setting.FCGIUnix:
154153
default:
155-
// Save LOCAL_ROOT_URL if port changed
156-
cfg := ini.Empty()
157-
isFile, err := util.IsFile(setting.CustomConf)
158-
if err != nil {
159-
log.Fatal("Unable to check if %s is a file", err)
160-
}
161-
if isFile {
162-
// Keeps custom settings if there is already something.
163-
if err := cfg.Append(setting.CustomConf); err != nil {
164-
return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err)
165-
}
166-
}
167-
168154
defaultLocalURL := string(setting.Protocol) + "://"
169155
if setting.HTTPAddr == "0.0.0.0" {
170156
defaultLocalURL += "localhost"
@@ -173,10 +159,10 @@ func setPort(port string) error {
173159
}
174160
defaultLocalURL += ":" + setting.HTTPPort + "/"
175161

176-
cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL)
177-
if err := cfg.SaveTo(setting.CustomConf); err != nil {
178-
return fmt.Errorf("Error saving generated LOCAL_ROOT_URL to custom config: %v", err)
179-
}
162+
// Save LOCAL_ROOT_URL if port changed
163+
setting.CreateOrAppendToCustomConf(func(cfg *ini.File) {
164+
cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL)
165+
})
180166
}
181167
return nil
182168
}

custom/conf/app.example.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,8 @@ PATH =
11451145
;;
11461146
;; When ISSUE_INDEXER_QUEUE_TYPE is levelqueue, this will be the path where the queue will be saved.
11471147
;; This can be overridden by `ISSUE_INDEXER_QUEUE_CONN_STR`.
1148-
;; default is indexers/issues.queue
1149-
;ISSUE_INDEXER_QUEUE_DIR = indexers/issues.queue
1148+
;; default is queues/common
1149+
;ISSUE_INDEXER_QUEUE_DIR = queues/common
11501150
;;
11511151
;; When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string.
11521152
;; When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of
@@ -1201,7 +1201,7 @@ PATH =
12011201
;; default to persistable-channel
12021202
;TYPE = persistable-channel
12031203
;;
1204-
;; data-dir for storing persistable queues and level queues, individual queues will be named by their type
1204+
;; data-dir for storing persistable queues and level queues, individual queues will default to `queues/common` meaning the queue is shared.
12051205
;DATADIR = queues/
12061206
;;
12071207
;; Default queue length before a channel queue will block
@@ -1231,7 +1231,7 @@ PATH =
12311231
;TIMEOUT = 15m30s
12321232
;;
12331233
;; Create a pool with this many workers
1234-
;WORKERS = 1
1234+
;WORKERS = 0
12351235
;;
12361236
;; Dynamically scale the worker pool to at this many workers
12371237
;MAX_WORKERS = 10
@@ -1243,7 +1243,7 @@ PATH =
12431243
;BOOST_TIMEOUT = 5m
12441244
;;
12451245
;; During a boost add BOOST_WORKERS
1246-
;BOOST_WORKERS = 5
1246+
;BOOST_WORKERS = 1
12471247

12481248
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12491249
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ update: $(THEME)
3131
$(THEME): $(THEME)/theme.toml
3232
$(THEME)/theme.toml:
3333
mkdir -p $$(dirname $@)
34-
curl -s $(ARCHIVE) | tar xz -C $$(dirname $@)
34+
curl -L -s $(ARCHIVE) | tar xz -C $$(dirname $@)

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ relation to port exhaustion.
350350
- `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search; available when ISSUE_INDEXER_TYPE is bleve and elasticsearch.
351351
- The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility:
352352
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`.
353-
- `ISSUE_INDEXER_QUEUE_DIR`: **indexers/issues.queue**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved.
353+
- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.)
354354
- `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string. When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`.
355355
- `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number.
356356

@@ -370,7 +370,7 @@ relation to port exhaustion.
370370
## Queue (`queue` and `queue.*`)
371371

372372
- `TYPE`: **persistable-channel**: General queue type, currently support: `persistable-channel` (uses a LevelDB internally), `channel`, `level`, `redis`, `dummy`
373-
- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`name`**.
373+
- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`common`**. (Previously each queue would default to `DATADIR/`**`name`**.)
374374
- `LENGTH`: **20**: Maximal queue size before channel queues block
375375
- `BATCH_LENGTH`: **20**: Batch data before passing to the handler
376376
- `CONN_STR`: **redis://127.0.0.1:6379/0**: Connection string for the redis queue type. Options can be set using query params. Similarly LevelDB options can also be set using: **leveldb://relative/path?option=value** or **leveldb:///absolute/path?option=value**, and will override `DATADIR`
@@ -381,11 +381,11 @@ relation to port exhaustion.
381381
- `MAX_ATTEMPTS`: **10**: Maximum number of attempts to create the wrapped queue
382382
- `TIMEOUT`: **GRACEFUL_HAMMER_TIME + 30s**: Timeout the creation of the wrapped queue if it takes longer than this to create.
383383
- Queues by default come with a dynamically scaling worker pool. The following settings configure this:
384-
- `WORKERS`: **1**: Number of initial workers for the queue.
384+
- `WORKERS`: **0** (v1.14 and before: **1**): Number of initial workers for the queue.
385385
- `MAX_WORKERS`: **10**: Maximum number of worker go-routines for the queue.
386386
- `BLOCK_TIMEOUT`: **1s**: If the queue blocks for this time, boost the number of workers - the `BLOCK_TIMEOUT` will then be doubled before boosting again whilst the boost is ongoing.
387387
- `BOOST_TIMEOUT`: **5m**: Boost workers will timeout after this long.
388-
- `BOOST_WORKERS`: **5**: This many workers will be added to the worker pool if there is a boost.
388+
- `BOOST_WORKERS`: **1** (v1.14 and before: **5**): This many workers will be added to the worker pool if there is a boost.
389389

390390
## Admin (`admin`)
391391

integrations/pull_merge_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ func TestCantMergeWorkInProgress(t *testing.T) {
197197
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())
198198
assert.NotEmpty(t, text, "Can't find WIP text")
199199

200-
// remove <strong /> from lang
201-
expected := i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress", "[wip]")
202-
replacer := strings.NewReplacer("<strong>", "", "</strong>", "")
203-
assert.Equal(t, replacer.Replace(expected), text, "Unable to find WIP text")
200+
assert.Contains(t, text, i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
201+
assert.Contains(t, text, "[wip]", "Unable to find WIP text")
204202
})
205203
}
206204

modules/auth/sso/basic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (b *Basic) IsEnabled() bool {
5151
func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
5252

5353
// Basic authentication should only fire on API, Download or on Git or LFSPaths
54-
if middleware.IsInternalPath(req) || !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitOrLFSPath(req) {
54+
if middleware.IsInternalPath(req) || !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawOrLFSPath(req) {
5555
return nil
5656
}
5757

modules/auth/sso/reverseproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter,
7878
}
7979

8080
// Make sure requests to API paths, attachment downloads, git and LFS do not create a new session
81-
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitOrLFSPath(req) {
81+
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawOrLFSPath(req) {
8282
if sess.Get("uid").(int64) != user.ID {
8383
handleSignIn(w, req, sess, user)
8484
}

modules/auth/sso/sso.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ func isAttachmentDownload(req *http.Request) bool {
104104
return strings.HasPrefix(req.URL.Path, "/attachments/") && req.Method == "GET"
105105
}
106106

107-
var gitPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/))`)
107+
var gitRawPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|raw/)`)
108108
var lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`)
109109

110-
func isGitOrLFSPath(req *http.Request) bool {
111-
if gitPathRe.MatchString(req.URL.Path) {
110+
func isGitRawOrLFSPath(req *http.Request) bool {
111+
if gitRawPathRe.MatchString(req.URL.Path) {
112112
return true
113113
}
114114
if setting.LFS.StartServer {

modules/auth/sso/sso_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/setting"
1313
)
1414

15-
func Test_isGitOrLFSPath(t *testing.T) {
15+
func Test_isGitRawOrLFSPath(t *testing.T) {
1616

1717
tests := []struct {
1818
path string
@@ -63,6 +63,10 @@ func Test_isGitOrLFSPath(t *testing.T) {
6363
"/owner/repo/objects/pack/pack-0123456789abcdef0123456789abcdef0123456.idx",
6464
true,
6565
},
66+
{
67+
"/owner/repo/raw/branch/foo/fanaso",
68+
true,
69+
},
6670
{
6771
"/owner/repo/stars",
6872
false,
@@ -98,11 +102,11 @@ func Test_isGitOrLFSPath(t *testing.T) {
98102
t.Run(tt.path, func(t *testing.T) {
99103
req, _ := http.NewRequest("POST", "http://localhost"+tt.path, nil)
100104
setting.LFS.StartServer = false
101-
if got := isGitOrLFSPath(req); got != tt.want {
105+
if got := isGitRawOrLFSPath(req); got != tt.want {
102106
t.Errorf("isGitOrLFSPath() = %v, want %v", got, tt.want)
103107
}
104108
setting.LFS.StartServer = true
105-
if got := isGitOrLFSPath(req); got != tt.want {
109+
if got := isGitRawOrLFSPath(req); got != tt.want {
106110
t.Errorf("isGitOrLFSPath() = %v, want %v", got, tt.want)
107111
}
108112
})
@@ -111,11 +115,11 @@ func Test_isGitOrLFSPath(t *testing.T) {
111115
t.Run(tt, func(t *testing.T) {
112116
req, _ := http.NewRequest("POST", tt, nil)
113117
setting.LFS.StartServer = false
114-
if got := isGitOrLFSPath(req); got != setting.LFS.StartServer {
115-
t.Errorf("isGitOrLFSPath(%q) = %v, want %v, %v", tt, got, setting.LFS.StartServer, gitPathRe.MatchString(tt))
118+
if got := isGitRawOrLFSPath(req); got != setting.LFS.StartServer {
119+
t.Errorf("isGitOrLFSPath(%q) = %v, want %v, %v", tt, got, setting.LFS.StartServer, gitRawPathRe.MatchString(tt))
116120
}
117121
setting.LFS.StartServer = true
118-
if got := isGitOrLFSPath(req); got != setting.LFS.StartServer {
122+
if got := isGitRawOrLFSPath(req); got != setting.LFS.StartServer {
119123
t.Errorf("isGitOrLFSPath(%q) = %v, want %v", tt, got, setting.LFS.StartServer)
120124
}
121125
})

modules/setting/indexer.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package setting
66

77
import (
8-
"path"
98
"path/filepath"
109
"strings"
1110
"time"
@@ -68,23 +67,23 @@ var (
6867
func newIndexerService() {
6968
sec := Cfg.Section("indexer")
7069
Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
71-
Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
70+
Indexer.IssuePath = filepath.ToSlash(sec.Key("ISSUE_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/issues.bleve"))))
7271
if !filepath.IsAbs(Indexer.IssuePath) {
73-
Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
72+
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath))
7473
}
7574
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
7675
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
7776

7877
Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
79-
Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "queues/common"))
78+
Indexer.IssueQueueDir = filepath.ToSlash(sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "queues/common"))))
8079
Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString("")
8180
Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
8281

8382
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
8483
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
85-
Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
84+
Indexer.RepoPath = filepath.ToSlash(sec.Key("REPO_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/repos.bleve"))))
8685
if !filepath.IsAbs(Indexer.RepoPath) {
87-
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
86+
Indexer.RepoPath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.RepoPath))
8887
}
8988
Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
9089
Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("gitea_codes")

modules/setting/lfs.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ package setting
66

77
import (
88
"encoding/base64"
9-
"os"
10-
"path/filepath"
119
"time"
1210

1311
"code.gitea.io/gitea/modules/generate"
1412
"code.gitea.io/gitea/modules/git"
1513
"code.gitea.io/gitea/modules/log"
16-
"code.gitea.io/gitea/modules/util"
1714

1815
ini "gopkg.in/ini.v1"
1916
)
@@ -64,27 +61,9 @@ func newLFSService() {
6461
}
6562

6663
// Save secret
67-
cfg := ini.Empty()
68-
isFile, err := util.IsFile(CustomConf)
69-
if err != nil {
70-
log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
71-
}
72-
if isFile {
73-
// Keeps custom settings if there is already something.
74-
if err := cfg.Append(CustomConf); err != nil {
75-
log.Error("Failed to load custom conf '%s': %v", CustomConf, err)
76-
}
77-
}
78-
79-
cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
80-
81-
if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
82-
log.Fatal("Failed to create '%s': %v", CustomConf, err)
83-
}
84-
if err := cfg.SaveTo(CustomConf); err != nil {
85-
log.Fatal("Error saving generated JWT Secret to custom config: %v", err)
86-
return
87-
}
64+
CreateOrAppendToCustomConf(func(cfg *ini.File) {
65+
cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
66+
})
8867
}
8968
}
9069
}

modules/setting/queue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func GetQueueSettings(name string) QueueSettings {
4848
q.Name = name
4949

5050
// DataDir is not directly inheritable
51-
q.DataDir = filepath.Join(Queue.DataDir, "common")
51+
q.DataDir = filepath.ToSlash(filepath.Join(Queue.DataDir, "common"))
5252
// QueueName is not directly inheritable either
5353
q.QueueName = name + Queue.QueueName
5454
for _, key := range sec.Keys() {
@@ -91,9 +91,9 @@ func GetQueueSettings(name string) QueueSettings {
9191
// This is exported for tests to be able to use the queue
9292
func NewQueueService() {
9393
sec := Cfg.Section("queue")
94-
Queue.DataDir = sec.Key("DATADIR").MustString("queues/")
94+
Queue.DataDir = filepath.ToSlash(sec.Key("DATADIR").MustString("queues/"))
9595
if !filepath.IsAbs(Queue.DataDir) {
96-
Queue.DataDir = filepath.Join(AppDataPath, Queue.DataDir)
96+
Queue.DataDir = filepath.ToSlash(filepath.Join(AppDataPath, Queue.DataDir))
9797
}
9898
Queue.QueueLength = sec.Key("LENGTH").MustInt(20)
9999
Queue.BatchLength = sec.Key("BATCH_LENGTH").MustInt(20)

0 commit comments

Comments
 (0)