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

Re: [PATCH 2/2] git-merge-recursive-{ours,theirs}

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 20, 2008, 12:58 UTC
Message-ID
<alpine.DEB.1.00.0806201351370.6439@racer>
In-Reply-To
<7vbq1wo8ck.fsf_-_@gitster.siamese.dyndns.org>
Hi,
On Fri, 20 Jun 2008, Junio C Hamano wrote:
Show 22 quoted lines
> diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
> index 4aa28a1..a355e7a 100644
> --- a/builtin-merge-recursive.c
> +++ b/builtin-merge-recursive.c
> @@ -650,9 +655,26 @@ static int merge_3way(mmbuffer_t *result_buf,
>  	fill_mm(a->sha1, &src1);
>  	fill_mm(b->sha1, &src2);
>  
> +	if (index_only)
> +		favor = 0;
> +	else {
> +		switch (merge_recursive_variants) {
> +		case MERGE_RECURSIVE_OURS:
> +			favor = XDL_MERGE_FAVOR_OURS;
> +			break;
> +		case MERGE_RECURSIVE_THEIRS:
> +			favor = XDL_MERGE_FAVOR_THEIRS;
> +			break;
> +		default:
> +			favor = 0;
> +			break;
> +		}
Hrm.  I would have preferred something like this:
	if (!index_only && merge_recursive_variants == MERGE_RECURSIVE_OURS)
		favor = XDL_MERGE_FAVOR_OURS;
	if (!index_only && merge_recursive_variants == MERGE_RECURSIVE_THEIRS)
		favor = XDL_MERGE_FAVOR_THEIRS;
	else
		favor = 0;
Show 7 quoted lines
> +	}
> +	flag = LL_MERGE_FLAGS(index_only, favor);
> +
>  	merge_status = ll_merge(result_buf, a->path, &orig,
>  				&src1, name1, &src2, name2,
> -				index_only);
> +				flag);

Sorry, but in my opinion this flag mangling makes the whole code uglier. Why not just add another parameter?

Or if you are really concerned about future enhancements to ll_merge(), use a struct.

Show 17 quoted lines
> @@ -1379,11 +1401,18 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
>  	struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
>  	int index_fd;
>  
> +	merge_recursive_variants = 0;
>  	if (argv[0]) {
>  		int namelen = strlen(argv[0]);
>  		if (8 < namelen &&
>  		    !strcmp(argv[0] + namelen - 8, "-subtree"))
> -			subtree_merge = 1;
> +			merge_recursive_variants = MERGE_RECURSIVE_SUBTREE;
> +		else if (5 < namelen &&
> +			 !strcmp(argv[0] + namelen - 5, "-ours"))
> +			merge_recursive_variants = MERGE_RECURSIVE_OURS;
> +		else if (7 < namelen &&
> +			 !strcmp(argv[0] + namelen - 7, "-theirs"))
> +			merge_recursive_variants = MERGE_RECURSIVE_THEIRS;
This just cries out loud for a new function suffixcmp().

I will not say anything about the long lines in git-merge.sh, since I fully expect builtin-merge to happen Real Soon Now.

Anyhow, your comments about this driving the wrong workflow still apply. Maybe we want to display them really, really prominently in Documentation/merge-strategies.txt.

Ciao, Dscho

Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 22 in “Guided merge with override”
  1. Geoff RussellJun 16, 2008
  2. Miklos VajnaJun 16, 2008
  3. Johannes SixtJun 16, 2008
  4. Miklos VajnaJun 16, 2008
  5. Sverre RabbelierJun 16, 2008
  6. Geoff RussellJun 16, 2008
  7. Junio C HamanoJun 17, 2008
  8. Johannes SchindelinJun 18, 2008
  9. Johannes SchindelinJun 18, 2008
  10. Junio C HamanoJun 18, 2008
  11. Johannes SchindelinJun 18, 2008
  12. 1/2 git-merge-file --ours, --theirsJunio C Hamano, Jun 20, 2008
  13. 2/2 git-merge-recursive-{ours,theirs}Junio C Hamano, Jun 20, 2008
  14. Johannes SchindelinJun 20, 2008
  15. Junio C HamanoJun 21, 2008
  16. Johannes SchindelinJun 21, 2008
  17. Jakub NarebskiJun 21, 2008
  18. Johannes SixtJun 17, 2008
  19. Sverre RabbelierJun 17, 2008
  20. Johannes SchindelinJun 17, 2008
  21. Sverre RabbelierJun 17, 2008
  22. Johannes SchindelinJun 17, 2008

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.