userdiff: add and use struct external_diff
Wrap the string specifying the external diff command in a new struct to simplify adding attributes, which the next patch will do. Make sure external_diff() still returns NULL if neither the environment variable GIT_EXTERNAL_DIFF nor the configuration option diff.external is set, to continue allowing its use in a boolean context. Use a designated initializer for the default builtin userdiff driver to adjust to the type change of the second struct member. Spelling out only the non-zero members improves readability as a nice side-effect. No functional change intended. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
33be6cf51a
commit
54443bbfc3
32
diff.c
32
diff.c
@ -57,7 +57,7 @@ static int diff_color_moved_ws_default;
|
|||||||
static int diff_context_default = 3;
|
static int diff_context_default = 3;
|
||||||
static int diff_interhunk_context_default;
|
static int diff_interhunk_context_default;
|
||||||
static char *diff_word_regex_cfg;
|
static char *diff_word_regex_cfg;
|
||||||
static char *external_diff_cmd_cfg;
|
static struct external_diff external_diff_cfg;
|
||||||
static char *diff_order_file_cfg;
|
static char *diff_order_file_cfg;
|
||||||
int diff_auto_refresh_index = 1;
|
int diff_auto_refresh_index = 1;
|
||||||
static int diff_mnemonic_prefix;
|
static int diff_mnemonic_prefix;
|
||||||
@ -431,7 +431,7 @@ int git_diff_ui_config(const char *var, const char *value,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "diff.external"))
|
if (!strcmp(var, "diff.external"))
|
||||||
return git_config_string(&external_diff_cmd_cfg, var, value);
|
return git_config_string(&external_diff_cfg.cmd, var, value);
|
||||||
if (!strcmp(var, "diff.wordregex"))
|
if (!strcmp(var, "diff.wordregex"))
|
||||||
return git_config_string(&diff_word_regex_cfg, var, value);
|
return git_config_string(&diff_word_regex_cfg, var, value);
|
||||||
if (!strcmp(var, "diff.orderfile"))
|
if (!strcmp(var, "diff.orderfile"))
|
||||||
@ -548,18 +548,20 @@ static char *quote_two(const char *one, const char *two)
|
|||||||
return strbuf_detach(&res, NULL);
|
return strbuf_detach(&res, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *external_diff(void)
|
static const struct external_diff *external_diff(void)
|
||||||
{
|
{
|
||||||
static const char *external_diff_cmd = NULL;
|
static struct external_diff external_diff_env, *external_diff_ptr;
|
||||||
static int done_preparing = 0;
|
static int done_preparing = 0;
|
||||||
|
|
||||||
if (done_preparing)
|
if (done_preparing)
|
||||||
return external_diff_cmd;
|
return external_diff_ptr;
|
||||||
external_diff_cmd = xstrdup_or_null(getenv("GIT_EXTERNAL_DIFF"));
|
external_diff_env.cmd = xstrdup_or_null(getenv("GIT_EXTERNAL_DIFF"));
|
||||||
if (!external_diff_cmd)
|
if (external_diff_env.cmd)
|
||||||
external_diff_cmd = external_diff_cmd_cfg;
|
external_diff_ptr = &external_diff_env;
|
||||||
|
else if (external_diff_cfg.cmd)
|
||||||
|
external_diff_ptr = &external_diff_cfg;
|
||||||
done_preparing = 1;
|
done_preparing = 1;
|
||||||
return external_diff_cmd;
|
return external_diff_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4375,7 +4377,7 @@ static void add_external_diff_name(struct repository *r,
|
|||||||
* infile2 infile2-sha1 infile2-mode [ rename-to ]
|
* infile2 infile2-sha1 infile2-mode [ rename-to ]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void run_external_diff(const char *pgm,
|
static void run_external_diff(const struct external_diff *pgm,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *other,
|
const char *other,
|
||||||
struct diff_filespec *one,
|
struct diff_filespec *one,
|
||||||
@ -4386,7 +4388,7 @@ static void run_external_diff(const char *pgm,
|
|||||||
struct child_process cmd = CHILD_PROCESS_INIT;
|
struct child_process cmd = CHILD_PROCESS_INIT;
|
||||||
struct diff_queue_struct *q = &diff_queued_diff;
|
struct diff_queue_struct *q = &diff_queued_diff;
|
||||||
|
|
||||||
strvec_push(&cmd.args, pgm);
|
strvec_push(&cmd.args, pgm->cmd);
|
||||||
strvec_push(&cmd.args, name);
|
strvec_push(&cmd.args, name);
|
||||||
|
|
||||||
if (one && two) {
|
if (one && two) {
|
||||||
@ -4512,7 +4514,7 @@ static void fill_metainfo(struct strbuf *msg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_diff_cmd(const char *pgm,
|
static void run_diff_cmd(const struct external_diff *pgm,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *other,
|
const char *other,
|
||||||
const char *attr_path,
|
const char *attr_path,
|
||||||
@ -4530,8 +4532,8 @@ static void run_diff_cmd(const char *pgm,
|
|||||||
if (o->flags.allow_external || !o->ignore_driver_algorithm)
|
if (o->flags.allow_external || !o->ignore_driver_algorithm)
|
||||||
drv = userdiff_find_by_path(o->repo->index, attr_path);
|
drv = userdiff_find_by_path(o->repo->index, attr_path);
|
||||||
|
|
||||||
if (o->flags.allow_external && drv && drv->external)
|
if (o->flags.allow_external && drv && drv->external.cmd)
|
||||||
pgm = drv->external;
|
pgm = &drv->external;
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
/*
|
/*
|
||||||
@ -4597,7 +4599,7 @@ static void strip_prefix(int prefix_length, const char **namep, const char **oth
|
|||||||
|
|
||||||
static void run_diff(struct diff_filepair *p, struct diff_options *o)
|
static void run_diff(struct diff_filepair *p, struct diff_options *o)
|
||||||
{
|
{
|
||||||
const char *pgm = external_diff();
|
const struct external_diff *pgm = external_diff();
|
||||||
struct strbuf msg;
|
struct strbuf msg;
|
||||||
struct diff_filespec *one = p->one;
|
struct diff_filespec *one = p->one;
|
||||||
struct diff_filespec *two = p->two;
|
struct diff_filespec *two = p->two;
|
||||||
|
@ -333,7 +333,7 @@ PATTERNS("scheme",
|
|||||||
"|([^][)(}{[ \t])+"),
|
"|([^][)(}{[ \t])+"),
|
||||||
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
|
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
|
||||||
"\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
|
"\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
|
||||||
{ "default", NULL, NULL, -1, { NULL, 0 } },
|
{ .name = "default", .binary = -1 },
|
||||||
};
|
};
|
||||||
#undef PATTERNS
|
#undef PATTERNS
|
||||||
#undef IPATTERN
|
#undef IPATTERN
|
||||||
@ -445,7 +445,7 @@ int userdiff_config(const char *k, const char *v)
|
|||||||
if (!strcmp(type, "binary"))
|
if (!strcmp(type, "binary"))
|
||||||
return parse_tristate(&drv->binary, k, v);
|
return parse_tristate(&drv->binary, k, v);
|
||||||
if (!strcmp(type, "command"))
|
if (!strcmp(type, "command"))
|
||||||
return git_config_string(&drv->external, k, v);
|
return git_config_string(&drv->external.cmd, k, v);
|
||||||
if (!strcmp(type, "textconv"))
|
if (!strcmp(type, "textconv"))
|
||||||
return git_config_string(&drv->textconv, k, v);
|
return git_config_string(&drv->textconv, k, v);
|
||||||
if (!strcmp(type, "cachetextconv"))
|
if (!strcmp(type, "cachetextconv"))
|
||||||
|
@ -11,9 +11,13 @@ struct userdiff_funcname {
|
|||||||
int cflags;
|
int cflags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct external_diff {
|
||||||
|
char *cmd;
|
||||||
|
};
|
||||||
|
|
||||||
struct userdiff_driver {
|
struct userdiff_driver {
|
||||||
const char *name;
|
const char *name;
|
||||||
char *external;
|
struct external_diff external;
|
||||||
char *algorithm;
|
char *algorithm;
|
||||||
int binary;
|
int binary;
|
||||||
struct userdiff_funcname funcname;
|
struct userdiff_funcname funcname;
|
||||||
|
Reference in New Issue
Block a user