mirror of
https://github.com/go-gitea/gitea
synced 2025-09-10 10:48:28 +00:00
Fix context usages (#35348)
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package attribute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -22,7 +21,7 @@ func testRun(m *testing.M) error {
|
||||
defer util.RemoveAll(gitHomePath)
|
||||
setting.Git.HomePath = gitHomePath
|
||||
|
||||
if err = git.InitFull(context.Background()); err != nil {
|
||||
if err = git.InitFull(); err != nil {
|
||||
return fmt.Errorf("failed to call Init: %w", err)
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ func DefaultFeatures() *Features {
|
||||
if !setting.IsProd || setting.IsInTesting {
|
||||
log.Warn("git.DefaultFeatures is called before git.InitXxx, initializing with default values")
|
||||
}
|
||||
if err := InitSimple(context.Background()); err != nil {
|
||||
if err := InitSimple(); err != nil {
|
||||
log.Fatal("git.InitSimple failed: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func HomeDir() string {
|
||||
|
||||
// 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 some Gitea sub-commands.
|
||||
func InitSimple(ctx context.Context) error {
|
||||
func InitSimple() error {
|
||||
if setting.Git.HomePath == "" {
|
||||
return errors.New("unable to init Git's HomeDir, incorrect initialization of the setting and git modules")
|
||||
}
|
||||
@@ -167,7 +167,8 @@ func InitSimple(ctx context.Context) error {
|
||||
log.Warn("git module has been initialized already, duplicate init may work but it's better to fix it")
|
||||
}
|
||||
|
||||
DefaultContext = ctx
|
||||
// FIXME: git context is used across the application, so it should use the global default context, this design is not right but it's hard to change now.
|
||||
DefaultContext = context.Background()
|
||||
globalCommandArgs = nil
|
||||
|
||||
if setting.Git.Timeout.Default > 0 {
|
||||
@@ -196,8 +197,8 @@ func InitSimple(ctx context.Context) error {
|
||||
|
||||
// InitFull initializes git module with version check and change global variables, sync gitconfig.
|
||||
// It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables.
|
||||
func InitFull(ctx context.Context) (err error) {
|
||||
if err = InitSimple(ctx); err != nil {
|
||||
func InitFull() (err error) {
|
||||
if err = InitSimple(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -25,7 +24,7 @@ func testRun(m *testing.M) error {
|
||||
|
||||
setting.Git.HomePath = gitHomePath
|
||||
|
||||
if err = InitFull(context.Background()); err != nil {
|
||||
if err = InitFull(); err != nil {
|
||||
return fmt.Errorf("failed to call Init: %w", err)
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package languagestats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -22,7 +21,7 @@ func testRun(m *testing.M) error {
|
||||
defer util.RemoveAll(gitHomePath)
|
||||
setting.Git.HomePath = gitHomePath
|
||||
|
||||
if err = git.InitFull(context.Background()); err != nil {
|
||||
if err = git.InitFull(); err != nil {
|
||||
return fmt.Errorf("failed to call Init: %w", err)
|
||||
}
|
||||
|
||||
|
@@ -47,12 +47,19 @@ var (
|
||||
|
||||
// GetManager returns the Manager
|
||||
func GetManager() *Manager {
|
||||
InitManager(context.Background())
|
||||
initManager(context.Background())
|
||||
return manager
|
||||
}
|
||||
|
||||
// InitManager creates the graceful manager in the provided context
|
||||
func InitManager(ctx context.Context) {
|
||||
if manager != nil {
|
||||
log.Error("graceful.InitManager called more than once")
|
||||
}
|
||||
initManager(ctx) // FIXME: this design is not right, it conflicts with the "Background" context used in GetManager
|
||||
}
|
||||
|
||||
func initManager(ctx context.Context) {
|
||||
initOnce.Do(func() {
|
||||
manager = newGracefulManager(ctx)
|
||||
|
||||
|
@@ -19,7 +19,7 @@ type RequestContextKeyStruct struct{}
|
||||
var RequestContextKey = RequestContextKeyStruct{}
|
||||
|
||||
func urlIsRelative(s string, u *url.URL) bool {
|
||||
// Unfortunately browsers consider a redirect Location with preceding "//", "\\", "/\" and "\/" as meaning redirect to "http(s)://REST_OF_PATH"
|
||||
// Unfortunately, browsers consider a redirect Location with preceding "//", "\\", "/\" and "\/" as meaning redirect to "http(s)://REST_OF_PATH"
|
||||
// Therefore we should ignore these redirect locations to prevent open redirects
|
||||
if len(s) > 1 && (s[0] == '/' || s[0] == '\\') && (s[1] == '/' || s[1] == '\\') {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user