Skip to content

Commit

Permalink
Resurrect "git apply --flags -" to read from the standard input
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 10, 2009
1 parent f26c494 commit 64912a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
19 changes: 5 additions & 14 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions t/t4106-apply-stdin.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 64912a6

Please sign in to comment.