Resurrect "git apply --flags -" to read from the standard input
The previous "parse-opt"ification broke git-apply reading from the standard input. "git apply A - C <B" is supposed to read patches from files A, B and C in this order. Before "parse-opt"ification, we used be able to: git apply --stat - --apply <A B to read the patch from file A, showing only the diffstat, and then read the patch from file B, showing the diffstat and actually applying it. Even with this fix we cannot do that anymore, but that is so crazy use case I do not think anybody sane relied on such a broken behaviour. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 9, 2009 at 22:21 UTC
64912a67a43dec151906b93f96b07f16e17f71e9
2 files changed
+31
-14
builtin-apply.c
+5
-14
@@ -3140,16 +3140,6 @@ static int git_apply_config(const char *var, const char *value, void *cb)
3140
return git_default_config(var, value, cb);
3141
}
3142
3143
-static int option_parse_stdin(const struct option *opt,
3144
- const char *arg, int unset)
3145
-{
3146
- int *errs = opt->value;
3147
-
3148
- *errs |= apply_patch(0, "<stdin>", options);
3149
- read_stdin = 0;
3150
- return 0;
3151
-}
3152
-
3143
static int option_parse_exclude(const struct option *opt,
3144
const char *arg, int unset)
3145
{
@@ -3218,9 +3208,6 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3208
const char *whitespace_option = NULL;
3209
3210
struct option builtin_apply_options[] = {
3221
- { OPTION_CALLBACK, '-', NULL, &errs, NULL,
3222
- "read the patch from the standard input",
3223
- PARSE_OPT_NOARG, option_parse_stdin },
3211
{ OPTION_CALLBACK, 0, "exclude", NULL, "path",
3212
"don´t apply changes matching the given path",
3213
0, option_parse_exclude },
@@ -3302,7 +3289,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
3289
const char *arg = argv[i];
3290
int fd;
3291
3305
- if (0 < prefix_length)
3292
+ if (!strcmp(arg, "-")) {
3293
+ errs |= apply_patch(0, "<stdin>", options);
3294
+ read_stdin = 0;
3295
+ continue;
3296
+ } else if (0 < prefix_length)
3297
arg = prefix_filename(prefix, prefix_length, arg);
3298
3299
fd = open(arg, O_RDONLY);
t/t4106-apply-stdin.sh
new
+26
@@ -0,0 +1,26 @@
1
+#!/bin/sh
2
+
3
+test_description='git apply --numstat - <patch'
4
+
5
+. ./test-lib.sh
6
+
7
+test_expect_success setup '
8
+ echo hello >text &&
9
+ git add text &&
10
+ echo goodbye >text &&
11
+ git diff >patch
12
+'
13
+
14
+test_expect_success 'git apply --numstat - < patch' '
15
+ echo "1 1 text" >expect &&
16
+ git apply --numstat - <patch >actual &&
17
+ test_cmp expect actual
18
+'
19
+
20
+test_expect_success 'git apply --numstat - < patch patch' '
21
+ for i in 1 2; do echo "1 1 text"; done >expect &&
22
+ git apply --numstat - < patch patch >actual &&
23
+ test_cmp expect actual
24
+'
25
+
26
+test_done