Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff: implement config.diff.renames=copies-harder #1606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Documentation/config/diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ diff.renames::
Whether and how Git detects renames. If set to "false",
rename detection is disabled. If set to "true", basic rename
detection is enabled. If set to "copies" or "copy", Git will
detect copies, as well. Defaults to true. Note that this
detect copies, as well. If set to "copies-harder", Git will try harder
to detect copies. Defaults to true. Note that this
affects only 'git diff' Porcelain like linkgit:git-diff[1] and
linkgit:git-log[1], and not lower level commands such as
linkgit:git-diff-files[1].
Expand Down
3 changes: 2 additions & 1 deletion Documentation/config/status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ status.renames::
Whether and how Git detects renames in linkgit:git-status[1] and
linkgit:git-commit[1] . If set to "false", rename detection is
disabled. If set to "true", basic rename detection is enabled.
If set to "copies" or "copy", Git will detect copies, as well.
If set to "copies" or "copy", Git will detect copies, as well. If
set to "copies-harder", Git will try harder to detect copies.
Defaults to the value of diff.renames.

status.showStash::
Expand Down
12 changes: 9 additions & 3 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ int git_config_rename(const char *var, const char *value)
{
if (!value)
return DIFF_DETECT_RENAME;
if (!strcasecmp(value, "copies-harder"))
return DIFF_DETECT_COPY_HARDER;
if (!strcasecmp(value, "copies") || !strcasecmp(value, "copy"))
return DIFF_DETECT_COPY;
return DIFF_DETECT_COPY;

return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0;
}

Expand Down Expand Up @@ -4832,8 +4835,11 @@ void diff_setup_done(struct diff_options *options)
else
options->flags.diff_from_contents = 0;

if (options->flags.find_copies_harder)
/* Just fold this in as it makes the patch-to-git smaller */
if (options->flags.find_copies_harder || options->detect_rename == DIFF_DETECT_COPY_HARDER) {
options->flags.find_copies_harder = 1;
options->detect_rename = DIFF_DETECT_COPY;
}

if (!options->flags.relative_name)
options->prefix = NULL;
Expand Down Expand Up @@ -5264,7 +5270,7 @@ static int diff_opt_find_copies(const struct option *opt,
if (*arg != 0)
return error(_("invalid argument to %s"), opt->long_name);

if (options->detect_rename == DIFF_DETECT_COPY)
if (options->detect_rename == DIFF_DETECT_COPY || options->detect_rename == DIFF_DETECT_COPY_HARDER)
options->flags.find_copies_harder = 1;
else
options->detect_rename = DIFF_DETECT_COPY;
Expand Down
1 change: 1 addition & 0 deletions diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ int git_config_rename(const char *var, const char *value);

#define DIFF_DETECT_RENAME 1
#define DIFF_DETECT_COPY 2
#define DIFF_DETECT_COPY_HARDER 3

#define DIFF_PICKAXE_ALL 1
#define DIFF_PICKAXE_REGEX 2
Expand Down
4 changes: 2 additions & 2 deletions diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static int find_identical_files(struct hashmap *srcs,
}
/* Give higher scores to sources that haven't been used already */
score = !source->rename_used;
if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY && options->detect_rename != DIFF_DETECT_COPY_HARDER)
continue;
score += basename_same(source, target);
if (score > best_score) {
Expand Down Expand Up @@ -1405,7 +1405,7 @@ void diffcore_rename_extended(struct diff_options *options,
trace2_region_enter("diff", "setup", options->repo);
info.setup = 0;
assert(!dir_rename_count || strmap_empty(dir_rename_count));
want_copies = (detect_rename == DIFF_DETECT_COPY);
want_copies = (detect_rename == DIFF_DETECT_COPY || detect_rename == DIFF_DETECT_COPY_HARDER);
if (dirs_removed && (break_idx || want_copies))
BUG("dirs_removed incompatible with break/copy detection");
if (break_idx && relevant_sources)
Expand Down
2 changes: 1 addition & 1 deletion merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -4782,7 +4782,7 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
* sanity check them anyway.
*/
assert(opt->detect_renames >= -1 &&
opt->detect_renames <= DIFF_DETECT_COPY);
opt->detect_renames <= DIFF_DETECT_COPY_HARDER);
assert(opt->verbosity >= 0 && opt->verbosity <= 5);
assert(opt->buffer_output <= 2);
assert(opt->obuf.len == 0);
Expand Down
2 changes: 1 addition & 1 deletion merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ static int merge_start(struct merge_options *opt, struct tree *head)
assert(opt->branch1 && opt->branch2);

assert(opt->detect_renames >= -1 &&
opt->detect_renames <= DIFF_DETECT_COPY);
opt->detect_renames <= DIFF_DETECT_COPY_HARDER);
assert(opt->detect_directory_renames >= MERGE_DIRECTORY_RENAMES_NONE &&
opt->detect_directory_renames <= MERGE_DIRECTORY_RENAMES_TRUE);
assert(opt->rename_limit >= -1);
Expand Down