Skip to content

Commit

Permalink
Revert "v.util: improve color_compare_files (#21243)"
Browse files Browse the repository at this point in the history
This reverts commit bfd53a9.
It restores the ability to use diff.find_working_diff_command() and
customise the result with VDIFF_TOOL and VDIFF_OPTIONS.
  • Loading branch information
spytheman committed Apr 10, 2024
1 parent bfd53a9 commit 056a443
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions vlib/v/util/diff/diff.v
Expand Up @@ -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 {
Expand Down

0 comments on commit 056a443

Please sign in to comment.