Merge branch 'bp/status-rename-config'

"git status" learned to honor a new status.renames configuration to
skip rename detection, which could be useful for those who want to
do so without disabling the default rename detection done by the
"git diff" command.

* bp/status-rename-config:
  add status config and command line options for rename detection
This commit is contained in:
Junio C Hamano
2018-05-30 14:04:07 +09:00
6 changed files with 192 additions and 1 deletions

View File

@ -143,6 +143,16 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
return 0;
}
static int opt_parse_rename_score(const struct option *opt, const char *arg, int unset)
{
const char **value = opt->value;
if (arg != NULL && *arg == '=')
arg = arg + 1;
*value = arg;
return 0;
}
static void determine_whence(struct wt_status *s)
{
if (file_exists(git_path_merge_head()))
@ -1259,11 +1269,31 @@ static int git_status_config(const char *k, const char *v, void *cb)
return error(_("Invalid untracked files mode '%s'"), v);
return 0;
}
if (!strcmp(k, "diff.renamelimit")) {
if (s->rename_limit == -1)
s->rename_limit = git_config_int(k, v);
return 0;
}
if (!strcmp(k, "status.renamelimit")) {
s->rename_limit = git_config_int(k, v);
return 0;
}
if (!strcmp(k, "diff.renames")) {
if (s->detect_rename == -1)
s->detect_rename = git_config_rename(k, v);
return 0;
}
if (!strcmp(k, "status.renames")) {
s->detect_rename = git_config_rename(k, v);
return 0;
}
return git_diff_ui_config(k, v, NULL);
}
int cmd_status(int argc, const char **argv, const char *prefix)
{
static int no_renames = -1;
static const char *rename_score_arg = (const char *)-1;
static struct wt_status s;
int fd;
struct object_id oid;
@ -1297,6 +1327,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
OPT_BOOL(0, "no-renames", &no_renames, N_("do not detect renames")),
{ OPTION_CALLBACK, 'M', "find-renames", &rename_score_arg,
N_("n"), N_("detect renames, optionally set similarity index"),
PARSE_OPT_OPTARG, opt_parse_rename_score },
OPT_END(),
};
@ -1336,6 +1370,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
s.ignore_submodule_arg = ignore_submodule_arg;
s.status_format = status_format;
s.verbose = verbose;
if (no_renames != -1)
s.detect_rename = !no_renames;
if ((intptr_t)rename_score_arg != -1) {
if (s.detect_rename < DIFF_DETECT_RENAME)
s.detect_rename = DIFF_DETECT_RENAME;
if (rename_score_arg)
s.rename_score = parse_rename_score(&rename_score_arg);
}
wt_status_collect(&s);