Skip to content

Commit 08b46ed

Browse files
committed
refactor: drop context from method name
1 parent e4be255 commit 08b46ed

File tree

9 files changed

+18
-29
lines changed

9 files changed

+18
-29
lines changed

modules/git/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath
135135
ignoreRevsFile = tryCreateBlameIgnoreRevsFile(commit)
136136
}
137137

138-
cmd := NewCommandContextNoGlobals("blame", "--porcelain")
138+
cmd := NewCommandNoGlobals("blame", "--porcelain")
139139
if ignoreRevsFile != nil {
140140
// Possible improvement: use --ignore-revs-file /dev/stdin on unix
141141
// There is no equivalent on Windows. May be implemented if Gitea uses an external git backend.

modules/git/command.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ const DefaultLocale = "C"
4242

4343
// Command represents a command with its subcommands or arguments.
4444
type Command struct {
45-
prog string
46-
args []string
47-
// parentContext context.Context
45+
prog string
46+
args []string
4847
globalArgsLength int
4948
brokenArgs []string
5049
}
@@ -92,33 +91,25 @@ func NewCommand(args ...internal.CmdArg) *Command {
9291
cargs = append(cargs, string(arg))
9392
}
9493
return &Command{
95-
prog: GitExecutable,
96-
args: cargs,
97-
// parentContext: ctx,
94+
prog: GitExecutable,
95+
args: cargs,
9896
globalArgsLength: len(globalCommandArgs),
9997
}
10098
}
10199

102-
// NewCommandContextNoGlobals creates and returns a new Git Command based on given command and arguments only with the specify args and don't care global command args
100+
// NewCommandNoGlobals creates and returns a new Git Command based on given command and arguments only with the specified args and don't use global command args
103101
// Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
104-
func NewCommandContextNoGlobals(args ...internal.CmdArg) *Command {
102+
func NewCommandNoGlobals(args ...internal.CmdArg) *Command {
105103
cargs := make([]string, 0, len(args))
106104
for _, arg := range args {
107105
cargs = append(cargs, string(arg))
108106
}
109107
return &Command{
110108
prog: GitExecutable,
111109
args: cargs,
112-
// parentContext: ctx,
113110
}
114111
}
115112

116-
// // SetParentContext sets the parent context for this command
117-
// func (c *Command) SetParentContext(ctx context.Context) *Command {
118-
// c.parentContext = ctx
119-
// return c
120-
// }
121-
122113
// isSafeArgumentValue checks if the argument is safe to be used as a value (not an option)
123114
func isSafeArgumentValue(s string) bool {
124115
return s == "" || s[0] != '-'

modules/git/command_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestRunWithContextStd(t *testing.T) {
1313
cmd := NewCommand("--version")
14-
stdout, stderr, err := cmd.RunStdString(t/Context(), &RunOpts{})
14+
stdout, stderr, err := cmd.RunStdString(t.Context(), &RunOpts{})
1515
assert.NoError(t, err)
1616
assert.Empty(t, stderr)
1717
assert.Contains(t, stdout, "git version")
@@ -53,9 +53,9 @@ func TestGitArgument(t *testing.T) {
5353
}
5454

5555
func TestCommandString(t *testing.T) {
56-
cmd := NewCommandContextNoGlobals("a", "-m msg", "it's a test", `say "hello"`)
56+
cmd := NewCommandNoGlobals("a", "-m msg", "it's a test", `say "hello"`)
5757
assert.EqualValues(t, cmd.prog+` a "-m msg" "it's a test" "say \"hello\""`, cmd.LogString())
5858

59-
cmd = NewCommandContextNoGlobals("url: https://a:b@c/", "/root/dir-a/dir-b")
59+
cmd = NewCommandNoGlobals("url: https://a:b@c/", "/root/dir-a/dir-b")
6060
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/" .../dir-a/dir-b`, cmd.LogString())
6161
}

modules/git/commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func AddChanges(repoPath string, all bool, files ...string) error {
9191

9292
// AddChangesWithArgs marks local changes to be ready for commit.
9393
func AddChangesWithArgs(repoPath string, globalArgs TrustedCmdArgs, all bool, files ...string) error {
94-
cmd := NewCommandContextNoGlobals(globalArgs...).AddArguments("add")
94+
cmd := NewCommandNoGlobals(globalArgs...).AddArguments("add")
9595
if all {
9696
cmd.AddArguments("--all")
9797
}
@@ -118,7 +118,7 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error {
118118
// CommitChangesWithArgs commits local changes with given committer, author and message.
119119
// If author is nil, it will be the same as committer.
120120
func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChangesOptions) error {
121-
cmd := NewCommandContextNoGlobals(args...)
121+
cmd := NewCommandNoGlobals(args...)
122122
if opts.Committer != nil {
123123
cmd.AddOptionValues("-c", "user.name="+opts.Committer.Name)
124124
cmd.AddOptionValues("-c", "user.email="+opts.Committer.Email)

modules/git/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, op
129129
return err
130130
}
131131

132-
cmd := NewCommandContextNoGlobals(args...).AddArguments("clone")
132+
cmd := NewCommandNoGlobals(args...).AddArguments("clone")
133133
if opts.SkipTLSVerify {
134134
cmd.AddArguments("-c", "http.sslVerify=false")
135135
}

modules/git/repo_commit_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
5959
}
6060
}
6161

62-
actualCommitID, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify").AddDynamicArguments(commitID).RunStdString(&RunOpts{Dir: repo.Path})
62+
actualCommitID, _, err := NewCommand("rev-parse", "--verify").AddDynamicArguments(commitID).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
6363
actualCommitID = strings.TrimSpace(actualCommitID)
6464
if err != nil {
6565
if strings.Contains(err.Error(), "unknown revision or path") ||

modules/git/repo_tree_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
3636
}
3737

3838
if len(idStr) != objectFormat.FullLength() {
39-
res, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify").AddDynamicArguments(idStr).RunStdString(&RunOpts{Dir: repo.Path})
39+
res, _, err := NewCommand("rev-parse", "--verify").AddDynamicArguments(idStr).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
4040
if err != nil {
4141
return nil, err
4242
}

routers/web/repo/issue_list.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
749749
}
750750

751751
// Issues render issues page
752-
func Issues(_ http.ResponseWriter, request *http.Request) {
753-
ctx := context.GetWebContext(request)
754-
log.Info("Hi from less weird handler!")
752+
func Issues(ctx *context.Context) {
755753
isPullList := ctx.PathParam("type") == "pulls"
756754
if isPullList {
757755
MustAllowPulls(ctx)

tests/integration/git_helper_for_declarative_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
187187

188188
func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
189189
return func(t *testing.T) {
190-
_, _, err := git.NewCommandContextNoGlobals(git.AllowLFSFiltersArgs()...).AddArguments("checkout").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(git.DefaultContext, &git.RunOpts{Dir: dstPath})
190+
_, _, err := git.NewCommandNoGlobals(git.AllowLFSFiltersArgs()...).AddArguments("checkout").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(git.DefaultContext, &git.RunOpts{Dir: dstPath})
191191
assert.NoError(t, err)
192192
}
193193
}
@@ -201,7 +201,7 @@ func doGitMerge(dstPath string, args ...string) func(*testing.T) {
201201

202202
func doGitPull(dstPath string, args ...string) func(*testing.T) {
203203
return func(t *testing.T) {
204-
_, _, err := git.NewCommandContextNoGlobals(git.AllowLFSFiltersArgs()...).AddArguments("pull").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(git.DefaultContext, &git.RunOpts{Dir: dstPath})
204+
_, _, err := git.NewCommandNoGlobals(git.AllowLFSFiltersArgs()...).AddArguments("pull").AddArguments(git.ToTrustedCmdArgs(args)...).RunStdString(git.DefaultContext, &git.RunOpts{Dir: dstPath})
205205
assert.NoError(t, err)
206206
}
207207
}

0 commit comments

Comments
 (0)