Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.util: improve code related to diff tool specified via environment, add check if the diff tool exists #21240

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions vlib/v/util/diff/diff.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ pub fn find_working_diff_command() !string {
env_difftool := os.getenv('VDIFF_TOOL')
env_diffopts := os.getenv('VDIFF_OPTIONS')
if env_difftool != '' {
os.find_abs_path_of_executable(env_difftool) or {
return error('could not find specified VDIFF_TOOL `${env_difftool}`')
}
return '${env_difftool} ${env_diffopts}'
}
mut known_diff_tools := []string{}
if env_difftool.len > 0 {
known_diff_tools << env_difftool
}
known_diff_tools << ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff',
'code', 'code.cmd']
// NOTE: code.cmd is the Windows variant of the `code` cli tool
known_diff_tools := ['colordiff', 'gdiff', 'diff', 'colordiff.exe', 'diff.exe', 'opendiff',
'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() {
Expand All @@ -30,15 +28,10 @@ pub fn find_working_diff_command() !string {
return diffcmd
}
}

p := os.execute('${diffcmd} --version')
if p.exit_code < 0 {
continue
}
if p.exit_code == 127 && diffcmd == env_difftool {
// user setup is wonky, fix it
return error('could not find specified VDIFF_TOOL ${diffcmd}')
}
if p.exit_code == 0 { // success
if diffcmd in ['code', 'code.cmd'] {
// there is no guarantee that the env opts exist
Expand Down