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

Re: [PATCH v2 09/11] bisect: libify `check_good_are_ancestors_of_bad` and its dependents

From
Miriam R. <mirucam@gmail.com>
Date
Jan 30, 2020, 14:40 UTC
Message-ID
<CAN7CjDCiP_KVC5Ey6cMuPN17vRNp_s4vy94qsaAKRPG=k3Rj3g@mail.gmail.com>
In-Reply-To
<nycvar.QRO.7.76.6.2001301341100.46@tvgsbejvaqbjf.bet>
Hi,

El jue., 30 ene. 2020 a las 14:46, Johannes Schindelin (<Johannes.Schindelin@gmx.de>) escribió:

Show 23 quoted lines
>
> Hi Miriam,
>
> On Tue, 28 Jan 2020, Miriam Rubio wrote:
>
> > @@ -893,18 +901,20 @@ static void check_good_are_ancestors_of_bad(struct repository *r,
> >       if (check_ancestors(r, rev_nr, rev, prefix))
> >               res = check_merge_bases(rev_nr, rev, no_checkout);
> >       free(rev);
> > -     if (res)
> > -             exit(res == -11 ? 0 : -res);
> >
> > -     /* Create file BISECT_ANCESTORS_OK. */
> > -     fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
> > -     if (fd < 0)
> > -             warning_errno(_("could not create file '%s'"),
> > -                           filename);
> > -     else
> > -             close(fd);
> > +     if (!res)
> > +     {
>
> Please move the opening `{` to the same line as the `if (!res)`.
Noted.
Show 21 quoted lines
>
> > +             /* Create file BISECT_ANCESTORS_OK. */
> > +             fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
> > +             if (fd < 0)
> > +                     warning_errno(_("could not create file '%s'"),
> > +                                   filename);
> > +             else
> > +                     close(fd);
> > +     }
>
> I wonder whether this would be easier to read:
>
>         if (res == -11)
>                 res = 0;
>         else if (res)
>                 ; /* error out */
>         else if ((fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0)
>                 res = warning_errno(_("could not create file '%s'"), filename);
>         else
>                 close(fd);
>
Yes, I think it is a good improvement.
> Note: my code explicitly assigns `res = -1` if the file could not be
> created, which is technically a change in behavior, but I think it is
> actually a bug fix.
Aha.

If my mentor is ok with this change, I will apply the improvement you suggested :).

Show 27 quoted lines
>
> >   done:
> >       free(filename);
> > +     return res;
> >  }
> >
> >  /*
> > @@ -975,7 +985,9 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
> >       if (read_bisect_refs())
> >               die(_("reading bisect refs failed"));
>
> I see that there is still a `die()` here, and you left it alone in this
> patch because at this point, only the callers of
> `check_good_are_ancestors_of_bad()` need to be addressed. Good.
>
> At a later point, this will have to be dealt with, of course.
>
> Another thing will need to be handled, too: while I was looking at the
> code whether any resources need to be released (returning a negative
> integer does not release memory or close file handles, unlike `die()`), I
> stumbled across the fact that `term_bad` and `term_good` are file-local
> variables. They will need to be made attributes of a `struct` and will
> need to be released properly, i.e. the ownership will have to be clarified
> (is a failed `bisect_next_all()` responsible for releasing the memory it
> allocated via `read_bisect_terms()`, or its caller?).
>
> Just something to keep in mind. Or better: to jot down in a TODO list.
Ok. I will write this down for future improvements. Thank you!
Show 40 quoted lines
>
> >
> > -     check_good_are_ancestors_of_bad(r, prefix, no_checkout);
> > +     res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
> > +     if (res)
> > +             return res;
> >
> >       bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
> >       revs.limited = 1;
> > diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> > index 826fcba2ed..3442bfe2cb 100644
> > --- a/builtin/bisect--helper.c
> > +++ b/builtin/bisect--helper.c
> > @@ -666,7 +666,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
> >
> >       switch (cmdmode) {
> >       case NEXT_ALL:
> > -             return bisect_next_all(the_repository, prefix, no_checkout);
> > +             res = bisect_next_all(the_repository, prefix, no_checkout);
> > +             break;
> >       case WRITE_TERMS:
> >               if (argc != 2)
> >                       return error(_("--write-terms requires two arguments"));
> > @@ -713,5 +714,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
> >               return error("BUG: unknown subcommand '%d'", cmdmode);
> >       }
> >       free_terms(&terms);
> > -     return !!res;
> > +     /*
> > +      * Handle early success
> > +      * From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all
> > +      */
> > +     if (res == -11)
> > +             res = 0;
>
> Hmm. Is this the correct place, though? Should `bisect_next_all()` not be
> the function that already turns `-11` into `0`? In other words, _which_
> code are we supposed to skip over when `check_good_are_ancestors_of_bad()`
> returns `-11`? In other words, where would the `catch` of the
> `try`/`catch` be, if we had portable exceptions in C?

I think there must be a reason to do it there (but I don't know exactly), because there are some comments in code that say explicitly that this -11 to 0 is done in cmd_bisect_helper(), when the bisecting command exits.

Show 7 quoted lines
>
> > +
> > +     return res < 0 ? -res : res;
>
> This is a change in behavior, though: previously we guaranteed that the
> exit code is either 0 on success or 1 upon failure. I am not quite sure
> that we want to change that behavior.

I think this is because different error codes might enable a bisecting script calling the bisect command that uses this function to do different things depending on the exit status of the bisect command.

Thank you for reviewing. Best, Miriam.

Show 9 quoted lines
>
> Ciao,
> Dscho
>
> >  }
> > --
> > 2.21.1 (Apple Git-122.3)
> >
> >
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 20 of 29 in “Finish converting git bisect to C part 1”
  1. Miriam RubioJan 28, 2020
  2. 01/11 bisect--helper: convert `vocab_*` char pointers to char arraysMiriam Rubio, Jan 28, 2020
  3. 02/11 bisect--helper: change `retval` to `res`Miriam Rubio, Jan 28, 2020
  4. 03/11 bisect: use the standard 'if (!var)' way to check for 0Miriam Rubio, Jan 28, 2020
  5. 04/11 run-command: make `exists_in_PATH()` non-staticMiriam Rubio, Jan 28, 2020
  6. Johannes SchindelinJan 30, 2020
  7. 05/11 bisect--helper: introduce new `decide_next()` functionMiriam Rubio, Jan 28, 2020
  8. Johannes SchindelinJan 30, 2020
  9. Miriam R.Jan 30, 2020
  10. 06/11 bisect: libify `exit_if_skipped_commits` to `error_if_skipped*` and its dependentsMiriam Rubio, Jan 28, 2020
  11. Junio C HamanoJan 31, 2020
  12. 07/11 bisect: libify `bisect_checkout`Miriam Rubio, Jan 28, 2020
  13. Junio C HamanoJan 31, 2020
  14. 08/11 bisect: libify `check_merge_bases` and its dependentsMiriam Rubio, Jan 28, 2020
  15. Junio C HamanoJan 31, 2020
  16. 11/11 bisect: libify `bisect_next_all`Miriam Rubio, Jan 28, 2020
  17. 10/11 bisect: libify `handle_bad_merge_base` and its dependentsMiriam Rubio, Jan 28, 2020
  18. 09/11 bisect: libify `check_good_are_ancestors_of_bad` and its dependentsMiriam Rubio, Jan 28, 2020
  19. Johannes SchindelinJan 30, 2020
  20. Miriam R.Jan 30, 2020
  21. Johannes SchindelinJan 30, 2020
  22. Miriam R.Jan 30, 2020
  23. Christian CouderJan 30, 2020
  24. Johannes SchindelinJan 31, 2020
  25. Christian CouderJan 31, 2020
  26. Johannes SchindelinJan 30, 2020
  27. Miriam R.Jan 30, 2020
  28. Fwd: [PATCH v2 04/11] run-command: make `exists_in_PATH()` non-staticMiriam R., Jan 30, 2020
  29. Fwd: [PATCH v2 09/11] bisect: libify `check_good_are_ancestors_of_bad` and its dependentsMiriam R., Jan 31, 2020

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.