Skip to content

Conversation

dbarnett
Copy link
Contributor

Also make version check logic a little more explicit and fix quirks for empty version or comparing shorter versions.

Resolves a ShellError bug when invoking some versions of the clang-format tool that return non-zero exit code, and instead makes it so if the tool returns a parseable version number it will be used regardless of exit code.

The material change was just updating .Call() to .Call(0), but I refactored the version check logic a little in the process to make sure the scenario of empty version number is handled properly. Also adjusts the logic for comparing versions of mismatched lengths to pad version with zeros instead of checking length only, which could false negative on long min version values.

Fixes #84 .

Also make version check logic a little more explicit and fix quirks for
empty version or comparing shorter versions.

Fixes #84.
Copy link
Contributor

@agriffis agriffis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

return 0
endif
" Compare each dotted version value in turn.
let l:length = max([len(a:minimum_version), len(s:clang_format_version)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional change from min to max?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see the change in the loop below, nevermind

return 0
endif
endfor
return len(a:minimum_version) <= len(s:clang_format_version)
" All version numbers were equal, so version was at least minimum.
return 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version comparison code feels like something that would be useful as a general helper, eventually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. We do have something similar in maktaba#IsAtLeastVersion, but without the variable length.

OTOH, often code that's checking versions is also low-level code that's awkward to have depending on libraries, but doesn't hurt to make an implementation available, at any rate.

@dbarnett dbarnett merged commit d3d8b8b into master Apr 1, 2020
@dbarnett dbarnett deleted the clangformat_exitcode branch July 29, 2020 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error formatting file: ERROR(ShellError): Error running: clang-format --version
3 participants