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
>