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

Replace RunInDir with RunWithContext #18978

Closed

Conversation

martinscholz83
Copy link
Contributor

Replace RunInDir with RunWIthContext.

#18553

@6543 6543 added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Mar 2, 2022
@6543 6543 added this to the 1.17.0 milestone Mar 2, 2022
@6543
Copy link
Member

6543 commented Mar 2, 2022

@martinscholz83 please run make fmt and commit the changes

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 2, 2022
models/migrations/v134.go Outdated Show resolved Hide resolved
modules/doctor/mergebase.go Outdated Show resolved Hide resolved
modules/git/commit.go Outdated Show resolved Hide resolved
modules/git/commit.go Outdated Show resolved Hide resolved
modules/git/remote.go Outdated Show resolved Hide resolved
modules/git/repo.go Outdated Show resolved Hide resolved
modules/git/repo.go Outdated Show resolved Hide resolved
modules/git/repo_blame.go Outdated Show resolved Hide resolved
modules/git/repo_commit.go Outdated Show resolved Hide resolved
modules/git/repo_index.go Outdated Show resolved Hide resolved
@lunny
Copy link
Member

lunny commented Mar 3, 2022

I think strings.Builder should have better performance than bytes.Buffer. Otherwise L-G-T-M .

@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 3, 2022
@martinscholz83
Copy link
Contributor Author

That repo_tree_gogit.go build failure I can ignore?

@lunny
Copy link
Member

lunny commented Mar 3, 2022

That repo_tree_gogit.go build failure I can ignore?

I don't think so.

@martinscholz83
Copy link
Contributor Author

I don't understand why it fails for arm64.

@martinscholz83
Copy link
Contributor Author

One more thing for my understanding. I found a lot places like this where still the ctx error is logged instead of the output from stderr. So my question, do these places also need to be changed to log stderr instead of err?

@6543
Copy link
Member

6543 commented Mar 23, 2022

@martinscholz83 a general roule: if err is just needed to check if it fails we dont need the stderr, if it is used in logs etc .. stderr is needed

and I agree to add a wrapper called RunWithContextString that return (stdout, stderr, err) - that way we dont need mouch boilerplate (this func should fail if Context set stdout and stderr, as it will init it's own)

I'll have a look at this pull soon^TM

@zeripath
Copy link
Contributor

Hmm... although this fails in different places each time I think it's been consistently failing too many times and we need to double check that there isn't a real issue here.

@wxiaoguang wxiaoguang force-pushed the feature/RunInPipline branch 6 times, most recently from 404785a to a6760a7 Compare March 28, 2022 10:54
@wxiaoguang

This comment was marked as outdated.

@wxiaoguang wxiaoguang added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Mar 28, 2022
modules/git/command.go Outdated Show resolved Hide resolved
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 28, 2022

This PR does wrong from begnning ..... replacing RunInDir by RunWithContext is incorrect, because the error returned by RunInDir contains stderr, while RunWithContext doesn't. Such replacing causes many error checks doesn't work correctly.

If there is a chance, the refactoring should use RunWithContextString to replace RunInDir.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 28, 2022

I reset the branch to the original one (cleaned my changes).

I think we need to make some decisions about how to continue ......

Comment on lines -260 to -262
// RunInDir executes the command in given directory
// and returns stdout in string and error (combined with stderr).
func (c *Command) RunInDir(dir string) (string, error) {
Copy link
Contributor

@wxiaoguang wxiaoguang Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point is here, it returns "stdout in string and error (combined with stderr)"

So the RunInXxx can not be replaced by RunWithContext directly

@wxiaoguang
Copy link
Contributor

Hi @martinscholz83 , thank you for your contribution and give us the hint about the refactoring. Now we can close #18553 and we have a clear git command module in Gitea! 🎉

Although this PR is not merged, it really help us to know how to continue about the refactoring. Appreciate your work.

Now we can safely close this PR.

@wxiaoguang wxiaoguang closed this Apr 1, 2022
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
@wxiaoguang wxiaoguang removed this from the 1.17.0 milestone Jun 12, 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. status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR 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.

7 participants