Skip to content

Commit a97262c

Browse files
pcloudsgitster
authored andcommitted
diff: make -O and --output work in subdirectory
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5f7a5d commit a97262c

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16531653

16541654
init_revisions(&rev_info, NULL);
16551655
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
1656-
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1);
1656+
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
16571657
add_pending_sha1(&rev_info, "HEAD", our_tree, 0);
16581658
diff_setup_done(&rev_info.diffopt);
16591659
run_diff_index(&rev_info, 1);

diff-no-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ void diff_no_index(struct rev_info *revs,
254254
else if (!strcmp(argv[i], "--"))
255255
i++;
256256
else {
257-
j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
257+
j = diff_opt_parse(&revs->diffopt, argv + i, argc - i,
258+
revs->prefix);
258259
if (j <= 0)
259260
die("invalid diff option/value: %s", argv[i]);
260261
i += j;

diff.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,12 +3695,16 @@ static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
36953695
return 1;
36963696
}
36973697

3698-
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3698+
int diff_opt_parse(struct diff_options *options,
3699+
const char **av, int ac, const char *prefix)
36993700
{
37003701
const char *arg = av[0];
37013702
const char *optarg;
37023703
int argcount;
37033704

3705+
if (!prefix)
3706+
prefix = "";
3707+
37043708
/* Output format options */
37053709
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
37063710
|| opt_arg(arg, 'U', "unified", &options->context))
@@ -3917,7 +3921,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
39173921
else if (!strcmp(arg, "--pickaxe-regex"))
39183922
options->pickaxe_opts |= DIFF_PICKAXE_REGEX;
39193923
else if ((argcount = short_opt('O', av, &optarg))) {
3920-
options->orderfile = optarg;
3924+
const char *path = prefix_filename(prefix, strlen(prefix), optarg);
3925+
options->orderfile = xstrdup(path);
39213926
return argcount;
39223927
}
39233928
else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
@@ -3956,9 +3961,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
39563961
else if (!strcmp(arg, "--no-function-context"))
39573962
DIFF_OPT_CLR(options, FUNCCONTEXT);
39583963
else if ((argcount = parse_long_opt("output", av, &optarg))) {
3959-
options->file = fopen(optarg, "w");
3964+
const char *path = prefix_filename(prefix, strlen(prefix), optarg);
3965+
options->file = fopen(path, "w");
39603966
if (!options->file)
3961-
die_errno("Could not open '%s'", optarg);
3967+
die_errno("Could not open '%s'", path);
39623968
options->close_file = 1;
39633969
return argcount;
39643970
} else

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ extern int parse_long_opt(const char *opt, const char **argv,
268268
extern int git_diff_basic_config(const char *var, const char *value, void *cb);
269269
extern int git_diff_ui_config(const char *var, const char *value, void *cb);
270270
extern void diff_setup(struct diff_options *);
271-
extern int diff_opt_parse(struct diff_options *, const char **, int);
271+
extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
272272
extern void diff_setup_done(struct diff_options *);
273273

274274
#define DIFF_DETECT_RENAME 1

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
20492049
} else if (!strcmp(arg, "--ignore-missing")) {
20502050
revs->ignore_missing = 1;
20512051
} else {
2052-
int opts = diff_opt_parse(&revs->diffopt, argv, argc);
2052+
int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
20532053
if (!opts)
20542054
unkv[(*unkc)++] = arg;
20552055
return opts;

t/t4056-diff-order.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ test_expect_success POSIXPERM,SANITY 'unreadable orderfile' '
6868
test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD
6969
'
7070

71+
test_expect_success "orderfile using option from subdir with --output" '
72+
mkdir subdir &&
73+
git -C subdir diff -O../order_file_1 --output ../actual --name-only HEAD^..HEAD &&
74+
test_cmp expect_1 actual
75+
'
76+
7177
for i in 1 2
7278
do
7379
test_expect_success "orderfile using option ($i)" '

0 commit comments

Comments
 (0)