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

Re: [PATCH] merge-recursive: option to disable renames

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 16, 2016, 21:49 UTC
Message-ID
<xmqqegccmikn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1455583834-4796-1-git-send-email-felipegassis@gmail.com>
"Felipe Gonçalves Assis"  <felipeg.assis@gmail.com> writes:
> +no-renames;;
> +	Turn off rename detection.
> +	See also linkgit:git-diff[1] `--no-renames`.

Even though by default for merge-recursive the rename detection is on, if we are adding an option to control this aspect of the behaviour from the command line, it should follow the usual pattern, i.e.

 (1) the code to parse options would allow an earlier "--no-renames"
     on the command line to be overridden with a later "--renames"; and
 (2) the description in the documentation would be headed by
     "--[no-]renames", describes which one is the default, etc.
Show 21 quoted lines
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 8eabde2..ca67805 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1839,9 +1839,16 @@ int merge_trees(struct merge_options *o,
>  
>  		entries = get_unmerged();
>  		record_df_conflict_files(o, entries);
> -		re_head  = get_renames(o, head, common, head, merge, entries);
> -		re_merge = get_renames(o, merge, common, head, merge, entries);
> -		clean = process_renames(o, re_head, re_merge);
> +		if (o->detect_rename) {
> +			re_head  = get_renames(o, head, common, head, merge, entries);
> +			re_merge = get_renames(o, merge, common, head, merge, entries);
> +			clean = process_renames(o, re_head, re_merge);
> +		}
> +		else {
> +			re_head  = xcalloc(1, sizeof(struct string_list));
> +			re_merge = xcalloc(1, sizeof(struct string_list));
> +			clean = 1;
> +		}

Yup, this is much nicer than butchering diffcore-rename.c for no good reason ;-).

Even if you _know_ that process_renames() currently does not do anything other than returning 1, it is a bad idea to hardcode that knowledge on the caller's side. Perhaps

Show 12 quoted lines
>  		entries = get_unmerged();
>  		record_df_conflict_files(o, entries);
> -		re_head  = get_renames(o, head, common, head, merge, entries);
> -		re_merge = get_renames(o, merge, common, head, merge, entries);
> +		if (o->detect_rename) {
> +			re_head  = get_renames(o, head, common, head, merge, entries);
> +			re_merge = get_renames(o, merge, common, head, merge, entries);
> +		} else {
> +			re_head  = xcalloc(1, sizeof(struct string_list));
> +			re_merge = xcalloc(1, sizeof(struct string_list));
> +		}
> 		clean = process_renames(o, re_head, re_merge);

Preparing a new empty string_list instance with xcalloc() without doing string_list_init() is probably "caller knows too much about implementation detail of the API", but get_renames() seems to do so already, so I'll let it pass.

Previous: Felipe Gonçalves AssisNext: Junio C Hamano
Message 2 of 5 in “merge-recursive: option to disable renames”
  1. merge-recursive: option to disable renamesFelipe Gonçalves Assis, Feb 16, 2016
  2. Junio C HamanoFeb 16, 2016
  3. Junio C HamanoFeb 16, 2016
  4. Felipe Gonçalves AssisFeb 16, 2016
  5. Junio C HamanoFeb 16, 2016

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.