Skip to content

Commit

Permalink
Merge branch 'main' into fix-git-legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jun 11, 2022
2 parents e8fad37 + 88f2e45 commit 9f89b2f
Show file tree
Hide file tree
Showing 61 changed files with 416 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ steps:
depends_on: [test-frontend]

- name: build-backend-no-gcc
image: golang:1.17 # this step is kept as the lowest version of golang that we support
image: golang:1.18 # this step is kept as the lowest version of golang that we support
pull: always
environment:
GO111MODULE: on
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ fomantic:
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
$(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*

.PHONY: webpack
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ or if SQLite support is required:

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

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

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.
Expand Down
2 changes: 1 addition & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ params:
author: The Gitea Authors
website: https://docs.gitea.io
version: 1.16.8
minGoVersion: 1.17
minGoVersion: 1.18
goVersion: 1.18
minNodeVersion: 14

Expand Down
4 changes: 2 additions & 2 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `SSL_MAX_VERSION`: **\<empty\>**: Set the maximum version of ssl support.
- `SSL_CURVE_PREFERENCES`: **X25519,P256**: Set the preferred curves,
- `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.
- If there is not hardware support for AES suites by default the cha cha suites will be preferred over the AES suites
- supported suites as of go 1.17 are:
- If there is no hardware support for AES suites, by default the ChaCha suites will be preferred over the AES suites.
- supported suites as of Go 1.18 are:
- TLS 1.0 - 1.2 cipher suites
- "rsa_with_rc4_128_sha"
- "rsa_with_3des_ede_cbc_sha"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module code.gitea.io/gitea

go 1.17
go 1.18

require (
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
Expand Down
4 changes: 2 additions & 2 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
assert.NoError(t, unittest.LoadFixtures())
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
assert.NoError(t, git.InitWithConfigSync(context.Background()))
assert.NoError(t, git.InitOnceWithSync(context.Background()))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
Expand Down Expand Up @@ -576,7 +576,7 @@ func resetFixtures(t *testing.T) {
assert.NoError(t, unittest.LoadFixtures())
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
assert.NoError(t, git.InitWithConfigSync(context.Background()))
assert.NoError(t, git.InitOnceWithSync(context.Background()))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion integrations/migration-test/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func initMigrationTest(t *testing.T) func() {
assert.True(t, len(setting.RepoRootPath) != 0)
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
assert.NoError(t, git.InitWithConfigSync(context.Background()))
assert.NoError(t, git.InitOnceWithSync(context.Background()))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func prepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.En
deferFn := PrintCurrentTest(t, ourSkip)
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
assert.NoError(t, git.InitWithConfigSync(context.Background()))
assert.NoError(t, git.InitOnceWithSync(context.Background()))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
if err != nil {
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
Expand Down
3 changes: 3 additions & 0 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ func (repo *Repository) ComposeMetas() map[string]string {
switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
case markup.IssueNameStyleAlphanumeric:
metas["style"] = markup.IssueNameStyleAlphanumeric
case markup.IssueNameStyleRegexp:
metas["style"] = markup.IssueNameStyleRegexp
metas["regexp"] = unit.ExternalTrackerConfig().ExternalTrackerRegexpPattern
default:
metas["style"] = markup.IssueNameStyleNumeric
}
Expand Down
7 changes: 4 additions & 3 deletions models/repo/repo_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {

// ExternalTrackerConfig describes external tracker config
type ExternalTrackerConfig struct {
ExternalTrackerURL string
ExternalTrackerFormat string
ExternalTrackerStyle string
ExternalTrackerURL string
ExternalTrackerFormat string
ExternalTrackerStyle string
ExternalTrackerRegexpPattern string
}

// FromDB fills up a ExternalTrackerConfig from serialized format.
Expand Down
3 changes: 3 additions & 0 deletions models/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func TestMetas(t *testing.T) {
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
testSuccess(markup.IssueNameStyleNumeric)

externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
testSuccess(markup.IssueNameStyleRegexp)

repo, err := repo_model.GetRepositoryByID(3)
assert.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions models/unittest/testdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
fatalTestError("util.CopyDir: %v\n", err)
}
if err = git.InitWithConfigSync(context.Background()); err != nil {
if err = git.InitOnceWithSync(context.Background()); err != nil {
fatalTestError("git.Init: %v\n", err)
}

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

ownerDirs, err := os.ReadDir(setting.RepoRootPath)
assert.NoError(t, err)
Expand Down
78 changes: 37 additions & 41 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ var (
GitExecutable = "git"

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

// SupportProcReceive version >= 2.29.0
SupportProcReceive bool

// initMutex is used to avoid Golang's data race error. see the comments below.
initMutex sync.Mutex

gitVersion *version.Version
)

Expand Down Expand Up @@ -128,15 +125,6 @@ func VersionInfo() string {
return fmt.Sprintf(format, args...)
}

// InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
// This method doesn't change anything to filesystem
func InitSimple(ctx context.Context) error {
initMutex.Lock()
defer initMutex.Unlock()

return initSimpleInternal(ctx)
}

// HomeDir is the home dir for git to store the global config file used by Gitea internally
func HomeDir() string {
if setting.RepoRootPath == "" {
Expand All @@ -150,11 +138,9 @@ func HomeDir() string {
return setting.RepoRootPath
}

func initSimpleInternal(ctx context.Context) error {
// at the moment, when running integration tests, the git.InitXxx would be called twice.
// one is called by the GlobalInitInstalled, one is called by TestMain.
// so the init functions should be protected by a mutex to avoid Golang's data race error.

// InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
// This method doesn't change anything to filesystem. At the moment, it is only used by "git serv" sub-command, no data-race
func InitSimple(ctx context.Context) error {
DefaultContext = ctx

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

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

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

if err = os.MkdirAll(setting.RepoRootPath, os.ModePerm); err != nil {
return fmt.Errorf("unable to create directory %s, err: %w", setting.RepoRootPath, err)
}
// Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
}

// By default partial clones are disabled, enable them from git v2.22
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
globalCommandArgs = append(globalCommandArgs, "-c", "uploadpack.allowfilter=true", "-c", "uploadpack.allowAnySHA1InWant=true")
}

if CheckGitVersionAtLeast("2.9") == nil {
// Explicitly disable credential helper, otherwise Git credentials might leak
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
}
if CheckGitVersionAtLeast("2.9") == nil {
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
}

// Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
})
if err != nil {
return err
}
return syncGitConfig()
}

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

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

if CheckGitVersionAtLeast("2.29") == nil {
if SupportProcReceive {
// set support for AGit flow
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
return err
}
SupportProcReceive = true
} else {
if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil {
return err
}
SupportProcReceive = false
}

if runtime.GOOS == "windows" {
Expand Down
2 changes: 1 addition & 1 deletion modules/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func testRun(m *testing.M) error {
defer util.RemoveAll(repoRootPath)
setting.RepoRootPath = repoRootPath

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

Expand Down
2 changes: 2 additions & 0 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func File(numLines int, fileName, language string, code []byte) []string {
content = "\n"
} else if content == `</span><span class="w">` {
content += "\n</span>"
} else if content == `</span></span><span class="line"><span class="cl">` {
content += "\n"
}
content = strings.TrimSuffix(content, `<span class="w">`)
content = strings.TrimPrefix(content, `</span>`)
Expand Down
Loading

0 comments on commit 9f89b2f

Please sign in to comment.