Re: [PATCH 6/7] xdiff: simplify style assignments
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jun 10, 2021, 09:26 UTC
- Message-ID
- <cc8bbc34-1048-0e7b-c783-33f556843a3f@gmail.com>
- In-Reply-To
- <20210609192842.696646-7-felipe.contreras@gmail.com>
On 09/06/2021 20:28, Felipe Contreras wrote:
I don't find the commit message explains this change very well
> There is little value in checking that git_xmerge_style isn't 0 before > changing it's default value.
I think the check is actually that git_xmerge_style isn't -1. Why is there little value in the check?
> Most of the time it isn't 0 anyway, so just assign the value directly.
Why to the times when it is zero (or -1) not matter?
Show 6 quoted lines
> Also, add the missing constant for the default value: XDL_MERGE_STYLE_MERGE. > > Additionally this change has the benefit that it gets rid of a Yoda > condition. > > No functional changes.
I think that is probably correct but it would be helpful if the commit message offered a bit more explanation.
Best Wishes
Phillip
Show 72 quoted lines
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
> builtin/merge-file.c | 3 +--
> ll-merge.c | 3 +--
> xdiff-interface.c | 4 ++--
> xdiff/xdiff.h | 1 +
> 4 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/builtin/merge-file.c b/builtin/merge-file.c
> index a4097a596f..01951762ec 100644
> --- a/builtin/merge-file.c
> +++ b/builtin/merge-file.c
> @@ -55,8 +55,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
> if (startup_info->have_repository) {
> /* Read the configuration file */
> git_config(git_xmerge_config, NULL);
> - if (0 <= git_xmerge_style)
> - xmp.style = git_xmerge_style;
> + xmp.style = git_xmerge_style;
> }
>
> argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
> diff --git a/ll-merge.c b/ll-merge.c
> index 9a8a2c365c..4ce8d3f9cc 100644
> --- a/ll-merge.c
> +++ b/ll-merge.c
> @@ -124,8 +124,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
> xmp.level = XDL_MERGE_ZEALOUS;
> xmp.favor = opts->variant;
> xmp.xpp.flags = opts->xdl_opts;
> - if (git_xmerge_style >= 0)
> - xmp.style = git_xmerge_style;
> + xmp.style = git_xmerge_style;
> if (marker_size > 0)
> xmp.marker_size = marker_size;
> xmp.ancestor = orig_name;
> diff --git a/xdiff-interface.c b/xdiff-interface.c
> index 64e2c4e301..19a030fbe2 100644
> --- a/xdiff-interface.c
> +++ b/xdiff-interface.c
> @@ -299,7 +299,7 @@ int xdiff_compare_lines(const char *l1, long s1,
> return xdl_recmatch(l1, s1, l2, s2, flags);
> }
>
> -int git_xmerge_style = -1;
> +int git_xmerge_style = XDL_MERGE_STYLE_MERGE;
>
> int git_xmerge_config(const char *var, const char *value, void *cb)
> {
> @@ -309,7 +309,7 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
> if (!strcmp(value, "diff3"))
> git_xmerge_style = XDL_MERGE_STYLE_DIFF3;
> else if (!strcmp(value, "merge"))
> - git_xmerge_style = 0;
> + git_xmerge_style = XDL_MERGE_STYLE_MERGE;
> /*
> * Please update _git_checkout() in
> * git-completion.bash when you add new merge config
> diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
> index 45883f5eb3..d24cd9f6ae 100644
> --- a/xdiff/xdiff.h
> +++ b/xdiff/xdiff.h
> @@ -64,6 +64,7 @@ extern "C" {
> #define XDL_MERGE_FAVOR_UNION 3
>
> /* merge output styles */
> +#define XDL_MERGE_STYLE_MERGE 0
> #define XDL_MERGE_STYLE_DIFF3 1
>
> typedef struct s_mmfile {
>