Skip to content

Commit

Permalink
v.util: improve detection for opendiff when automatically searching d…
Browse files Browse the repository at this point in the history
…ifftools (#21241)
  • Loading branch information
ttytm authored Apr 10, 2024
1 parent 056a443 commit b832b96
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions vlib/v/util/diff/diff.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ pub fn find_working_diff_command() !string {
'code', 'code.cmd']
// NOTE: code.cmd is the Windows variant of the `code` cli tool
for diffcmd in known_diff_tools {
if diffcmd == 'opendiff' { // opendiff has no `--version` option
if opendiff_exists() {
return diffcmd
}
continue
if diffcmd == 'opendiff' {
os.find_abs_path_of_executable('opendiff') or { continue }
return diffcmd
}
$if freebsd || openbsd {
if diffcmd == 'diff' { // FreeBSD/OpenBSD diff have no `--version` option
Expand Down Expand Up @@ -51,20 +49,6 @@ pub fn find_working_diff_command() !string {
return error('No working "diff" command found')
}

// determine if the FileMerge opendiff tool is available
fn opendiff_exists() bool {
o := os.execute('opendiff')
if o.exit_code < 0 {
return false
}
if o.exit_code == 1 { // failed (expected), but found (i.e. not 127)
if o.output.contains('too few arguments') { // got some expected output
return true
}
}
return false
}

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)} '
Expand Down

0 comments on commit b832b96

Please sign in to comment.