Message ID | cover.1683721293.git.ps@pks.im (mailing list archive) |
---|---|
Headers | show |
Series | fetch: introduce machine-parseable output | expand |
Patrick Steinhardt <ps@pks.im> writes: > - Patch 3/9: Added a test to verify that `git fetch -c fetch.output` > without a value set fails as expected. Also dropped the tests that > checked whether stdout was empty. Thank you for the attention to this small detail of valueless configuration variable definition. > - Patch 4/9: Reformulated the commit message to treat the missing > left-hand side of displayed references as an inconsistency instead > of a bug. I've also added a testcase to verify that direct OID > fetches continue to work as expected. Again, the direct OID fetch is a good thing to test here. I noticed that the test added here insists that the standard output stream is empty when the command errors out, which is not consistent with [3/9] above. > - Patch 5/9: New patch that makes calculation of the table width for > displayed reference updates self-contained in `refcol_width()`. > This is a preparatory refactoring that should make patch 6/9 > easier to review. It is an excellent idea to avoid calls to refcol_width() for each ref that gets shown and make the helper responsible for computing the required maxwidth. The result indeed has become easier to follow as you mentioned in your response to my review on the previous round. > - Patch 7/9: Refactored the code to parse the "fetch.output" config > variable inside of `git_fetch_config()` before we parse command > line options. Also fixed that the commit message was still > referring to `--output-format=porcelain` instead of the new > `--porcelain` switch. As a standalone step, it leaves an impression that the step makes the way we handle the output-format configuration variable inconsistent with the way we handle the other configuration variables, but I think it is a good place to stop for the purpose of this topic. It lays a good foundation for future clean-up after the dust settles from this topic---we may want to move global variables assigned in the git_fetch_config() into the fetch_config structure. > - Patch 9/9: The `--porcelain` option is now a simple `OPT_BOOL()` > that can be negated. Added a test that `--no-porcelain` works as > expected. OK, this time the familiar "prepare a variable to its default, let config callback to overwrite it by reading configuration variables, and then let the command line option override it" is used and the result easy to follow. I do not think .display_format is never assigned DISPLAY_FORMAT_UNKNOWN with this change, so [6/9] could lose the value from the enum, I think. The defensive switch statement that has BUG() to notice an erroneous caller that pass values other than DISPLAY_FORMAT_{FULL,COMPACT} is still a good idea. Looking good. Thanks.
On Wed, May 10, 2023 at 11:05:19AM -0700, Junio C Hamano wrote: > Patrick Steinhardt <ps@pks.im> writes: [snip] > > - Patch 4/9: Reformulated the commit message to treat the missing > > left-hand side of displayed references as an inconsistency instead > > of a bug. I've also added a testcase to verify that direct OID > > fetches continue to work as expected. > > Again, the direct OID fetch is a good thing to test here. I noticed > that the test added here insists that the standard output stream is > empty when the command errors out, which is not consistent with [3/9] > above. I think you misread the test: yes, we do test stdout and stderr separately and in many cases assert that stdout is in fact empty. But none of the added tests are about failing commands. So given that: - The added tests explicitly are about verifying the output format. - The distinction between stdout and stderr matters. - The distinction matters even more with the addition of `--porcelain`. I think that explicitly verifing both output streams is the correct thing to do. > > - Patch 9/9: The `--porcelain` option is now a simple `OPT_BOOL()` > > that can be negated. Added a test that `--no-porcelain` works as > > expected. > > OK, this time the familiar "prepare a variable to its default, let > config callback to overwrite it by reading configuration variables, > and then let the command line option override it" is used and the > result easy to follow. I do not think .display_format is never > assigned DISPLAY_FORMAT_UNKNOWN with this change, so [6/9] could > lose the value from the enum, I think. The defensive switch > statement that has BUG() to notice an erroneous caller that pass > values other than DISPLAY_FORMAT_{FULL,COMPACT} is still a good > idea. Ah, right, `DISPLAY_FORMAT_UNKNOWN` isn't really needed anymore. I think it's still good to have valid values of the enum start with `1` so that it becomes easier to detect cases where we accidentally use a default initialized variable. But that can be achieved without giving the default value an explicit name. I'll refrain from sending a new version just to remove this constant as it doesn't really feel worth it, though. But please, let me know in case you disagree and I'll send an updated version. Thanks Patrick
Patrick Steinhardt <ps@pks.im> writes: > On Wed, May 10, 2023 at 11:05:19AM -0700, Junio C Hamano wrote: >> Patrick Steinhardt <ps@pks.im> writes: > [snip] >> > - Patch 4/9: Reformulated the commit message to treat the missing >> > left-hand side of displayed references as an inconsistency instead >> > of a bug. I've also added a testcase to verify that direct OID >> > fetches continue to work as expected. >> >> Again, the direct OID fetch is a good thing to test here. I noticed >> that the test added here insists that the standard output stream is >> empty when the command errors out, which is not consistent with [3/9] >> above. > > I think you misread the test: yes, we do test stdout and stderr > separately and in many cases assert that stdout is in fact empty. But > none of the added tests are about failing commands. Ah, you are absolutely right. Sorry for the noise---I do not have an objection to ensure that program output in the successful case is predictable. My main concern is to avoid giving unneeded assurance in the failing case. >> assigned DISPLAY_FORMAT_UNKNOWN with this change, so [6/9] could >> lose the value from the enum, I think. The defensive switch >> statement that has BUG() to notice an erroneous caller that pass >> values other than DISPLAY_FORMAT_{FULL,COMPACT} is still a good >> idea. > > Ah, right, `DISPLAY_FORMAT_UNKNOWN` isn't really needed anymore. I think > it's still good to have valid values of the enum start with `1` so that > it becomes easier to detect cases where we accidentally use a default > initialized variable. But that can be achieved without giving the > default value an explicit name. Unless we explicitly take advantage of UNKNOWN being 0 and perform clever defaulting, the result is far safer if you get rid of it, and instead give 0 to a real choice that is used as the default, for two reasons: (1) naturally 0 initialization work fine, (2) we have one less enum constant people (or editor's auto-completer) assign to a variable by mistake instead of a real one they intended to. I agree with the last sentence of your paragraph above.
Patrick Steinhardt wrote: > On Wed, May 10, 2023 at 11:05:19AM -0700, Junio C Hamano wrote: > > OK, this time the familiar "prepare a variable to its default, let > > config callback to overwrite it by reading configuration variables, > > and then let the command line option override it" is used and the > > result easy to follow. I do not think .display_format is never > > assigned DISPLAY_FORMAT_UNKNOWN with this change, so [6/9] could > > lose the value from the enum, I think. The defensive switch > > statement that has BUG() to notice an erroneous caller that pass > > values other than DISPLAY_FORMAT_{FULL,COMPACT} is still a good > > idea. > > Ah, right, `DISPLAY_FORMAT_UNKNOWN` isn't really needed anymore. I think > it's still good to have valid values of the enum start with `1` so that > it becomes easier to detect cases where we accidentally use a default > initialized variable. But that can be achieved without giving the > default value an explicit name. I think it's standard to have an element like that. It could be UNKNOWN, NULL, INVALID, or even DEFAULT. For example, you could have code like this: if (format == DISPLAY_FORMAT_DEFAULT) format = DISPLAY_FORMAT_FULL; This would distinguish cases in which the user did not specify a display format and we choose a default, from those where the user explicitely chose the format that happens to be the default.
Patrick Steinhardt <ps@pks.im> writes: > Changes compared to v4: > > - Patch 1/9: Simplified the test as proposed by Junio and Glen. > > - Patch 3/9: Added a test to verify that `git fetch -c fetch.output` > without a value set fails as expected. Also dropped the tests that > checked whether stdout was empty. > > - Patch 4/9: Reformulated the commit message to treat the missing > left-hand side of displayed references as an inconsistency instead > of a bug. I've also added a testcase to verify that direct OID > fetches continue to work as expected. > > - Patch 5/9: New patch that makes calculation of the table width for > displayed reference updates self-contained in `refcol_width()`. > This is a preparatory refactoring that should make patch 6/9 > easier to review. > > - Patch 7/9: Refactored the code to parse the "fetch.output" config > variable inside of `git_fetch_config()` before we parse command > line options. Also fixed that the commit message was still > referring to `--output-format=porcelain` instead of the new > `--porcelain` switch. > > - Patch 9/9: The `--porcelain` option is now a simple `OPT_BOOL()` > that can be negated. Added a test that `--no-porcelain` works as > expected. I didn't spot any blocking issues in this version, and the various improvements (especially 6-7/9) are really welcome. I also read through Junio's comments, but I didn't spot anything that I thought should block the series, so I'm happy to leave Reviewed-by: Glen Choo <chooglen@google.com>
On Thu, May 11, 2023 at 06:09:03PM -0700, Glen Choo wrote: > Patrick Steinhardt <ps@pks.im> writes: > > > Changes compared to v4: > > > > - Patch 1/9: Simplified the test as proposed by Junio and Glen. > > > > - Patch 3/9: Added a test to verify that `git fetch -c fetch.output` > > without a value set fails as expected. Also dropped the tests that > > checked whether stdout was empty. > > > > - Patch 4/9: Reformulated the commit message to treat the missing > > left-hand side of displayed references as an inconsistency instead > > of a bug. I've also added a testcase to verify that direct OID > > fetches continue to work as expected. > > > > - Patch 5/9: New patch that makes calculation of the table width for > > displayed reference updates self-contained in `refcol_width()`. > > This is a preparatory refactoring that should make patch 6/9 > > easier to review. > > > > - Patch 7/9: Refactored the code to parse the "fetch.output" config > > variable inside of `git_fetch_config()` before we parse command > > line options. Also fixed that the commit message was still > > referring to `--output-format=porcelain` instead of the new > > `--porcelain` switch. > > > > - Patch 9/9: The `--porcelain` option is now a simple `OPT_BOOL()` > > that can be negated. Added a test that `--no-porcelain` works as > > expected. > > I didn't spot any blocking issues in this version, and the various > improvements (especially 6-7/9) are really welcome. I also read through > Junio's comments, but I didn't spot anything that I thought should block > the series, so I'm happy to leave > > Reviewed-by: Glen Choo <chooglen@google.com> Thanks a lot for your reviews! Patrick