Re: What's cooking in git.git (Jan 2009, #01; Mon, 05)
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 10, 2009, 06:15 UTC
- Message-ID
- <7vr63by9cw.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <2c6b72b30901092015l2405627aqf928e43c12eabc3c@mail.gmail.com>
"Jonas Fonseca" <jonas.fonseca@gmail.com> writes:
Show 11 quoted lines
> On Tue, Jan 6, 2009 at 01:33, Junio C Hamano <gitster@pobox.com> wrote: >> ---------------------------------------------------------------- >> * mv/apply-parse-opt (Sun Dec 28 00:03:57 2008 +0100) 1 commit >> + parse-opt: migrate builtin-apply. > > This broke apply for me after updating to the current "next" earlier > today. When requesting that the patch be read from stdin I get the > following error message: > > > git diff | git apply -R - > fatal: can't open patch '-': No such file or directory
Thanks. I think this patch would fix it.
Because the original option parser was incremental and immediate with respect to "-", we used to be able to say:
$ git apply -p - --stat patch2.txt <patch1.txt
and the use of parseopt breaks such usage, even after this fix.
But I think it is a bit too crazy to support such backward compatibility.
builtin-apply.c | 19 +++++-------------- t/t4106-apply-stdin.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-)
diff --git c/builtin-apply.c w/builtin-apply.c index cb988a3..2811c0f 100644 --- c/builtin-apply.c +++ w/builtin-apply.c @@ -3140,16 +3140,6 @@ static int git_apply_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } -static int option_parse_stdin(const struct option *opt, - const char *arg, int unset) -{ - int *errs = opt->value; - - *errs |= apply_patch(0, "<stdin>", options); - read_stdin = 0; - return 0; -} - static int option_parse_exclude(const struct option *opt, const char *arg, int unset) { @@ -3218,9 +3208,6 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) const char *whitespace_option = NULL; struct option builtin_apply_options[] = { - { OPTION_CALLBACK, '-', NULL, &errs, NULL, - "read the patch from the standard input", - PARSE_OPT_NOARG, option_parse_stdin }, { OPTION_CALLBACK, 0, "exclude", NULL, "path", "don´t apply changes matching the given path", 0, option_parse_exclude }, @@ -3302,7 +3289,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) const char *arg = argv[i]; int fd; - if (0 < prefix_length) + if (!strcmp(arg, "-")) { + errs |= apply_patch(0, "<stdin>", options); + read_stdin = 0; + continue; + } else if (0 < prefix_length) arg = prefix_filename(prefix, prefix_length, arg); fd = open(arg, O_RDONLY); diff --git c/t/t4106-apply-stdin.sh w/t/t4106-apply-stdin.sh new file mode 100755 index 0000000..72467a1 --- /dev/null +++ w/t/t4106-apply-stdin.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='git apply --numstat - <patch' + +. ./test-lib.sh + +test_expect_success setup ' + echo hello >text && + git add text && + echo goodbye >text && + git diff >patch +' + +test_expect_success 'git apply --numstat - < patch' ' + echo "1 1 text" >expect && + git apply --numstat - <patch >actual && + test_cmp expect actual +' + +test_expect_success 'git apply --numstat - < patch patch' ' + for i in 1 2; do echo "1 1 text"; done >expect && + git apply --numstat - < patch patch >actual && + test_cmp expect actual +' + +test_done