t4201: make use of abbreviation in the test more robust
[gitweb.git] / builtin / merge-file.c
index ab4330a3d0b0099c37acf12dbb3d02bd06b74287..13e22a2f0be73ec7e521a02d1f36c414e77a8700 100644 (file)
@@ -5,7 +5,7 @@
 #include "parse-options.h"
 
 static const char *const merge_file_usage[] = {
-       N_("git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2"),
+       N_("git merge-file [<options>] [-L <name1> [-L <orig> [-L <name2>]]] <file1> <orig-file> <file2>"),
        NULL
 };
 
@@ -42,7 +42,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
                            N_("for conflicts, use this marker size")),
                OPT__QUIET(&quiet, N_("do not warn about conflicts")),
                OPT_CALLBACK('L', NULL, names, N_("name"),
-                            N_("set labels for file1/orig_file/file2"), &label_cb),
+                            N_("set labels for file1/orig-file/file2"), &label_cb),
                OPT_END(),
        };
 
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
                usage_with_options(merge_file_usage, options);
        if (quiet) {
                if (!freopen("/dev/null", "w", stderr))
-                       return error("failed to redirect stderr to /dev/null: "
-                                    "%s", strerror(errno));
+                       return error_errno("failed to redirect stderr to /dev/null");
        }
 
        if (prefix)
@@ -75,7 +74,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
                        names[i] = argv[i];
                if (read_mmfile(mmfs + i, fname))
                        return -1;
-               if (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
+               if (mmfs[i].size > MAX_XDIFF_SIZE ||
+                   buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
                        return error("Cannot merge binary files: %s",
                                        argv[i]);
        }
@@ -90,15 +90,17 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 
        if (ret >= 0) {
                const char *filename = argv[0];
-               FILE *f = to_stdout ? stdout : fopen(filename, "wb");
+               const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);
+               FILE *f = to_stdout ? stdout : fopen(fpath, "wb");
 
                if (!f)
-                       ret = error("Could not open %s for writing", filename);
+                       ret = error_errno("Could not open %s for writing",
+                                         filename);
                else if (result.size &&
                         fwrite(result.ptr, result.size, 1, f) != 1)
-                       ret = error("Could not write to %s", filename);
+                       ret = error_errno("Could not write to %s", filename);
                else if (fclose(f))
-                       ret = error("Could not close %s", filename);
+                       ret = error_errno("Could not close %s", filename);
                free(result.ptr);
        }