Merge branch 'tr/maint-merge-file-subdir'
* tr/maint-merge-file-subdir: merge-file: correctly find files when called in subdir prefix_filename(): safely handle the case where pfx_len=0
This commit is contained in:
commit
ba0254cb32
@ -28,6 +28,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
|
|||||||
xmparam_t xmp = {{0}};
|
xmparam_t xmp = {{0}};
|
||||||
int ret = 0, i = 0, to_stdout = 0;
|
int ret = 0, i = 0, to_stdout = 0;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
|
int prefixlen = 0;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
|
OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
|
||||||
OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
|
OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
|
||||||
@ -65,10 +66,14 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
|
|||||||
"%s\n", strerror(errno));
|
"%s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
prefixlen = strlen(prefix);
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
|
const char *fname = prefix_filename(prefix, prefixlen, argv[i]);
|
||||||
if (!names[i])
|
if (!names[i])
|
||||||
names[i] = argv[i];
|
names[i] = argv[i];
|
||||||
if (read_mmfile(mmfs + i, argv[i]))
|
if (read_mmfile(mmfs + i, fname))
|
||||||
return -1;
|
return -1;
|
||||||
if (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
|
if (buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
|
||||||
return error("Cannot merge binary files: %s\n",
|
return error("Cannot merge binary files: %s\n",
|
||||||
|
4
setup.c
4
setup.c
@ -46,7 +46,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
|
|||||||
{
|
{
|
||||||
static char path[PATH_MAX];
|
static char path[PATH_MAX];
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (!pfx || !*pfx || is_absolute_path(arg))
|
if (!pfx_len || is_absolute_path(arg))
|
||||||
return arg;
|
return arg;
|
||||||
memcpy(path, pfx, pfx_len);
|
memcpy(path, pfx, pfx_len);
|
||||||
strcpy(path + pfx_len, arg);
|
strcpy(path + pfx_len, arg);
|
||||||
@ -55,7 +55,7 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
|
|||||||
/* don't add prefix to absolute paths, but still replace '\' by '/' */
|
/* don't add prefix to absolute paths, but still replace '\' by '/' */
|
||||||
if (is_absolute_path(arg))
|
if (is_absolute_path(arg))
|
||||||
pfx_len = 0;
|
pfx_len = 0;
|
||||||
else
|
else if (pfx_len)
|
||||||
memcpy(path, pfx, pfx_len);
|
memcpy(path, pfx, pfx_len);
|
||||||
strcpy(path + pfx_len, arg);
|
strcpy(path + pfx_len, arg);
|
||||||
for (p = path + pfx_len; *p; p++)
|
for (p = path + pfx_len; *p; p++)
|
||||||
|
@ -64,6 +64,14 @@ cp new1.txt test.txt
|
|||||||
test_expect_success "merge without conflict" \
|
test_expect_success "merge without conflict" \
|
||||||
"git merge-file test.txt orig.txt new2.txt"
|
"git merge-file test.txt orig.txt new2.txt"
|
||||||
|
|
||||||
|
test_expect_success 'works in subdirectory' '
|
||||||
|
mkdir dir &&
|
||||||
|
cp new1.txt dir/a.txt &&
|
||||||
|
cp orig.txt dir/o.txt &&
|
||||||
|
cp new2.txt dir/b.txt &&
|
||||||
|
( cd dir && git merge-file a.txt o.txt b.txt )
|
||||||
|
'
|
||||||
|
|
||||||
cp new1.txt test.txt
|
cp new1.txt test.txt
|
||||||
test_expect_success "merge without conflict (--quiet)" \
|
test_expect_success "merge without conflict (--quiet)" \
|
||||||
"git merge-file --quiet test.txt orig.txt new2.txt"
|
"git merge-file --quiet test.txt orig.txt new2.txt"
|
||||||
|
Loading…
Reference in New Issue
Block a user