Use "diif --help" to find out if diff is available at all. Otherwise the

return code from "could not find command" which is 1, conflicts with return
code from diff failed, which is also 1.
parent 03d31f72
...@@ -1313,12 +1313,26 @@ void show_diff(DYNAMIC_STRING* ds, ...@@ -1313,12 +1313,26 @@ void show_diff(DYNAMIC_STRING* ds,
const char* filename1, const char* filename2) const char* filename1, const char* filename2)
{ {
const char* diff_failed= 0;
DYNAMIC_STRING ds_tmp; DYNAMIC_STRING ds_tmp;
if (init_dynamic_string(&ds_tmp, "", 256, 256)) if (init_dynamic_string(&ds_tmp, "", 256, 256))
die("Out of memory"); die("Out of memory");
/* First try with diff --help to see if the command exists at all */
if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */
"--help",
"2>&1",
NULL) != 0) /* Most "diff --help" tools return 0 */
{
diff_failed= "You don't appear to have diff installed";
}
else
{
/* First try with unified diff */ /* First try with unified diff */
if (run_tool("diff", if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */ &ds_tmp, /* Get output from diff in ds_tmp */
"-u", "-u",
...@@ -1337,18 +1351,26 @@ void show_diff(DYNAMIC_STRING* ds, ...@@ -1337,18 +1351,26 @@ void show_diff(DYNAMIC_STRING* ds,
filename2, filename2,
"2>&1", "2>&1",
NULL) > 1) /* Most "diff" tools return >1 if error */ NULL) > 1) /* Most "diff" tools return >1 if error */
{
dynstr_set(&ds_tmp, "");
diff_failed= "Could not execute 'diff -u' or 'diff -c'";
}
}
}
if (diff_failed)
{ {
/* /*
Fallback to dump both files to result file and inform Fallback to dump both files to result file and inform
about installing "diff" about installing "diff"
*/ */
dynstr_set(&ds_tmp, ""); dynstr_append(&ds_tmp, "\n");
dynstr_append(&ds_tmp, diff_failed);
dynstr_append(&ds_tmp, dynstr_append(&ds_tmp,
"\n" "\n"
"The two files differ but it was not possible to execute 'diff' in\n" "The two files differ but it was not possible to execute 'diff' in\n"
"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" "order to show only the difference. Instead the whole content of the\n"
"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" "two files was shown for you to diff manually.\n\n"
"To get a better report you should install 'diff' on your system, which you\n" "To get a better report you should install 'diff' on your system, which you\n"
"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" "for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n"
#ifdef __WIN__ #ifdef __WIN__
...@@ -1366,7 +1388,6 @@ void show_diff(DYNAMIC_STRING* ds, ...@@ -1366,7 +1388,6 @@ void show_diff(DYNAMIC_STRING* ds,
cat_file(&ds_tmp, filename2); cat_file(&ds_tmp, filename2);
dynstr_append(&ds_tmp, "<<<<\n"); dynstr_append(&ds_tmp, "<<<<\n");
} }
}
if (ds) if (ds)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment