summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorDuy Nguyen <pclouds@gmail.com>2016-01-21 11:48:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-01-21 18:45:13 (GMT)
commita97262c62f1a31fcc7edf7629d313058bc7d66b5 (patch)
tree96f459828c6adbb05998b7fca180fef22bf41a7f /diff.c
parente5f7a5d16f2c890e7dda96e5681ee8f6687b45e4 (diff)
downloadgit-a97262c62f1a31fcc7edf7629d313058bc7d66b5.zip
git-a97262c62f1a31fcc7edf7629d313058bc7d66b5.tar.gz
git-a97262c62f1a31fcc7edf7629d313058bc7d66b5.tar.bz2
diff: make -O and --output work in subdirectory
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/diff.c b/diff.c
index 46260ed..93e9533 100644
--- a/diff.c
+++ b/diff.c
@@ -3695,12 +3695,16 @@ static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
return 1;
}
-int diff_opt_parse(struct diff_options *options, const char **av, int ac)
+int diff_opt_parse(struct diff_options *options,
+ const char **av, int ac, const char *prefix)
{
const char *arg = av[0];
const char *optarg;
int argcount;
+ if (!prefix)
+ prefix = "";
+
/* Output format options */
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
|| opt_arg(arg, 'U', "unified", &options->context))
@@ -3917,7 +3921,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
else if (!strcmp(arg, "--pickaxe-regex"))
options->pickaxe_opts |= DIFF_PICKAXE_REGEX;
else if ((argcount = short_opt('O', av, &optarg))) {
- options->orderfile = optarg;
+ const char *path = prefix_filename(prefix, strlen(prefix), optarg);
+ options->orderfile = xstrdup(path);
return argcount;
}
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)
else if (!strcmp(arg, "--no-function-context"))
DIFF_OPT_CLR(options, FUNCCONTEXT);
else if ((argcount = parse_long_opt("output", av, &optarg))) {
- options->file = fopen(optarg, "w");
+ const char *path = prefix_filename(prefix, strlen(prefix), optarg);
+ options->file = fopen(path, "w");
if (!options->file)
- die_errno("Could not open '%s'", optarg);
+ die_errno("Could not open '%s'", path);
options->close_file = 1;
return argcount;
} else