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

Cleanup handling of AllOutput for processes #10262

Merged

Conversation

gerhardol
Copy link
Member

Initiated from #10242
Some parts were initially in #10261 , separated to this PR

Proposed changes

AllOutput is combined use of stderr and stdout and should only be used to display messages for users.

  • Change a few commands to explicitly read stderr where required. Some tests had to be adapted (including MockExecutable).

  • Clarify usage that AllOutput is used for user popups. Most of these occurrences are related to FormCommit. The structure of these command was changed to return a bool for result and the output as a string, also if result/output were unused.

  • Set TODO on a few occurrences that were not investigated.

Test methodology

Tests updated

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned gerhardol Oct 15, 2022
Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

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

LGTM, though I haven't run this.

Comment on lines 1645 to 1651
/// <summary>
/// Set/unset assumeUnchanged
/// </summary>
/// <param name="files">Files to change</param>
/// <param name="assumeUnchanged">Set/unset assumeUnchanged</param>
/// <param name="alloutput">stdout and stderr output</param>
/// <returns>true if no errors occurred</returns>
Copy link
Member

Choose a reason for hiding this comment

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

The docs should be in sentence case and end with a full stop. We should also strive to use xml-doc tags, where appropriate.

Suggested change
/// <summary>
/// Set/unset assumeUnchanged
/// </summary>
/// <param name="files">Files to change</param>
/// <param name="assumeUnchanged">Set/unset assumeUnchanged</param>
/// <param name="alloutput">stdout and stderr output</param>
/// <returns>true if no errors occurred</returns>
/// <summary>
/// Set/unset whether given items are assumed unchanged.
/// </summary>
/// <param name="files">The files to set the status for.</param>
/// <param name="assumeUnchanged">The status value.</param>
/// <param name="allOutput">stdout and stderr output.</param>
/// <returns><see langword="true"/> if no errors occurred; otherwise, <see langword="false"/>.</returns>

Ditto below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.
(Not too happy with the xml-doc, the primary intention is to mark that AllOutput is deliberate, not being parsed.)

@RussKie
Copy link
Member

RussKie commented Oct 16, 2022

I presume we'd want this in v4, right?

Copy link
Contributor

@vbjay vbjay left a comment

Choose a reason for hiding this comment

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

Not blocking comments but things I noticed.

@@ -232,13 +232,13 @@ public string GetCommitVerificationMessage(GitRevision revision)
return null;
}

var module = GetModule();
// '--raw' returns info in stderr
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather it say verify-tag. It's not just raw that uses the error stream.

Copy link
Member Author

Choose a reason for hiding this comment

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

'git verify-tag --raw' returns the info in stderr, but the command itself is redundant here.
--raw returning in stderr is just an unexpected behavior that I want to document, commands should normally only use stderr for displaying errors.

I moved the comment to the return that accesses stderr instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

#10261 (comment)

#10261 (comment)

My point is it doesn't matter if it is --raw or not.

Copy link
Contributor

@vbjay vbjay Oct 16, 2022

Choose a reason for hiding this comment

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

https://github.com/git/git/blob/d420dda0576340909c3faff364cfbd1485f70376/gpg-interface.c#L656-L666

See how they output to both streams? It is not an error if error stream has output. That is what the error code provides. I have seen a few programs do this where they output a your summary or details in standard output and verbose logging in error or a different result sent in error. As seen above they have the potential to output a different verify output if the flag is set in standard output. The error is the output we expect. I certainly see the issue of they should have done it the other way around.

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment is intended to describe why stderr is parsed instead of stdout.
In general commands should only use stderr to display error messages to the user. I tried to document why stderr was explicitly used with this commit.

Can you make a suggestion on how to describe this behavior?

Copy link
Contributor

@vbjay vbjay Oct 16, 2022

Choose a reason for hiding this comment

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

https://github.com/git/git/blob/d420dda0576340909c3faff364cfbd1485f70376/gpg-interface.c#L661-662

        if (flags & GPG_VERIFY_VERBOSE && sigc->payload)
                fwrite(sigc->payload, 1, sigc->payload_len, stdout);

Typically that is the case but it is not always the case. Looks like it outputs the raw payload to stdoutput if GPG_VERIFY_VERBOSE is set.

foreach (var file in nonNewFiles)
{
sb.Append($" \"{file.Name.ToPosixPath()}\"");
sb.Add($"\"{file.Name.ToPosixPath()}\"");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Quote or QuoteNe extension method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure removing the space still works as expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind. I get it. The add adds the space.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed to QuoteNE

@gerhardol
Copy link
Member Author

I presume we'd want this in v4, right?

This makes no functional change, it was a cleanup to ensure that there are no "unexpected" use of stderr as for git-verify-tag.
There are still possible use of stderr in GetOutput, but as throwOnErrorExit is not exposed, the usages throws an exception if Git fails.

But I find it safe to include.
We need to stop adding to 4.0 soon and release it...
But yet another beta.

Copy link
Contributor

@vbjay vbjay left a comment

Choose a reason for hiding this comment

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

GitCommands/Git/GitGpgController.cs Outdated Show resolved Hide resolved
@ghost ghost added 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity and removed 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity labels Oct 16, 2022
Copy link
Contributor

@vbjay vbjay left a comment

Choose a reason for hiding this comment

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

LGTM

@vbjay
Copy link
Contributor

vbjay commented Oct 16, 2022

I'll run and verify changes later on today for #10242

vbjay added a commit to vbjay/gitextensions that referenced this pull request Oct 16, 2022
@vbjay
Copy link
Contributor

vbjay commented Oct 16, 2022

gerhardol#5

vbjay added a commit to vbjay/gitextensions that referenced this pull request Oct 16, 2022
@gerhardol gerhardol added this to the 4.0.0 milestone Oct 16, 2022
@vbjay
Copy link
Contributor

vbjay commented Oct 16, 2022

So testing of this pull and the other together are confirmed that #10242 is resolved if both #10261 and #10262 are merged. See gerhardol#5 for how I tested.

AllOutput is combined use of stderr and stdout and should only
be used to display messages for users.

* Change a few commands to explicitly read stderr where required.
Some tests had to be adapted (including MockExecutable).

* Clarify usage that AllOutput is used for user popups.
Most of these occurrences are related to FormCommit.
The structure of these command was changed to return a bool for
result and the output as a string, also if result/output were unused.

* Set TODO on a few occurrences that were not investigated.

Co-authored-by: Jay Asbury <vbjay.net@gmail.com>
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -98,10 +98,10 @@ public IProcess Start(ArgumentString arguments, bool createWindow, bool redirect

private sealed class MockProcess : IProcess
{
public MockProcess([CanBeNull] string output, int? exitCode = 0)
public MockProcess([CanBeNull] string output, int? exitCode = 0, [CanBeNull] string error = null)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public MockProcess([CanBeNull] string output, int? exitCode = 0, [CanBeNull] string error = null)
public MockProcess(string? output, int? exitCode = 0, string? error = null)

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the JetBrains annotation. There are a few other uses remaining, mostly in test files

@gerhardol gerhardol force-pushed the feature/i10242-cleanup-stderr branch from 10b59aa to 9c4a355 Compare October 17, 2022 20:08
@gerhardol gerhardol merged commit 2e2d79f into gitextensions:master Oct 17, 2022
@gerhardol gerhardol deleted the feature/i10242-cleanup-stderr branch October 17, 2022 20:30
@ghost ghost modified the milestones: 4.0.0, vNext Oct 17, 2022
gerhardol added a commit that referenced this pull request Oct 17, 2022
AllOutput is combined use of stderr and stdout and should only
be used to display messages for users.

* Change a few commands to explicitly read stderr where required.
Some tests had to be adapted (including MockExecutable).

* Clarify usage that AllOutput is used for user popups.
Most of these occurrences are related to FormCommit.
The structure of these command was changed to return a bool for
result and the output as a string, also if result/output were unused.

* Set TODO on a few occurrences that were not investigated.

(cherry picked from commit 2e2d79f)
@gerhardol gerhardol modified the milestones: vNext, 4.0.0 Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants