Skip to content

Commit

Permalink
Merge branch 'difftool-no-index'
Browse files Browse the repository at this point in the history
This fixes git-for-windows#2123

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed May 8, 2019
2 parents 59a40ee + 89dfd5d commit 860e652
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Documentation/technical/api-parse-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ There are some macros to easily define options:
The filename will be prefixed by passing the filename along with
the prefix argument of `parse_options()` to `prefix_filename()`.

`OPT_ARGUMENT(long, description)`::
`OPT_ARGUMENT(long, &int_var, description)`::
Introduce a long-option argument that will be kept in `argv[]`.
If this option was seen, `int_var` will be set to one (except
if a `NULL` pointer was passed).

`OPT_NUMBER_CALLBACK(&var, description, func_ptr)`::
Recognize numerical options like -123 and feed the integer as
Expand Down
14 changes: 10 additions & 4 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix,
int cmd_difftool(int argc, const char **argv, const char *prefix)
{
int use_gui_tool = 0, dir_diff = 0, prompt = -1, symlinks = 0,
tool_help = 0;
tool_help = 0, no_index = 0;
static char *difftool_cmd = NULL, *extcmd = NULL;
struct option builtin_difftool_options[] = {
OPT_BOOL('g', "gui", &use_gui_tool,
Expand All @@ -714,6 +714,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
"tool returns a non - zero exit code")),
OPT_STRING('x', "extcmd", &extcmd, N_("command"),
N_("specify a custom command for viewing diffs")),
OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")),
OPT_END()
};

Expand All @@ -727,9 +728,14 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
if (tool_help)
return print_tool_help();

/* NEEDSWORK: once we no longer spawn anything, remove this */
setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
if (!no_index && !startup_info->have_repository)
die(_("difftool requires worktree or --no-index"));

if (!no_index){
setup_work_tree();
setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
}

if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
Expand Down
2 changes: 1 addition & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static struct cmd_struct commands[] = {
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
{ "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
{ "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
{ "difftool", cmd_difftool, RUN_SETUP | NEED_WORK_TREE },
{ "difftool", cmd_difftool, RUN_SETUP_GENTLY },
{ "fast-export", cmd_fast_export, RUN_SETUP },
{ "fetch", cmd_fetch, RUN_SETUP },
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },
Expand Down
2 changes: 2 additions & 0 deletions parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
optname(options, flags));
if (*rest)
continue;
if (options->value)
*(int *)options->value = options->defval;
p->out[p->cpidx++] = arg - 2;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ struct option {
#define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f)

#define OPT_END() { OPTION_END }
#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
(h), PARSE_OPT_NOARG}
#define OPT_ARGUMENT(l, v, h) { OPTION_ARGUMENT, 0, (l), (v), NULL, \
(h), PARSE_OPT_NOARG, NULL, 1 }
#define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
#define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \
Expand Down
2 changes: 1 addition & 1 deletion t/helper/test-parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int cmd__parse_options(int argc, const char **argv)
OPT_NOOP_NOARG(0, "obsolete"),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
OPT_GROUP("Magic arguments"),
OPT_ARGUMENT("quux", "means --quux"),
OPT_ARGUMENT("quux", NULL, "means --quux"),
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
number_callback),
{ OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
Expand Down
10 changes: 10 additions & 0 deletions t/t7800-difftool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
test_cmp expect actual
'

test_expect_success 'outside worktree' '
echo 1 >1 &&
echo 2 >2 &&
test_expect_code 1 nongit git \
-c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \
difftool --no-prompt --no-index --ext-diff ../1 ../2 >actual &&
echo "../1 ../2" >expect &&
test_cmp expect actual
'

test_done

0 comments on commit 860e652

Please sign in to comment.