git-apply --verbose
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Aug 18, 2006 at 03:14 UTC
a2bf404e280b8d56d0efa15bd9700464cf8f0d4d
2 files changed
+84
-2
builtin-apply.c
+36
-2
@@ -39,12 +39,13 @@ static int check;
39
static int apply = 1;
40
static int apply_in_reverse;
41
static int apply_with_reject;
42
+static int apply_verbosely;
43
static int no_add;
44
static int show_index_info;
45
static int line_termination = '\n';
46
static unsigned long p_context = -1;
47
static const char apply_usage[] =
47
-"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
48
+"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
49
50
static enum whitespace_eol {
51
nowarn_whitespace,
@@ -153,6 +154,24 @@ struct patch {
154
struct patch *next;
155
};
156
157
+static void say_patch_name(FILE *output, const char *pre, struct patch *patch, const char *post)
158
+{
159
+ fputs(pre, output);
160
+ if (patch->old_name && patch->new_name &&
161
+ strcmp(patch->old_name, patch->new_name)) {
162
+ write_name_quoted(NULL, 0, patch->old_name, 1, output);
163
+ fputs(" => ", output);
164
+ write_name_quoted(NULL, 0, patch->new_name, 1, output);
165
+ }
166
+ else {
167
+ const char *n = patch->new_name;
168
+ if (!n)
169
+ n = patch->old_name;
170
+ write_name_quoted(NULL, 0, n, 1, output);
171
+ }
172
+ fputs(post, output);
173
+}
174
+
175
#define CHUNKSIZE (8192)
176
#define SLOP (16)
177
@@ -1928,6 +1947,9 @@ static int check_patch_list(struct patch *patch)
1947
int error = 0;
1948
1949
for (prev_patch = NULL; patch ; patch = patch->next) {
1950
+ if (apply_verbosely)
1951
+ say_patch_name(stderr,
1952
+ "Checking patch ", patch, "...\n");
1953
error |= check_patch(patch, prev_patch);
1954
prev_patch = patch;
1955
}
@@ -2253,8 +2275,12 @@ static int write_out_one_reject(struct patch *patch)
2275
cnt++;
2276
}
2277
2256
- if (!cnt)
2278
+ if (!cnt) {
2279
+ if (apply_verbosely)
2280
+ say_patch_name(stderr,
2281
+ "Applied patch ", patch, " cleanly.\n");
2282
return 0;
2283
+ }
2284
2285
/* This should not happen, because a removal patch that leaves
2286
* contents are marked "rejected" at the patch level.
@@ -2262,6 +2288,10 @@ static int write_out_one_reject(struct patch *patch)
2288
if (!patch->new_name)
2289
die("internal error");
2290
2291
+ /* Say this even without --verbose */
2292
+ say_patch_name(stderr, "Applying patch ", patch, " with");
2293
+ fprintf(stderr, " %d rejects...\n", cnt);
2294
+
2295
cnt = strlen(patch->new_name);
2296
if (ARRAY_SIZE(namebuf) <= cnt + 5) {
2297
cnt = ARRAY_SIZE(namebuf) - 5;
@@ -2530,6 +2560,10 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2560
apply = apply_with_reject = 1;
2561
continue;
2562
}
2563
+ if (!strcmp(arg, "--verbose")) {
2564
+ apply_verbosely = 1;
2565
+ continue;
2566
+ }
2567
if (!strcmp(arg, "--inaccurate-eof")) {
2568
inaccurate_eof = 1;
2569
continue;
t/t4117-apply-reject.sh
+48
@@ -57,6 +57,17 @@ test_expect_success 'apply without --reject should fail' '
57
diff -u file1 saved.file1
58
'
59
60
+test_expect_success 'apply without --reject should fail' '
61
+
62
+ if git apply --verbose patch.1
63
+ then
64
+ echo "Eh? Why?"
65
+ exit 1
66
+ fi
67
+
68
+ diff -u file1 saved.file1
69
+'
70
+
71
test_expect_success 'apply with --reject should fail but update the file' '
72
73
cat saved.file1 >file1 &&
@@ -106,4 +117,41 @@ test_expect_success 'apply with --reject should fail but update the file' '
117
118
'
119
120
+test_expect_success 'the same test with --verbose' '
121
+
122
+ cat saved.file1 >file1 &&
123
+ rm -f file1.rej file2.rej file2 &&
124
+
125
+ if git apply --reject --verbose patch.2 >rejects
126
+ then
127
+ echo "succeeds with --reject?"
128
+ exit 1
129
+ fi
130
+
131
+ test -f file1 && {
132
+ echo "file1 still exists?"
133
+ exit 1
134
+ }
135
+ diff -u file2 expected &&
136
+
137
+ cat file2.rej &&
138
+
139
+ if test -f file1.rej
140
+ then
141
+ echo "file2 should not have been touched"
142
+ exit 1
143
+ fi
144
+
145
+'
146
+
147
+test_expect_success 'apply cleanly with --verbose' '
148
+
149
+ git cat-file -p HEAD:file1 >file1 &&
150
+ rm -f file?.rej file2 &&
151
+
152
+ git apply --verbose patch.1 &&
153
+
154
+ diff -u file1 clean
155
+'
156
+
157
test_done