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

Re: [PATCH 6/7] xdiff: simplify style assignments

From
PWPhillip 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 {
> 
Previous: Felipe ContrerasNext: Felipe Contreras
Message 49 of 69 in “Make diff3 the default conflict style”
  1. 0/7 Make diff3 the default conflict styleFelipe Contreras, Jun 9, 2021
  2. 1/7 test: add merge style config testFelipe Contreras, Jun 9, 2021
  3. Eric SunshineJun 9, 2021
  4. Felipe ContrerasJun 9, 2021
  5. Phillip WoodJun 10, 2021
  6. Felipe ContrerasJun 10, 2021
  7. Phillip WoodJun 10, 2021
  8. Felipe ContrerasJun 10, 2021
  9. Phillip WoodJun 10, 2021
  10. Felipe ContrerasJun 10, 2021
  11. Phillip WoodJun 11, 2021
  12. Felipe ContrerasJun 11, 2021
  13. 3/7 notes: fix merge.conflictstyle handlingFelipe Contreras, Jun 9, 2021
  14. 7/7 xdiff: make diff3 the default conflictStyleFelipe Contreras, Jun 9, 2021
  15. Johannes SixtJun 10, 2021
  16. Đoàn Trần Công DanhJun 10, 2021
  17. Felipe ContrerasJun 10, 2021
  18. Felipe ContrerasJun 10, 2021
  19. Jeff KingJun 10, 2021
  20. Felipe ContrerasJun 10, 2021
  21. Jeff KingJun 10, 2021
  22. Junio C HamanoJun 11, 2021
  23. Johannes SixtJun 11, 2021
  24. Junio C HamanoJun 11, 2021
  25. Johannes SixtJun 11, 2021
  26. Junio C HamanoJun 11, 2021
  27. Sergey OrganovJun 11, 2021
  28. Felipe ContrerasJun 11, 2021
  29. Sergey OrganovJun 11, 2021
  30. Felipe ContrerasJun 11, 2021
  31. Johannes SixtJun 11, 2021
  32. Felipe ContrerasJun 11, 2021
  33. Sergey OrganovJun 11, 2021
  34. Felipe ContrerasJun 11, 2021
  35. Sergey OrganovJun 11, 2021
  36. Felipe ContrerasJun 11, 2021
  37. Felipe ContrerasJun 11, 2021
  38. Johannes SixtJun 11, 2021
  39. Felipe ContrerasJun 11, 2021
  40. Felipe ContrerasJun 11, 2021
  41. Phillip WoodJun 10, 2021
  42. Felipe ContrerasJun 10, 2021
  43. 5/7 xdiff: rename XDL_MERGE_STYLE_DIFF3Felipe Contreras, Jun 9, 2021
  44. Phillip WoodJun 10, 2021
  45. Felipe ContrerasJun 10, 2021
  46. Junio C HamanoJun 11, 2021
  47. Felipe ContrerasJun 11, 2021
  48. 6/7 xdiff: simplify style assignmentsFelipe Contreras, Jun 9, 2021
  49. Phillip WoodJun 10, 2021
  50. Felipe ContrerasJun 10, 2021
  51. 2/7 merge-tree: fix merge.conflictstyle handlingFelipe Contreras, Jun 9, 2021
  52. 4/7 checkout: fix merge.conflictstyle handlingFelipe Contreras, Jun 9, 2021
  53. Phillip WoodJun 10, 2021
  54. Felipe ContrerasJun 10, 2021
  55. Phillip WoodJun 10, 2021
  56. Felipe ContrerasJun 10, 2021
  57. Phillip WoodJun 11, 2021
  58. Felipe ContrerasJun 11, 2021
  59. Phillip WoodJun 11, 2021
  60. Phillip WoodJun 17, 2021
  61. Felipe ContrerasJun 17, 2021
  62. Felipe ContrerasJun 11, 2021
  63. Elijah NewrenJun 11, 2021
  64. Felipe ContrerasJun 11, 2021
  65. Felipe ContrerasJun 11, 2021
  66. Elijah NewrenJun 11, 2021
  67. Felipe ContrerasJun 11, 2021
  68. Elijah NewrenJun 11, 2021
  69. Felipe ContrerasJun 13, 2021

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.