From 056a44378c3984b8c369385234638e9d530c0f48 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 10 Apr 2024 09:21:02 +0300 Subject: [PATCH] Revert "v.util: improve `color_compare_files` (#21243)" This reverts commit bfd53a9b3855e9675058e9fd59576079c38ebfe3. It restores the ability to use diff.find_working_diff_command() and customise the result with VDIFF_TOOL and VDIFF_OPTIONS. --- vlib/v/util/diff/diff.v | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/vlib/v/util/diff/diff.v b/vlib/v/util/diff/diff.v index c011f19b251960..cf5dac06f36a03 100644 --- a/vlib/v/util/diff/diff.v +++ b/vlib/v/util/diff/diff.v @@ -65,19 +65,22 @@ fn opendiff_exists() bool { return false } -pub fn color_compare_files(diff_cmd string, path1 string, path2 string) string { - os.find_abs_path_of_executable(diff_cmd) or { - return 'comparison command: `${diff_cmd}` not found' - } - flags := $if openbsd { - ['-d', '-a', '-U', '2'] - } $else $if freebsd { - ['--minimal', '--text', '--unified=2'] - } $else { - ['--minimal', '--text', '--unified=2', '--show-function-line="fn "'] +pub fn color_compare_files(diff_cmd string, file1 string, file2 string) string { + if diff_cmd != '' { + mut full_cmd := '${diff_cmd} --minimal --text --unified=2 --show-function-line="fn " ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + $if freebsd { + full_cmd = '${diff_cmd} --minimal --text --unified=2 ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + } + $if openbsd { + full_cmd = '${diff_cmd} -d -a -U 2 ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' + } + x := os.execute(full_cmd) + if x.exit_code < 0 { + return 'comparison command: `${full_cmd}` not found' + } + return x.output.trim_right('\r\n') } - full_cmd := '${diff_cmd} ${flags.join(' ')} ${os.quoted_path(path1)} ${os.quoted_path(path2)}' - return os.execute(full_cmd).output.trim_right('\r\n') + return '' } pub fn color_compare_strings(diff_cmd string, unique_prefix string, expected string, found string) string {