mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-30 04:22:54 +09: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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user