From: Duy Nguyen <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Re: [PATCH 2/7] diff.c: take "prefix" argument in diff_opt_parse()
Date: Thu, 21 Jan 2016 18:48:44 +0700 [thread overview]
Message-ID: <20160121114844.GA19318@lanh> (raw)
In-Reply-To: <xmqqh9i753by.fsf@gitster.mtv.corp.google.com>
On Wed, Jan 20, 2016 at 01:49:21PM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > On Wed, Jan 20, 2016 at 12:23:38PM -0800, Junio C Hamano wrote:
> >
> >> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> >>
> >> > This will be important later when diff_opt_parse() accepts paths as
> >> > arguments. Paths must be prefixed before access because setup code
> >> > moves cwd but does not (and cannot) update command line options.
> >>
> >> The above sounds like a sensible thing to do (note: I didn't read
> >> the patch or remainder of the series), but makes me wonder how the
> >> existing --orderfile option works without this support. Perhaps it
> >> is not working and needs to be updated to take advantage of this
> >> change, too?
> >
> > Yeah, I think it simply does not work.
> >
> > $ >main-order
> > $ mkdir subdir && >subdir/sub-order
> > $ cd subdir
> > $ git show -Osub-order
> > fatal: failed to read orderfile 'sub-order': No such file or directory
> > $ git show -Omain-order
> > [shows diff]
>
> Good.
>
> Then 2/7 can be rerolled and advertised as "make -O to work from
> subdirectories", and can gradulate regardless of the remainder of
> the series. Even if the rest needs rerolls to get it right (or
> takes until 2019 to mature ;-), we will have one less change to
> re-review in the process as we can push these early and obviously
> correct part out separately.
>
I didn't know there was already an option that takes a path. I read
through the function and found another one. So here's the standalone
patch that fixes both.
-- 8< --
Subject: [PATCH] diff: make -O and --output work in subdirectory
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/am.c | 2 +-
diff-no-index.c | 3 ++-
diff.c | 14 ++++++++++----
diff.h | 2 +-
revision.c | 2 +-
t/t4056-diff-order.sh | 6 ++++++
6 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 9fb42fd..f009b6c 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1657,7 +1657,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);
diff --git a/diff-no-index.c b/diff-no-index.c
index 8e0fd27..aa81a15 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -252,7 +252,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 80eb0c2..2136b69 100644
--- a/diff.c
+++ b/diff.c
@@ -3693,12 +3693,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))
@@ -3915,7 +3919,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))) {
@@ -3954,9 +3959,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 893f446..4537e38 100644
--- 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
diff --git a/revision.c b/revision.c
index 0a282f5..14daefb 100644
--- a/revision.c
+++ b/revision.c
@@ -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;
diff --git a/t/t4056-diff-order.sh b/t/t4056-diff-order.sh
index c0460bb..43dd474 100755
--- a/t/t4056-diff-order.sh
+++ b/t/t4056-diff-order.sh
@@ -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)" '
--
2.7.0.125.g9eec362
-- 8< --
next prev parent reply other threads:[~2016-01-21 11:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-20 11:06 [PATCH 0/7] Diff rename, manual correction, round 2 Nguyễn Thái Ngọc Duy
2016-01-20 11:06 ` [PATCH 1/7] diff-no-index: do not take a redundant prefix argument Nguyễn Thái Ngọc Duy
2016-01-20 11:06 ` [PATCH 2/7] diff.c: take "prefix" argument in diff_opt_parse() Nguyễn Thái Ngọc Duy
2016-01-20 20:23 ` Junio C Hamano
2016-01-20 20:29 ` Jeff King
2016-01-20 21:49 ` Junio C Hamano
2016-01-21 11:48 ` Duy Nguyen [this message]
2016-01-21 23:01 ` Junio C Hamano
2016-01-20 11:06 ` [PATCH 3/7] diff: add --rename-file Nguyễn Thái Ngọc Duy
2016-01-20 22:44 ` Junio C Hamano
2016-01-20 22:47 ` Junio C Hamano
2016-01-20 11:06 ` [PATCH 4/7] log: add --rename-notes to correct renames per commit Nguyễn Thái Ngọc Duy
2016-01-20 23:29 ` Junio C Hamano
2016-01-22 1:00 ` Duy Nguyen
2016-01-20 11:06 ` [PATCH 5/7] merge: add --rename-file Nguyễn Thái Ngọc Duy
2016-01-20 11:06 ` [PATCH 6/7] diffcore-rename: allow to say "rename this blob to that blob" Nguyễn Thái Ngọc Duy
2016-01-20 11:06 ` [PATCH 7/7] merge: add --rename-notes Nguyễn Thái Ngọc Duy
2016-01-21 17:53 ` Junio C Hamano
2016-01-22 3:35 ` Duy Nguyen
2016-01-22 17:17 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160121114844.GA19318@lanh \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).