Skip to content

Commit fbe0b24

Browse files
dschoJunio C Hamano
authored andcommitted
merge-file: support -p and -q; fix compile warnings
Now merge-file also understands --stdout and --quiet options. While at it, two compile warnings were fixed. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent ba1f5f3 commit fbe0b24

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

builtin-merge-file.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "xdiff/xdiff.h"
33

44
static const char merge_file_usage[] =
5-
"git merge-file [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
5+
"git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
66

77
static int read_file(mmfile_t *ptr, const char *filename)
88
{
@@ -27,16 +27,23 @@ int cmd_merge_file(int argc, char **argv, char **envp)
2727
mmfile_t mmfs[3];
2828
mmbuffer_t result = {NULL, 0};
2929
xpparam_t xpp = {XDF_NEED_MINIMAL};
30-
int ret = 0, i = 0;
30+
int ret = 0, i = 0, to_stdout = 0;
3131

3232
while (argc > 4) {
33-
if (!strcmp(argv[1], "-L")) {
33+
if (!strcmp(argv[1], "-L") && i < 3) {
3434
names[i++] = argv[2];
35-
argc -= 2;
36-
argv += 2;
37-
continue;
38-
}
39-
usage(merge_file_usage);
35+
argc--;
36+
argv++;
37+
} else if (!strcmp(argv[1], "-p") ||
38+
!strcmp(argv[1], "--stdout"))
39+
to_stdout = 1;
40+
else if (!strcmp(argv[1], "-q") ||
41+
!strcmp(argv[1], "--quiet"))
42+
freopen("/dev/null", "w", stderr);
43+
else
44+
usage(merge_file_usage);
45+
argc--;
46+
argv++;
4047
}
4148

4249
if (argc != 4)
@@ -57,7 +64,7 @@ int cmd_merge_file(int argc, char **argv, char **envp)
5764

5865
if (ret >= 0) {
5966
char *filename = argv[1];
60-
FILE *f = fopen(filename, "wb");
67+
FILE *f = to_stdout ? stdout : fopen(filename, "wb");
6168

6269
if (!f)
6370
ret = error("Could not open %s for writing", filename);

0 commit comments

Comments
 (0)