Skip to content

Commit 9f89b2f

Browse files
committed
Merge branch 'main' into fix-git-legacy
2 parents e8fad37 + 88f2e45 commit 9f89b2f

Some content is hidden

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

61 files changed

+416
-162
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ steps:
109109
depends_on: [test-frontend]
110110

111111
- name: build-backend-no-gcc
112-
image: golang:1.17 # this step is kept as the lowest version of golang that we support
112+
image: golang:1.18 # this step is kept as the lowest version of golang that we support
113113
pull: always
114114
environment:
115115
GO111MODULE: on

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ fomantic:
704704
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
705705
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
706706
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
707+
$(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
707708
rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
708709

709710
.PHONY: webpack

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ or if SQLite support is required:
7373

7474
The `build` target is split into two sub-targets:
7575

76-
- `make backend` which requires [Go 1.17](https://go.dev/dl/) or greater.
76+
- `make backend` which requires [Go Stable](https://go.dev/dl/), required version is defined in [go.mod](/go.mod).
7777
- `make frontend` which requires [Node.js LTS](https://nodejs.org/en/download/) or greater and Internet connectivity to download npm dependencies.
7878

7979
When building from the official source tarballs which include pre-built frontend files, the `frontend` target will not be triggered, making it possible to build without Node.js and Internet connectivity.

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.16.8
22-
minGoVersion: 1.17
22+
minGoVersion: 1.18
2323
goVersion: 1.18
2424
minNodeVersion: 14
2525

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a
315315
- `SSL_MAX_VERSION`: **\<empty\>**: Set the maximum version of ssl support.
316316
- `SSL_CURVE_PREFERENCES`: **X25519,P256**: Set the preferred curves,
317317
- `SSL_CIPHER_SUITES`: **ecdhe_ecdsa_with_aes_256_gcm_sha384,ecdhe_rsa_with_aes_256_gcm_sha384,ecdhe_ecdsa_with_aes_128_gcm_sha256,ecdhe_rsa_with_aes_128_gcm_sha256,ecdhe_ecdsa_with_chacha20_poly1305,ecdhe_rsa_with_chacha20_poly1305**: Set the preferred cipher suites.
318-
- If there is not hardware support for AES suites by default the cha cha suites will be preferred over the AES suites
319-
- supported suites as of go 1.17 are:
318+
- If there is no hardware support for AES suites, by default the ChaCha suites will be preferred over the AES suites.
319+
- supported suites as of Go 1.18 are:
320320
- TLS 1.0 - 1.2 cipher suites
321321
- "rsa_with_rc4_128_sha"
322322
- "rsa_with_3des_ede_cbc_sha"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b

integrations/integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
275275
assert.NoError(t, unittest.LoadFixtures())
276276
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
277277
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
278-
assert.NoError(t, git.InitWithConfigSync(context.Background()))
278+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
279279
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
280280
if err != nil {
281281
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
@@ -576,7 +576,7 @@ func resetFixtures(t *testing.T) {
576576
assert.NoError(t, unittest.LoadFixtures())
577577
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
578578
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
579-
assert.NoError(t, git.InitWithConfigSync(context.Background()))
579+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
580580
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
581581
if err != nil {
582582
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

integrations/migration-test/migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func initMigrationTest(t *testing.T) func() {
6262
assert.True(t, len(setting.RepoRootPath) != 0)
6363
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
6464
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
65-
assert.NoError(t, git.InitWithConfigSync(context.Background()))
65+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
6666
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
6767
if err != nil {
6868
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

models/migrations/migrations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func prepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.En
203203
deferFn := PrintCurrentTest(t, ourSkip)
204204
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
205205
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
206-
assert.NoError(t, git.InitWithConfigSync(context.Background()))
206+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
207207
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
208208
if err != nil {
209209
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

models/repo/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ func (repo *Repository) ComposeMetas() map[string]string {
414414
switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
415415
case markup.IssueNameStyleAlphanumeric:
416416
metas["style"] = markup.IssueNameStyleAlphanumeric
417+
case markup.IssueNameStyleRegexp:
418+
metas["style"] = markup.IssueNameStyleRegexp
419+
metas["regexp"] = unit.ExternalTrackerConfig().ExternalTrackerRegexpPattern
417420
default:
418421
metas["style"] = markup.IssueNameStyleNumeric
419422
}

models/repo/repo_unit.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {
7676

7777
// ExternalTrackerConfig describes external tracker config
7878
type ExternalTrackerConfig struct {
79-
ExternalTrackerURL string
80-
ExternalTrackerFormat string
81-
ExternalTrackerStyle string
79+
ExternalTrackerURL string
80+
ExternalTrackerFormat string
81+
ExternalTrackerStyle string
82+
ExternalTrackerRegexpPattern string
8283
}
8384

8485
// FromDB fills up a ExternalTrackerConfig from serialized format.

models/repo_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func TestMetas(t *testing.T) {
7474
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
7575
testSuccess(markup.IssueNameStyleNumeric)
7676

77+
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
78+
testSuccess(markup.IssueNameStyleRegexp)
79+
7780
repo, err := repo_model.GetRepositoryByID(3)
7881
assert.NoError(t, err)
7982

models/unittest/testdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
117117
if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
118118
fatalTestError("util.CopyDir: %v\n", err)
119119
}
120-
if err = git.InitWithConfigSync(context.Background()); err != nil {
120+
if err = git.InitOnceWithSync(context.Background()); err != nil {
121121
fatalTestError("git.Init: %v\n", err)
122122
}
123123

@@ -202,7 +202,7 @@ func PrepareTestEnv(t testing.TB) {
202202
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
203203
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
204204
assert.NoError(t, CopyDir(metaPath, setting.RepoRootPath))
205-
assert.NoError(t, git.InitWithConfigSync(context.Background()))
205+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
206206

207207
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
208208
assert.NoError(t, err)

modules/git/git.go

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ var (
3131
GitExecutable = "git"
3232

3333
// DefaultContext is the default context to run git commands in
34-
// will be overwritten by InitWithConfigSync with HammerContext
34+
// will be overwritten by InitXxx with HammerContext
3535
DefaultContext = context.Background()
3636

3737
// SupportProcReceive version >= 2.29.0
3838
SupportProcReceive bool
3939

40-
// initMutex is used to avoid Golang's data race error. see the comments below.
41-
initMutex sync.Mutex
42-
4340
gitVersion *version.Version
4441
)
4542

@@ -128,15 +125,6 @@ func VersionInfo() string {
128125
return fmt.Sprintf(format, args...)
129126
}
130127

131-
// InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
132-
// This method doesn't change anything to filesystem
133-
func InitSimple(ctx context.Context) error {
134-
initMutex.Lock()
135-
defer initMutex.Unlock()
136-
137-
return initSimpleInternal(ctx)
138-
}
139-
140128
// HomeDir is the home dir for git to store the global config file used by Gitea internally
141129
func HomeDir() string {
142130
if setting.RepoRootPath == "" {
@@ -150,11 +138,9 @@ func HomeDir() string {
150138
return setting.RepoRootPath
151139
}
152140

153-
func initSimpleInternal(ctx context.Context) error {
154-
// at the moment, when running integration tests, the git.InitXxx would be called twice.
155-
// one is called by the GlobalInitInstalled, one is called by TestMain.
156-
// so the init functions should be protected by a mutex to avoid Golang's data race error.
157-
141+
// InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
142+
// This method doesn't change anything to filesystem. At the moment, it is only used by "git serv" sub-command, no data-race
143+
func InitSimple(ctx context.Context) error {
158144
DefaultContext = ctx
159145

160146
if setting.Git.Timeout.Default > 0 {
@@ -171,33 +157,45 @@ func initSimpleInternal(ctx context.Context) error {
171157
return nil
172158
}
173159

174-
// InitWithConfigSync initializes git module. This method may create directories or write files into filesystem
175-
func InitWithConfigSync(ctx context.Context) error {
176-
initMutex.Lock()
177-
defer initMutex.Unlock()
160+
var initOnce sync.Once
178161

179-
err := initSimpleInternal(ctx)
180-
if err != nil {
181-
return err
182-
}
162+
// InitOnceWithSync initializes git module with version check and change global variables, sync gitconfig.
163+
// This method will update the global variables ONLY ONCE (just like git.CheckLFSVersion -- which is not ideal too),
164+
// otherwise there will be data-race problem at the moment.
165+
func InitOnceWithSync(ctx context.Context) (err error) {
166+
initOnce.Do(func() {
167+
err = InitSimple(ctx)
168+
if err != nil {
169+
return
170+
}
183171

184-
if err = os.MkdirAll(setting.RepoRootPath, os.ModePerm); err != nil {
185-
return fmt.Errorf("unable to create directory %s, err: %w", setting.RepoRootPath, err)
186-
}
172+
// Since git wire protocol has been released from git v2.18
173+
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
174+
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
175+
}
176+
177+
// By default partial clones are disabled, enable them from git v2.22
178+
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
179+
globalCommandArgs = append(globalCommandArgs, "-c", "uploadpack.allowfilter=true", "-c", "uploadpack.allowAnySHA1InWant=true")
180+
}
187181

188-
if CheckGitVersionAtLeast("2.9") == nil {
189182
// Explicitly disable credential helper, otherwise Git credentials might leak
190-
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
191-
}
183+
if CheckGitVersionAtLeast("2.9") == nil {
184+
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
185+
}
192186

193-
// Since git wire protocol has been released from git v2.18
194-
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
195-
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
187+
SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
188+
})
189+
if err != nil {
190+
return err
196191
}
192+
return syncGitConfig()
193+
}
197194

198-
// By default partial clones are disabled, enable them from git v2.22
199-
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
200-
globalCommandArgs = append(globalCommandArgs, "-c", "uploadpack.allowfilter=true", "-c", "uploadpack.allowAnySHA1InWant=true")
195+
// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem)
196+
func syncGitConfig() (err error) {
197+
if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil {
198+
return fmt.Errorf("unable to create directory %s, err: %w", setting.RepoRootPath, err)
201199
}
202200

203201
// Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults"
@@ -232,17 +230,15 @@ func InitWithConfigSync(ctx context.Context) error {
232230
}
233231
}
234232

235-
if CheckGitVersionAtLeast("2.29") == nil {
233+
if SupportProcReceive {
236234
// set support for AGit flow
237235
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
238236
return err
239237
}
240-
SupportProcReceive = true
241238
} else {
242239
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
243240
return err
244241
}
245-
SupportProcReceive = false
246242
}
247243

248244
if runtime.GOOS == "windows" {

modules/git/git_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func testRun(m *testing.M) error {
2828
defer util.RemoveAll(repoRootPath)
2929
setting.RepoRootPath = repoRootPath
3030

31-
if err = InitWithConfigSync(context.Background()); err != nil {
31+
if err = InitOnceWithSync(context.Background()); err != nil {
3232
return fmt.Errorf("failed to call Init: %w", err)
3333
}
3434

modules/highlight/highlight.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ func File(numLines int, fileName, language string, code []byte) []string {
203203
content = "\n"
204204
} else if content == `</span><span class="w">` {
205205
content += "\n</span>"
206+
} else if content == `</span></span><span class="line"><span class="cl">` {
207+
content += "\n"
206208
}
207209
content = strings.TrimSuffix(content, `<span class="w">`)
208210
content = strings.TrimPrefix(content, `</span>`)

0 commit comments

Comments
 (0)