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

Re: [RFC/PATCH v11 04/13] bisect--helper: `bisect_clean_state` shell function in C

From
Pranit Bauva <pranit.bauva@gmail.com>
Date
Aug 3, 2016, 20:27 UTC
Message-ID
<CAFZEwPNFohRLCS4piB1t0LO-=keucwzRKZ2Jyhhf234tnWnVGg@mail.gmail.com>
In-Reply-To
<xmqqy44fdpxd.fsf@gitster.mtv.corp.google.com>
Hey Junio,
On Tue, Aug 2, 2016 at 11:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 35 quoted lines
> Pranit Bauva <pranit.bauva@gmail.com> writes:
>
>> +static int bisect_clean_state(void)
>> +{
>> +     int result = 0;
>> +
>> +     /* There may be some refs packed during bisection */
>> +     struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
>> +     for_each_ref_in("refs/bisect/", mark_for_removal, (void *) &refs_for_removal);
>> +     string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
>> +     result = delete_refs(&refs_for_removal);
>> +     refs_for_removal.strdup_strings = 1;
>> +     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_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 to support the --no-checkout option
>> +      * introduced in the commit 4796e823a.
>> +      */
>> +     remove_path(git_path_bisect_start());
>
> I can see that refs/files-backend.c misuses it already, but
> remove_path() helper is about removing a path in the working tree,
> together with any parent directory that becomes empty due to the
> removal.  You do not expect $GIT_DIR/ to become an empty directory
> after removing $GIT_DIR/BISECT_LOG nor want to rmdir $GIT_DIR even
> if it becomes empty.  It is a wrong helper function to use here.
>
> Also you do not seem to check the error from the function to smudge
> the "result" you are returning from this function.
Yes I should combine the results from every removal.
> Isn't unlink_or_warn() more correct helper to use here?

The shell code uses rm -f which is silent and it removes only if present. So it makes me wonder which would be more appropriate unlink_or_warn() or remove_or_warn() or remove_path(). Is remove_path() different from its shell equivalent "rm -f"?

>> +     return result;
>> +}

Regards, Pranit Bauva

Previous: Junio C HamanoNext: Junio C Hamano
Message 34 of 39 in “bisect--helper: use OPT_CMDMODE instead of OPT_BOOL”
  1. 01/13 bisect--helper: use OPT_CMDMODE instead of OPT_BOOLPranit Bauva, Jul 31, 2016
  2. 06/13 wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()Pranit Bauva, Jul 31, 2016
  3. 05/13 t6030: explicitly test for bisection cleanupPranit Bauva, Jul 31, 2016
  4. 03/13 bisect--helper: `write_terms` shell function in CPranit Bauva, Jul 31, 2016
  5. Junio C HamanoAug 2, 2016
  6. Pranit BauvaAug 3, 2016
  7. Junio C HamanoAug 4, 2016
  8. 07/13 bisect--helper: `bisect_reset` shell function in CPranit Bauva, Jul 31, 2016
  9. Junio C HamanoAug 2, 2016
  10. 11/13 bisect--helper: `bisect_next_check` shell function in CPranit Bauva, Jul 31, 2016
  11. Junio C HamanoAug 2, 2016
  12. Pranit BauvaAug 3, 2016
  13. 12/13 bisect--helper: `get_terms` & `bisect_terms` shell function in CPranit Bauva, Jul 31, 2016
  14. Junio C HamanoAug 2, 2016
  15. Pranit BauvaAug 3, 2016
  16. 08/13 bisect--helper: `is_expected_rev` & `check_expected_revs` shell function in CPranit Bauva, Jul 31, 2016
  17. Junio C HamanoAug 2, 2016
  18. 09/13 bisect--helper: `bisect_write` shell function in CPranit Bauva, Jul 31, 2016
  19. Junio C HamanoAug 2, 2016
  20. Junio C HamanoAug 2, 2016
  21. Pranit BauvaAug 3, 2016
  22. Pranit BauvaAug 3, 2016
  23. 02/13 bisect: rewrite `check_term_format` shell function in CPranit Bauva, Jul 31, 2016
  24. Junio C HamanoAug 2, 2016
  25. Pranit BauvaAug 3, 2016
  26. 10/13 bisect--helper: `check_and_set_terms` shell function in CPranit Bauva, Jul 31, 2016
  27. Junio C HamanoAug 2, 2016
  28. Pranit BauvaAug 3, 2016
  29. 13/13 bisect--helper: `bisect_start` shell function partially in CPranit Bauva, Jul 31, 2016
  30. Junio C HamanoAug 2, 2016
  31. Pranit BauvaAug 3, 2016
  32. 04/13 bisect--helper: `bisect_clean_state` shell function in CPranit Bauva, Jul 31, 2016
  33. Junio C HamanoAug 2, 2016
  34. Pranit BauvaAug 3, 2016
  35. Junio C HamanoAug 4, 2016
  36. Pranit BauvaAug 4, 2016
  37. Junio C HamanoAug 4, 2016
  38. Pranit BauvaAug 4, 2016
  39. Junio C HamanoAug 2, 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.