git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Jonas Fonseca" <jonas.fonseca@gmail.com>
Cc: "Miklos Vajna" <vmiklos@frugalware.org>, git@vger.kernel.org
Subject: Re: What's cooking in git.git (Jan 2009, #01; Mon, 05)
Date: Fri, 09 Jan 2009 22:15:59 -0800	[thread overview]
Message-ID: <7vr63by9cw.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <2c6b72b30901092015l2405627aqf928e43c12eabc3c@mail.gmail.com> (Jonas Fonseca's message of "Fri, 9 Jan 2009 23:15:37 -0500")

"Jonas Fonseca" <jonas.fonseca@gmail.com> writes:

> 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

  reply	other threads:[~2009-01-10  6:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06  6:33 What's cooking in git.git (Jan 2009, #01; Mon, 05) Junio C Hamano
2009-01-10  4:15 ` Jonas Fonseca
2009-01-10  6:15   ` Junio C Hamano [this message]
2009-01-10 13:08     ` Miklos Vajna
2009-01-10 15:10     ` Jonas Fonseca

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=7vr63by9cw.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonas.fonseca@gmail.com \
    --cc=vmiklos@frugalware.org \
    /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).