diff: make -O and --output work in subdirectory
authorDuy Nguyen <pclouds@gmail.com>
Thu, 21 Jan 2016 11:48:44 +0000 (18:48 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Jan 2016 18:45:13 +0000 (10:45 -0800)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c
diff-no-index.c
diff.c
diff.h
revision.c
t/t4056-diff-order.sh
index 4e396c832139aa3c4ae4e68e9d265b0107817aa9..919bd91b0ffc87c9b6857fa8ad761d39d70c9e56 100644 (file)
@@ -1653,7 +1653,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
 
                init_revisions(&rev_info, NULL);
                rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
-               diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1);
+               diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
                add_pending_sha1(&rev_info, "HEAD", our_tree, 0);
                diff_setup_done(&rev_info.diffopt);
                run_diff_index(&rev_info, 1);
index 8edc6f36906d2d9d052790ac5eef0a3ca6121d0e..95057b7a7f2651d351ef569488d646c983ecdb75 100644 (file)
@@ -254,7 +254,8 @@ void diff_no_index(struct rev_info *revs,
                else if (!strcmp(argv[i], "--"))
                        i++;
                else {
-                       j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
+                       j = diff_opt_parse(&revs->diffopt, argv + i, argc - i,
+                                          revs->prefix);
                        if (j <= 0)
                                die("invalid diff option/value: %s", argv[i]);
                        i += j;
diff --git a/diff.c b/diff.c
index 46260ed7a1d521cf95342caff83a825b34959bdc..93e9533389fc087317453993376e304e70d571ad 100644 (file)
--- 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
diff --git a/diff.h b/diff.h
index f61ee5494b46f40d1f9a5632746f1f9dc9accf2e..76b5536edb4a1079ff4e30f96699f9ed2fcbe2c5 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -268,7 +268,7 @@ extern int parse_long_opt(const char *opt, const char **argv,
 extern int git_diff_basic_config(const char *var, const char *value, void *cb);
 extern int git_diff_ui_config(const char *var, const char *value, void *cb);
 extern void diff_setup(struct diff_options *);
-extern int diff_opt_parse(struct diff_options *, const char **, int);
+extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
 extern void diff_setup_done(struct diff_options *);
 
 #define DIFF_DETECT_RENAME     1
index e0107738b7ad4faa8c5937f4589d306382d65030..47e38b6c4648373c58d5d659838101a55e4b79d5 100644 (file)
@@ -2049,7 +2049,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (!strcmp(arg, "--ignore-missing")) {
                revs->ignore_missing = 1;
        } else {
-               int opts = diff_opt_parse(&revs->diffopt, argv, argc);
+               int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
                if (!opts)
                        unkv[(*unkc)++] = arg;
                return opts;
index c0460bb0e59c42de179fc6cbe0f3702a3b538a8e..43dd474a12e97945d38de00f7ab99f30d73490ea 100755 (executable)
@@ -68,6 +68,12 @@ test_expect_success POSIXPERM,SANITY 'unreadable orderfile' '
        test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD
 '
 
+test_expect_success "orderfile using option from subdir with --output" '
+       mkdir subdir &&
+       git -C subdir diff -O../order_file_1 --output ../actual --name-only HEAD^..HEAD &&
+       test_cmp expect_1 actual
+'
+
 for i in 1 2
 do
        test_expect_success "orderfile using option ($i)" '