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

Re: [PATCH 5/5] merge-recursive: simplify handle_change_delete

From
Johannes Sixt <j6t@kdbg.org>
Date
May 19, 2018, 07:32 UTC
Message-ID
<3b05f4b1-e236-989d-afe0-e85b28c2e278@kdbg.org>
In-Reply-To
<20180519020700.2241-6-newren@gmail.com>
Am 19.05.2018 um 04:07 schrieb Elijah Newren:
> There is really no need for four branches of nearly identical messages
> when we can store the differences into small variables before printing.

Oh, there is a reason for the repeated message text: translations! Please do not play sentence Lego with translated strings. The original code is preferable.

Show 56 quoted lines
> It does require a few allocations this way, but makes the code much
> easier to parse for human readers.
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>   merge-recursive.c | 36 +++++++++++-------------------------
>   1 file changed, 11 insertions(+), 25 deletions(-)
> 
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 273ee79afa..3bd727995b 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1290,31 +1290,17 @@ static int handle_change_delete(struct merge_options *o,
>   		if (!ret)
>   			ret = update_file(o, 0, o_oid, o_mode, update_path);
>   	} else {
> -		if (!alt_path) {
> -			if (!old_path) {
> -				output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
> -				       "and %s in %s. Version %s of %s left in tree."),
> -				       change, path, delete_branch, change_past,
> -				       change_branch, change_branch, path);
> -			} else {
> -				output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
> -				       "and %s to %s in %s. Version %s of %s left in tree."),
> -				       change, old_path, delete_branch, change_past, path,
> -				       change_branch, change_branch, path);
> -			}
> -		} else {
> -			if (!old_path) {
> -				output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
> -				       "and %s in %s. Version %s of %s left in tree at %s."),
> -				       change, path, delete_branch, change_past,
> -				       change_branch, change_branch, path, alt_path);
> -			} else {
> -				output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
> -				       "and %s to %s in %s. Version %s of %s left in tree at %s."),
> -				       change, old_path, delete_branch, change_past, path,
> -				       change_branch, change_branch, path, alt_path);
> -			}
> -		}
> +		const char *deleted_path = old_path ? old_path : path;
> +		char *supp1 = xstrfmt(old_path ? " to %s" : "", path);
> +		char *supp2 = xstrfmt(alt_path ? " at %s" : "", alt_path);
> +
> +		output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
> +		       "and %s%s in %s. Version %s of %s left in tree%s."),
> +		       change, deleted_path, delete_branch, change_past,
> +		       supp1, change_branch, change_branch, path, supp2);
> +		free(supp1);
> +		free(supp2);
> +
>   		/*
>   		 * No need to call update_file() on path when change_branch ==
>   		 * o->branch1 && !alt_path, since that would needlessly touch
> 
Previous: Elijah NewrenNext: Elijah Newren
Message 4 of 27 in “merge-recursive code cleanups”
  1. 0/5 merge-recursive code cleanupsElijah Newren, May 19, 2018
  2. 1/5 merge-recursive: fix miscellaneous grammar error in commentElijah Newren, May 19, 2018
  3. 5/5 merge-recursive: simplify handle_change_deleteElijah Newren, May 19, 2018
  4. Johannes SixtMay 19, 2018
  5. Elijah NewrenMay 19, 2018
  6. Johannes SchindelinMay 21, 2018
  7. Elijah NewrenMay 21, 2018
  8. 2/5 merge-recursive: fix numerous argument alignment issuesElijah Newren, May 19, 2018
  9. Johannes SchindelinMay 21, 2018
  10. Elijah NewrenMay 21, 2018
  11. 3/5 merge-recursive: clarify the rename_dir/RENAME_DIR meaningElijah Newren, May 19, 2018
  12. Johannes SchindelinMay 21, 2018
  13. 4/5 merge-recursive: rename conflict_rename_*() family of functionsElijah Newren, May 19, 2018
  14. Johannes SchindelinMay 21, 2018
  15. 0/5 merge-recursive code cleanupsElijah Newren, May 22, 2018
  16. 4/5 merge-recursive: rename conflict_rename_*() family of functionsElijah Newren, May 22, 2018
  17. 5/5 merge-recursive: add pointer about unduly complex looking codeElijah Newren, May 22, 2018
  18. 1/5 merge-recursive: fix miscellaneous grammar error in commentElijah Newren, May 22, 2018
  19. 2/5 merge-recursive: fix numerous argument alignment issuesElijah Newren, May 22, 2018
  20. 3/5 merge-recursive: clarify the rename_dir/RENAME_DIR meaningElijah Newren, May 22, 2018
  21. 0/6 merge-recursive code cleanupsElijah Newren, Jun 10, 2018
  22. 1/6 merge-recursive: fix miscellaneous grammar error in commentElijah Newren, Jun 10, 2018
  23. 2/6 merge-recursive: fix numerous argument alignment issuesElijah Newren, Jun 10, 2018
  24. 4/6 merge-recursive: clarify the rename_dir/RENAME_DIR meaningElijah Newren, Jun 10, 2018
  25. 3/6 merge-recursive: align labels with their respective code blocksElijah Newren, Jun 10, 2018
  26. 6/6 merge-recursive: add pointer about unduly complex looking codeElijah Newren, Jun 10, 2018
  27. 5/6 merge-recursive: rename conflict_rename_*() family of functionsElijah Newren, Jun 10, 2018

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.