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

Re: [PATCH v2 3/3] diff: Introduce --diff-algorithm command line option

From
Michal Privoznik <mprivozn@redhat.com>
Date
Jan 15, 2013, 10:07 UTC
Message-ID
<50F52A5B.4030609@redhat.com>
In-Reply-To
<7vvcaz8of4.fsf@alter.siamese.dyndns.org>
On 14.01.2013 22:06, Junio C Hamano wrote:
Show 60 quoted lines
> Michal Privoznik <mprivozn@redhat.com> writes:
> 
>> +--diff-algorithm={patience|minimal|histogram|myers}::
>> +	Choose a diff algorithm. The variants are as follows:
>> ++
>> +--
>> +`myers`;;
>> +	The basic greedy diff algorithm.
>> +`minimal`;;
>> +	Spend extra time to make sure the smallest possible diff is
>> +	produced.
>> +`patience`;;
>> +	Use "patience diff" algorithm when generating patches.
>> +`histogram`;;
>> +	This algorithm extends the patience algorithm to "support
>> +	low-occurrence common elements".
>> +--
>> ++
>> +For instance, if you configured diff.algorithm variable to a
>> +non-default value and want to use the default one, then you
>> +have to use `--diff-algorithm=myers` option.
>> +
>> +You should prefer this option over the `--minimal`, `--patience` and
>> +`--histogram` which are kept just for backwards compatibility.
> 
> Much better; I'd drop the last paragraph, though.
> 
> I also think we really should consider "default" synonym for
> whichever happens to be the built-in default (currently myers).
> 
>> diff --git a/diff.c b/diff.c
>> index e9a7e4d..3e021d5 100644
>> --- a/diff.c
>> +++ b/diff.c
>> @@ -144,7 +144,7 @@ static int git_config_rename(const char *var, const char *value)
>>  	return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0;
>>  }
>>  
>> -static long parse_algorithm_value(const char *value)
>> +long parse_algorithm_value(const char *value)
>>  {
>>  	if (!value || !strcasecmp(value, "myers"))
>>  		return 0;
>> @@ -3633,6 +3633,16 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
>>  		options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
>>  	else if (!strcmp(arg, "--histogram"))
>>  		options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
>> +	else if (!prefixcmp(arg, "--diff-algorithm=")) {
>> +		long value = parse_algorithm_value(arg+17);
>> +		if (value < 0)
>> +			return error("option diff-algorithm accepts \"myers\", "
>> +				     "\"minimal\", \"patience\" and \"histogram\"");
>> +		/* clear out previous settings */
>> +		DIFF_XDL_CLR(options, NEED_MINIMAL);
>> +		options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
>> +		options->xdl_opts |= value;
> 
> This makes me wonder if other places that use DIFF_WITH_ALG() also
> need to worry about clearing NEED_MINIMAL?
> 

Not really. In my approach, --minimal looks at yet another algorithm. However, current code sees it as orthogonal to the myers algorithm. The flag doesn't have any effect on --patience or --histogram at all.

So I think we need to clear the flag only when using --diff-algorithm.
Michal
Previous: Junio C Hamano
Message 9 of 9 in “Rework git-diff algorithm selection”
  1. 0/3 Rework git-diff algorithm selectionMichal Privoznik, Jan 14, 2013
  2. 1/3 git-completion.bash: Autocomplete --minimal and --histogram for git-diffMichal Privoznik, Jan 14, 2013
  3. 2/3 config: Introduce diff.algorithm variableMichal Privoznik, Jan 14, 2013
  4. Junio C HamanoJan 14, 2013
  5. Jeff KingJan 15, 2013
  6. Junio C HamanoJan 15, 2013
  7. 3/3 diff: Introduce --diff-algorithm command line optionMichal Privoznik, Jan 14, 2013
  8. Junio C HamanoJan 14, 2013
  9. Michal PrivoznikJan 15, 2013

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.