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

Re: [PATCH v2] sequencer: rectify empty hint in call of require_clean_work_tree()

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 7, 2023, 20:19 UTC
Message-ID
<xmqqa5v2ehba.fsf@gitster.g>
In-Reply-To
<20230807170935.2336730-1-oswald.buddenhagen@gmx.de>
Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:
Show 7 quoted lines
> The canonical way to represent "no error hint" is making it null, which
> shortcuts the error() call altogether. This fixes the output by removing
> the line which said just "error:".
>
> Alternatively, one could make the function treat empty strings like null
> strings, which would make it resemble its original script implementation
> more closely, but that doesn't seem like a worthwhile goal. If anything,

The analysis I gave you in the previous round was primarily to explain how this bug came to be, i.e. a misconversion of the scripted original, and that would be a lot more pertinent information than "is this closer to or further from the scripted original?" IOW, "equating NULL and an empty string is how the original implemented the logic correctly, but the misconversion made the current source to fail to do so" is the take-home message.

You could correct the current version by making it follow the same "NULL and an empty string are the same" convention to implement the logic correctly, or you can build on the misconverted callee that treats only NULL specially hence pass NULL instead of "". Either one is a valid implementation, but the reason to choose the former would not be to "make it resemble the original".

IOW, "doesn't seem like a worthwhile goal" is beating a strawman. Nobody advocates "if (!hint || !*hint)" because "the code must look exactly like the original". It is merely that it is one known way to achieve correctness, as it was how the original achieved its correctness.

> I'd go in the opposite direction and assert() that the argument is not
> an empty string.

If we were writing this program from scratch, "NULL means something different from any sttring, and an empty string does not have anything special compared to any other strings" would probably be a good semantics to give to this helper function. I'd be OK with the change. Also, adding "if (!*hint) BUG(...)" would be a good future direction, I would think.

Show 13 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index cc9821ece2..d15a7409d8 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -6182,7 +6182,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
>  	if (checkout_onto(r, opts, onto_name, &oid, orig_head))
>  		goto cleanup;
>  
> -	if (require_clean_work_tree(r, "rebase", "", 1, 1))
> +	if (require_clean_work_tree(r, "rebase", NULL, 1, 1))
>  		goto cleanup;
>  
>  	todo_list_write_total_nr(&new_todo);
Previous: Oswald BuddenhagenNext: Oswald Buddenhagen
Message 8 of 15 in “sequencer: rectify empty hint in call of require_clean_work_tree()”
  1. sequencer: rectify empty hint in call of require_clean_work_tree()Oswald Buddenhagen, Mar 23, 2023
  2. Oswald BuddenhagenApr 27, 2023
  3. Junio C HamanoApr 27, 2023
  4. Oswald BuddenhagenApr 27, 2023
  5. Felipe ContrerasMay 2, 2023
  6. Oswald BuddenhagenMay 3, 2023
  7. sequencer: rectify empty hint in call of require_clean_work_tree()Oswald Buddenhagen, Aug 7, 2023
  8. Junio C HamanoAug 7, 2023
  9. sequencer: rectify empty hint in call of require_clean_work_tree()Oswald Buddenhagen, Aug 9, 2023
  10. Junio C HamanoAug 9, 2023
  11. Oswald BuddenhagenAug 10, 2023
  12. Junio C HamanoAug 10, 2023
  13. sequencer: rectify empty hint in call of require_clean_work_tree()Oswald Buddenhagen, Aug 24, 2023
  14. Junio C HamanoAug 24, 2023
  15. Junio C HamanoAug 9, 2023

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.