Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove git.Command.Run and git.Command.RunInDir* #19280

Merged
merged 9 commits into from
Apr 1, 2022

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Mar 31, 2022

Follows

Close #18553

Now, only RunWithContext related functions.

This PR is a simple search & replace:

  • before: stdout, err := RunInDir(path)
  • now: stdout, _, err := RunStdString(&git.RunOpts{Dir:path})

@wxiaoguang wxiaoguang added type/refactoring Existing code has been cleaned up. There should be no new functionality. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Mar 31, 2022
@wxiaoguang wxiaoguang added this to the 1.17.0 milestone Mar 31, 2022
integrations/git_test.go Outdated Show resolved Hide resolved
integrations/git_test.go Outdated Show resolved Hide resolved
integrations/git_test.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 31, 2022
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 31, 2022
@lunny
Copy link
Member

lunny commented Mar 31, 2022

I think it's better to have some rename.

  • rename RunWithContext -> Run
  • rename RunWithContextString -> RunString
  • rename RunWithContextBytes -> RunBytes

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Mar 31, 2022

I think it's better to have some rename.

* rename `RunWithContext` -> `Run`

* rename `RunWithContextString` -> `RunString`

* rename `RunWithContextBytes` -> `RunBytes`

Do most people like to rename them now? And I think if we do so, we should also rename RunContext, it's not a context. What's the proper name?

RunContext is OK, or RunOptions is better.

@wxiaoguang
Copy link
Contributor Author

And the name Run is too short. I prefer to use RunCmd, RunStdString, RunStdBytes, and use CmdParams instead of RunContext

The longer names are friendly to be grep-ed out during refactoring.

@lunny
Copy link
Member

lunny commented Mar 31, 2022

And the name Run is too short. I prefer to use RunCmd, RunStdString, RunStdBytes, and use CmdParams instead of RunContext

The longer names are friendly to be grep-ed out during refactoring.

I don't think command.RunCmd is a good name.

@wxiaoguang
Copy link
Contributor Author

Hmmm, RunCmd is not good indeed. Do we have choices for a two-word name?

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Mar 31, 2022

I can not get a better name now. So how about:

  • cmd.Run(&git.CmdOpts{Dir: "..."})
  • cmd.RunStdString(&git.CmdOpts{Dir: "..."}) // std means it handles stdout/stderr
  • cmd.RunStdBytes(&git.CmdOpts{Dir: "..."})

If no objection, I will do it.

@lunny
Copy link
Member

lunny commented Mar 31, 2022

I can not get a better name now. So how about:

  • cmd.Run(&git.CmdOpts{Dir: "..."})
  • cmd.RunStdString(&git.CmdOpts{Dir: "..."}) // std means it handles stdout/stderr
  • cmd.RunStdBytes(&git.CmdOpts{Dir: "..."})

If no objection, I will do it.

I still think Std will not help for understanding the method meaning. And the options is for Run not for Command. Command have many Args methods. So CmdOpts is not better than RunOpts. In fact, I think move command to git/command sub package is better, so that RunOpts will be more clear than CmdOpts.

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Mar 31, 2022

I pushed a demo for:

  • cmd.Run(&git.RunOpts{Dir: "..."})
  • cmd.RunStdString(&git.RunOpts{Dir: "..."}) // std means it handles stdout/stderr
  • cmd.RunStdBytes(&git.RunOpts{Dir: "..."})

I think the Std is a must, because these two functions are totally different from Run, they handle stdout/stderr internally, and the returned error is totally different.

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Mar 31, 2022

@lunny a real example, when you read:

err := cmd.Run(...)
_, _, err := cmd.RunString(...)

// then
if strings.Contains(err.Error(), "fatal: ...") {
}

Do you know that these 2 errors are different? The second one contains stderr output, while the first one doesn't, if misused, there would be bugs.

So _, _, err := cmd.RunStdString(...) is more clear in such case.

And I have designed a new error RunStdError, so in future you can do:

_, _, runErr := cmd.RunStdString(...);
if runErr != nil && runErr.Stderr() == "fatal: ..." { ... }

Access the stderr directly, more handy and clear.

@6543
Copy link
Member

6543 commented Mar 31, 2022

I pushed a demo for:

* `cmd.Run(&git.RunOpts{Dir: "..."})`

* `cmd.RunStdString(&git.RunOpts{Dir: "..."})`   // std means it handles stdout/stderr

* `cmd.RunStdBytes(&git.RunOpts{Dir: "..."})`

I think the Std is a must, because these two functions are totally different from Run, they handle stdout/stderr internally, and the returned error is totally different.

Ack for rename ...

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 1, 2022
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@3a73645). Click here to learn what that means.
The diff coverage is 70.73%.

@@           Coverage Diff           @@
##             main   #19280   +/-   ##
=======================================
  Coverage        ?   47.40%           
=======================================
  Files           ?      939           
  Lines           ?   131080           
  Branches        ?        0           
=======================================
  Hits            ?    62134           
  Misses          ?    61471           
  Partials        ?     7475           
Impacted Files Coverage Δ
cmd/hook.go 7.11% <0.00%> (ø)
modules/doctor/mergebase.go 10.25% <0.00%> (ø)
modules/doctor/misc.go 21.55% <0.00%> (ø)
modules/git/pipeline/lfs_nogogit.go 0.00% <0.00%> (ø)
modules/git/pipeline/namerev.go 0.00% <0.00%> (ø)
modules/git/repo_commitgraph.go 50.00% <0.00%> (ø)
modules/indexer/code/elastic_search.go 1.12% <0.00%> (ø)
routers/private/hook_verification.go 0.00% <0.00%> (ø)
routers/web/repo/pull.go 30.84% <0.00%> (ø)
services/asymkey/sign.go 38.46% <0.00%> (ø)
... and 56 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a73645...82f75be. Read the comment docs.

@wxiaoguang wxiaoguang merged commit 124b072 into go-gitea:main Apr 1, 2022
@wxiaoguang wxiaoguang deleted the refactor-git-run branch April 1, 2022 02:55
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 1, 2022
* giteaoffical/main:
  Fix broken of team create (go-gitea#19288)
  Remove `git.Command.Run` and `git.Command.RunInDir*` (go-gitea#19280)
  Performance improvement for add team user when org has more than 1000 repositories (go-gitea#19227)
  [skip ci] Updated translations via Crowdin
  Update JS dependencies (go-gitea#19281)
  Fix container download counter (go-gitea#19287)
  go.mod: update kevinburke/ssh_config to v1.2.0 (go-gitea#19286)
  Fix global packages enabled avaiable (go-gitea#19276)
  Add Goroutine stack inspector to admin/monitor (go-gitea#19207)
  Move checks for pulls before merge into own function (go-gitea#19271)
  Restore user autoregistration with email addresses (go-gitea#19261)
  Improve sync performance for pull-mirrors (go-gitea#19125)
  Refactor `git.Command.Run*`, introduce `RunWithContextString` and `RunWithContextBytes` (go-gitea#19266)
  Move reaction to models/issues/ (go-gitea#19264)
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace all git.Command.RunInPipeline... with RunWithContext
5 participants