prefix_filename: drop length parameter
This function takes the prefix as a ptr/len pair, but in every caller the length is exactly strlen(ptr). Let's simplify the interface and just take the string. This saves callers specifying it (and in some cases handling a NULL prefix). In a handful of cases we had the length already without calling strlen, so this is technically slower. But it's not likely to matter (after all, if the prefix is non-empty we'll allocate and copy it into a buffer anyway). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
598019769c
commit
116fb64e43
@ -28,7 +28,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
|
||||
xmparam_t xmp = {{0}};
|
||||
int ret = 0, i = 0, to_stdout = 0;
|
||||
int quiet = 0;
|
||||
int prefixlen = 0;
|
||||
struct option options[] = {
|
||||
OPT_BOOL('p', "stdout", &to_stdout, N_("send results to standard output")),
|
||||
OPT_SET_INT(0, "diff3", &xmp.style, N_("use a diff3 based merge"), XDL_MERGE_DIFF3),
|
||||
@ -65,11 +64,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
|
||||
return error_errno("failed to redirect stderr to /dev/null");
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
prefixlen = strlen(prefix);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
const char *fname = prefix_filename(prefix, prefixlen, argv[i]);
|
||||
const char *fname = prefix_filename(prefix, argv[i]);
|
||||
if (!names[i])
|
||||
names[i] = argv[i];
|
||||
if (read_mmfile(mmfs + i, fname))
|
||||
@ -90,7 +86,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
|
||||
|
||||
if (ret >= 0) {
|
||||
const char *filename = argv[0];
|
||||
const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);
|
||||
const char *fpath = prefix_filename(prefix, argv[0]);
|
||||
FILE *f = to_stdout ? stdout : fopen(fpath, "wb");
|
||||
|
||||
if (!f)
|
||||
|
Reference in New Issue
Block a user