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

Re: [PATCH 1/4] bisect--helper: `bisect_clean_state` shell function in C

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Jun 8, 2016, 07:46 UTC
Message-ID
<CAFZEwPMJbKAOdffWs7QedB+4j32LaBZeV1iGpUuGntMjXeN3hg@mail.gmail.com>
In-Reply-To
<CAPig+cTqk0d60Omsm12RXF2uzoxoPjbqHj7V8Y=6Uu+fH5b43Q@mail.gmail.com>
Hey Eric,
On Wed, Jun 8, 2016 at 4:01 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 30 quoted lines
> On Tue, Jun 7, 2016 at 4:54 PM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>> Reimplement `bisect_clean_state` shell function in C and add a
>> `bisect-clean-state` subcommand to `git bisect--helper` to call it from
>> git-bisect.sh .
>> [...]
>> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
>> ---
>> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
>> @@ -78,11 +87,43 @@ static int write_terms(const char *bad, const char *good)
>> +int mark_for_removal(const char *refname, const struct object_id *oid,
>> +                      int flag, void *cb_data)
>> +{
>> +       struct string_list *refs = cb_data;
>> +       char *ref = xstrfmt("refs/bisect/%s", refname);
>
> Here you're allocating a string...
>
>> +       string_list_append(refs, ref);
>> +       return 0;
>> +}
>> +
>> +int bisect_clean_state(void)
>> +{
>> +       int result = 0;
>> +       struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
>> +       for_each_ref_in("refs/bisect/", mark_for_removal, (void *) &refs_for_removal);
>
> ...and the allocated string gets inserted into a string_list which
> itself duplicates the string (STRING_LIST_INIT_DUP), so this is
> leaking the string you created with xstrfmt(), isn't it?

Yes nice catch. I would prefer using the string_list with STRING_LIST_INIT_DUP and free the ref.

Show 5 quoted lines
>> +       string_list_append(&refs_for_removal, "BISECT_HEAD");
>> +       result |= delete_refs(&refs_for_removal);
>
> Not sure I understand the point of using |= here rather than merely =
> since this is the only place 'result' is assigned in this function.
In some initial iterations I assigned value of result before so used
|=. Then I realized it isn't necessary, so removed it. Forgot to
remove |=. Will do it!
Show 18 quoted lines
>> +       string_list_clear(&refs_for_removal, 0);
>> +       remove_path(git_path_bisect_expected_rev());
>> +       remove_path(git_path_bisect_ancestors_ok());
>> +       remove_path(git_path_bisect_log());
>> +       remove_path(git_path_bisect_names());
>> +       remove_path(git_path_bisect_run());
>> +       remove_path(git_path_bisect_write_terms());
>> +       /* Cleanup head-name if it got left by an old version of git-bisect */
>> +       remove_path(git_path_head_name());
>> +       /* Cleanup BISECT_START last */
>> +       remove_path(git_path_bisect_start());
>
> The BISECT_START comment merely repeats what the code itself already
> says. I realize that you merely copied this from the shell code, but
> it isn't helpful in its current form. Much more helpful would be to
> explain *why* this needs to be done last. Perhaps the commit message
> of the commit which introduced the comment originally would give a
> clue (I haven't checked).

The commit(4796e823a) by Jon Seymour (4 Aug, 2011) explains this. I am not sure how I would frame the sentence as that commit introduces a concept whose by-product is the comment. I do want to include it in the commit message otherwise it would be passed on as "you have to do it but no one knows why".

Show 10 quoted lines
>> +       return result;
>> +}
>> diff --git a/git-bisect.sh b/git-bisect.sh
>> @@ -430,27 +430,7 @@ bisect_reset() {
>> -bisect_clean_state() {
>> -       # There may be some refs packed during bisection.
>
> This comment doesn't seem to be reproduced in the C version. Should it
> be? Is it no longer relevant in the C version? What does it mean
> exactly?

git-bisect itself never packs refs on its own. But there is a possibility that the user might have packed the refs in the bisection state. This was introduced by Christian ( 15 Nov, 2007) in commit 947a604b01.

Show 18 quoted lines
>> -       git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
>> -       while read ref hash
>> -       do
>> -               git update-ref -d $ref $hash || exit
>> -       done
>> -       rm -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
>> -       rm -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
>> -       rm -f "$GIT_DIR/BISECT_LOG" &&
>> -       rm -f "$GIT_DIR/BISECT_NAMES" &&
>> -       rm -f "$GIT_DIR/BISECT_RUN" &&
>> -       rm -f "$GIT_DIR/BISECT_TERMS" &&
>> -       # Cleanup head-name if it got left by an old version of git-bisect
>> -       rm -f "$GIT_DIR/head-name" &&
>> -       git update-ref -d --no-deref BISECT_HEAD &&
>> -       # clean up BISECT_START last
>> -       rm -f "$GIT_DIR/BISECT_START"
>> +       git bisect--helper --bisect-clean-state || exit
>>  }
I will also include static in function declaration. Thanks!

Regards, Pranit Bauva

Previous: Eric SunshineNext: Eric Sunshine
Message 26 of 75 in “bisect--helper: `bisect_clean_state` shell function in C”
  1. 1/4 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Jun 7, 2016
  2. 2/4 t6030: explicitly test for bisection cleanupPranit Bauva, Jun 7, 2016
  3. Eric SunshineJun 7, 2016
  4. Pranit BauvaJun 8, 2016
  5. Eric SunshineJun 8, 2016
  6. Pranit BauvaJun 8, 2016
  7. 3/4 dir: introduce file_size() to check the size of filePranit Bauva, Jun 7, 2016
  8. Eric SunshineJun 8, 2016
  9. Pranit BauvaJun 8, 2016
  10. Eric SunshineJun 8, 2016
  11. Christian CouderJun 8, 2016
  12. Torsten BögershausenJun 8, 2016
  13. Pranit BauvaJun 8, 2016
  14. Torsten BögershausenJun 12, 2016
  15. Pranit BauvaJun 13, 2016
  16. 4/4 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Jun 7, 2016
  17. Eric SunshineJun 8, 2016
  18. Christian CouderJun 8, 2016
  19. Christian CouderJun 8, 2016
  20. Eric SunshineJun 8, 2016
  21. Pranit BauvaJun 8, 2016
  22. Eric SunshineJun 8, 2016
  23. Pranit BauvaJun 8, 2016
  24. Eric SunshineJun 7, 2016
  25. Eric SunshineJun 8, 2016
  26. Pranit BauvaJun 8, 2016
  27. Eric SunshineJun 8, 2016
  28. Pranit BauvaJun 8, 2016
  29. Christian CouderJun 8, 2016
  30. Eric SunshineJun 8, 2016
  31. Pranit BauvaJun 8, 2016
  32. 0/6 convert various shell functions in git-bisect to CPranit Bauva, Jun 15, 2016
  33. 1/6 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Jun 15, 2016
  34. Eric SunshineJun 15, 2016
  35. Pranit BauvaJun 15, 2016
  36. Eric SunshineJun 15, 2016
  37. 2/6 t6030: explicitly test for bisection cleanupPranit Bauva, Jun 15, 2016
  38. 3/6 wrapper: move is_empty_file() from builtin/am.cPranit Bauva, Jun 15, 2016
  39. Junio C HamanoJun 15, 2016
  40. Pranit BauvaJun 15, 2016
  41. Eric SunshineJun 15, 2016
  42. Pranit BauvaJun 15, 2016
  43. 5/6 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Jun 15, 2016
  44. Eric SunshineJun 15, 2016
  45. Pranit BauvaJun 16, 2016
  46. Eric SunshineJun 16, 2016
  47. Pranit BauvaJun 16, 2016
  48. Christian CouderJun 16, 2016
  49. Pranit BauvaJun 17, 2016
  50. 4/6 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Jun 15, 2016
  51. Eric SunshineJun 15, 2016
  52. Pranit BauvaJun 16, 2016
  53. 6/6 bisect--helper: `bisect_write` shell function in CPranit Bauva, Jun 15, 2016
  54. Eric SunshineJun 16, 2016
  55. Pranit BauvaJun 16, 2016
  56. Christian CouderJun 16, 2016
  57. Pranit BauvaJun 17, 2016
  58. Eric SunshineJun 15, 2016
  59. Pranit BauvaJun 15, 2016
  60. 0/6 convert various shell functions in git-bisect to CPranit Bauva, Jun 26, 2016
  61. 1/6 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Jun 26, 2016
  62. 2/6 t6030: explicitly test for bisection cleanupPranit Bauva, Jun 26, 2016
  63. 3/6 wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()Pranit Bauva, Jun 26, 2016
  64. 4/6 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Jun 26, 2016
  65. 5/6 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Jun 26, 2016
  66. 6/6 bisect--helper: `bisect_write` shell function in CPranit Bauva, Jun 26, 2016
  67. 0/6 convert various shell functions in git-bisect to CPranit Bauva, Jul 6, 2016
  68. 1/6 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Jul 6, 2016
  69. 2/6 t6030: explicitly test for bisection cleanupPranit Bauva, Jul 6, 2016
  70. Junio C HamanoJul 11, 2016
  71. 3/6 wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()Pranit Bauva, Jul 6, 2016
  72. 4/6 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Jul 6, 2016
  73. 5/6 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Jul 6, 2016
  74. 6/6 bisect--helper: `bisect_write` shell function in CPranit Bauva, Jul 6, 2016
  75. Junio C HamanoJul 11, 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.