git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v15 09/27] bisect--helper: `bisect_write` shell function in C

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Dec 6, 2016, 21:32 UTC
Message-ID
<CAFZEwPN_6HVWzdk46kKyU7vOzd1rhxzCo7JR45ucsVrhwDWEGw@mail.gmail.com>
In-Reply-To
<ceb2c50b-0ca7-115d-eb0e-316389569e36@gmx.net>
Hey Stephan,
On Thu, Nov 17, 2016 at 3:10 PM, Stephan Beyer <s-beyer@gmx.net> wrote:
Show 21 quoted lines
> Hi,
>
> I've only got some minors to mention here ;)
>
> On 10/14/2016 04:14 PM, Pranit Bauva wrote:
>> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
>> index c542e8b..3f19b68 100644
>> --- a/builtin/bisect--helper.c
>> +++ b/builtin/bisect--helper.c
>> @@ -19,9 +19,15 @@ static const char * const git_bisect_helper_usage[] = {
>>       N_("git bisect--helper --write-terms <bad_term> <good_term>"),
>>       N_("git bisect--helper --bisect-clean-state"),
>>       N_("git bisect--helper --bisect-reset [<commit>]"),
>> +     N_("git bisect--helper --bisect-write <state> <revision> <TERM_GOOD> <TERM_BAD> [<nolog>]"),
>>       NULL
>>  };
>
> I wouldn't write "<TERM_GOOD <TERM_BAD>" in capital letters. I'd use
> something like "<good_term> <bad_term>" as you have used for
> --write-terms. Note that "git bisect --help" uses "<term-old>
> <term-new>" in that context.
Keeping it in small does give less strain to the eye ;)
Show 39 quoted lines
>> @@ -149,6 +155,63 @@ static int check_expected_revs(const char **revs, int rev_nr)
>>       return 0;
>>  }
>>
>> +static int bisect_write(const char *state, const char *rev,
>> +                     const struct bisect_terms *terms, int nolog)
>> +{
>> +     struct strbuf tag = STRBUF_INIT;
>> +     struct strbuf commit_name = STRBUF_INIT;
>> +     struct object_id oid;
>> +     struct commit *commit;
>> +     struct pretty_print_context pp = {0};
>> +     FILE *fp = NULL;
>> +     int retval = 0;
>> +
>> +     if (!strcmp(state, terms->term_bad))
>> +             strbuf_addf(&tag, "refs/bisect/%s", state);
>> +     else if (one_of(state, terms->term_good, "skip", NULL))
>> +             strbuf_addf(&tag, "refs/bisect/%s-%s", state, rev);
>> +     else {
>> +             error(_("Bad bisect_write argument: %s"), state);
>> +             retval = -1;
>> +             goto finish;
>> +     }
>> +
>> +     if (get_oid(rev, &oid)) {
>> +             error(_("couldn't get the oid of the rev '%s'"), rev);
>> +             retval = -1;
>> +             goto finish;
>> +     }
>> +
>> +     if (update_ref(NULL, tag.buf, oid.hash, NULL, 0,
>> +                    UPDATE_REFS_MSG_ON_ERR)) {
>> +             retval = -1;
>> +             goto finish;
>> +     }
>
> I'd like to mention that the "goto fail;" trick could apply in this
> function, too.
Sure!
Show 15 quoted lines
>> @@ -156,9 +219,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
>>               WRITE_TERMS,
>>               BISECT_CLEAN_STATE,
>>               BISECT_RESET,
>> -             CHECK_EXPECTED_REVS
>> +             CHECK_EXPECTED_REVS,
>> +             BISECT_WRITE
>>       } cmdmode = 0;
>> -     int no_checkout = 0;
>> +     int no_checkout = 0, res = 0;
>
> Why do you do this "direct return" -> "set res and return res" transition?
> You don't need it in this patch, you do not need it in the subsequent
> patches (you always set "res" exactly once after the initialization),
> and you don't need cleanup code in this function.

Initially I was using strbuf but then I switched to const char * according to Junio's suggestion. It seems that in this version I have forgot to free the terms.

Show 13 quoted lines
>>       struct option options[] = {
>>               OPT_CMDMODE(0, "next-all", &cmdmode,
>>                        N_("perform 'git bisect next'"), NEXT_ALL),
>> @@ -170,10 +234,13 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
>>                        N_("reset the bisection state"), BISECT_RESET),
>>               OPT_CMDMODE(0, "check-expected-revs", &cmdmode,
>>                        N_("check for expected revs"), CHECK_EXPECTED_REVS),
>> +             OPT_CMDMODE(0, "bisect-write", &cmdmode,
>> +                      N_("write out the bisection state in BISECT_LOG"), BISECT_WRITE),
>
> That info text is confusing, especially considering that there is a
> "nolog" option. I think the action of bisect-write is two-fold: (1)
> update the refs, (2) log.

I agree that it is confusing. I couldn't find a better way to describe it and since this would be gone after the whole conversion, I didn't bother putting more efforts there.

Regards, Pranit Bauva

Previous: Stephan BeyerNext: Pranit Bauva
Message 23 of 82 in “bisect--helper: use OPT_CMDMODE instead of OPT_BOOL”
  1. 01/27 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, Oct 14, 2016
  2. 06/27 wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()Pranit Bauva, Oct 14, 2016
  3. 05/27 t6030: explicitly test for bisection cleanupPranit Bauva, Oct 14, 2016
  4. 22/27 bisect--helper: `bisect_log` shell function in CPranit Bauva, Oct 14, 2016
  5. Stephan BeyerNov 17, 2016
  6. Pranit BauvaDec 6, 2016
  7. 10/27 bisect--helper: `check_and_set_terms` shell function in CPranit Bauva, Oct 14, 2016
  8. Stephan BeyerNov 17, 2016
  9. Pranit BauvaDec 6, 2016
  10. 23/27 bisect--helper: `bisect_replay` shell function in CPranit Bauva, Oct 14, 2016
  11. Stephan BeyerNov 22, 2016
  12. Pranit BauvaDec 6, 2016
  13. Stephan BeyerDec 6, 2016
  14. Stephan BeyerDec 6, 2016
  15. Christian CouderDec 7, 2016
  16. 04/27 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Oct 14, 2016
  17. Stephan BeyerNov 15, 2016
  18. Junio C HamanoNov 15, 2016
  19. Stephan BeyerNov 15, 2016
  20. Pranit BauvaNov 16, 2016
  21. 09/27 bisect--helper: `bisect_write` shell function in CPranit Bauva, Oct 14, 2016
  22. Stephan BeyerNov 17, 2016
  23. Pranit BauvaDec 6, 2016
  24. 20/27 bisect--helper: retire `--check-expected-revs` subcommandPranit Bauva, Oct 14, 2016
  25. 12/27 bisect--helper: `get_terms` & `bisect_terms` shell function in CPranit Bauva, Oct 14, 2016
  26. Stephan BeyerNov 17, 2016
  27. Pranit BauvaDec 6, 2016
  28. Stephan BeyerDec 6, 2016
  29. Pranit BauvaDec 7, 2016
  30. 13/27 bisect--helper: `bisect_start` shell function partially in CPranit Bauva, Oct 14, 2016
  31. Stephan BeyerNov 15, 2016
  32. Pranit BauvaNov 16, 2016
  33. Stephan BeyerNov 20, 2016
  34. Stephan BeyerNov 20, 2016
  35. 18/27 bisect--helper: `bisect_autostart` shell function in CPranit Bauva, Oct 14, 2016
  36. Stephan BeyerNov 20, 2016
  37. Pranit BauvaDec 6, 2016
  38. 21/27 bisect--helper: retire `--write-terms` subcommandPranit Bauva, Oct 14, 2016
  39. 19/27 bisect--helper: `bisect_state` & `bisect_head` shell function in CPranit Bauva, Oct 14, 2016
  40. Stephan BeyerNov 22, 2016
  41. Pranit BauvaDec 6, 2016
  42. Stephan BeyerDec 6, 2016
  43. Pranit BauvaDec 8, 2016
  44. 14/27 t6030: no cleanup with bad merge basePranit Bauva, Oct 14, 2016
  45. Junio C HamanoOct 14, 2016
  46. Pranit BauvaOct 15, 2016
  47. 15/27 bisect--helper: `bisect_next` and `bisect_auto_next` shell function in CPranit Bauva, Oct 14, 2016
  48. Stephan BeyerNov 20, 2016
  49. Pranit BauvaDec 31, 2016
  50. Stephan BeyerNov 21, 2016
  51. Pranit BauvaDec 31, 2016
  52. Stephan BeyerJan 1, 2017
  53. Pranit BauvaJan 1, 2017
  54. 07/27 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Oct 14, 2016
  55. Stephan BeyerNov 16, 2016
  56. Pranit BauvaNov 17, 2016
  57. 17/27 bisect--helper: retire `--next-all` subcommandPranit Bauva, Oct 14, 2016
  58. 24/27 bisect--helper: retire `--bisect-write` subcommandPranit Bauva, Oct 14, 2016
  59. 03/27 bisect--helper: `write_terms` shell function in CPranit Bauva, Oct 14, 2016
  60. 02/27 bisect: rewrite `check_term_format` shell function in CPranit Bauva, Oct 14, 2016
  61. Stephan BeyerNov 14, 2016
  62. Pranit BauvaNov 15, 2016
  63. 26/27 bisect--helper: retire `--bisect-auto-next` subcommandPranit Bauva, Oct 14, 2016
  64. 16/27 bisect--helper: retire `--bisect-clean-state` subcommandPranit Bauva, Oct 14, 2016
  65. 08/27 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Oct 14, 2016
  66. Stephan BeyerNov 16, 2016
  67. Pranit BauvaDec 6, 2016
  68. Pranit BauvaDec 16, 2016
  69. Stephan BeyerDec 17, 2016
  70. Pranit BauvaDec 16, 2016
  71. Stephan BeyerDec 17, 2016
  72. 25/27 bisect--helper: retire `--bisect-autostart` subcommandPranit Bauva, Oct 14, 2016
  73. Pranit BauvaOct 14, 2016
  74. 11/27 bisect--helper: `bisect_next_check` & bisect_voc shell function in CPranit Bauva, Oct 14, 2016
  75. Stephan BeyerNov 17, 2016
  76. Pranit BauvaDec 6, 2016
  77. 27/27 bisect--helper: remove the dequote in bisect_start()Pranit Bauva, Oct 14, 2016
  78. Junio C HamanoOct 27, 2016
  79. Christian CouderOct 27, 2016
  80. Matthieu MoyOct 28, 2016
  81. Stephan BeyerNov 15, 2016
  82. Junio C HamanoNov 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.