[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

Nikolaos Chatzikonstantinou via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 2 14:13:49 PST 2025


createyourpersonalaccount wrote:

> > > From #123921, it seems that you only want the new option to work with `--staged`, but should it also work with other options that may print a list of filenames?
> > 
> > 
> > I don't know; I only use `git clang-format` as in #123921 and I am not familiar with all its uses. I was hoping that you or someone other who is familiar could determine this.
> > What worries me is conditions where more than one list of files is printed, e.g. unchanged + changed files. It's difficult to parse these messages from the shell; when a null-separated list is printed from other command line utilities, it has one meaning, e.g. "here's the list of files you asked for", whereas `git clang-format` prints other diagnostics too.
> > If someone is familiar with the usages of this tool maybe they can tell me what is the logic that must be followed in terms of **which list** is the important one according to the options passed, so that only that list is printed with `--print0`.
> 
> It seems that `git-clang-format` was not designed for its output to be consumed by another utility as it prints everything to `stdout` instead of `stderr`. Adding an option like`--print0` (especially just for `--staged`) looks odd to me.

No, the approach of printing to `stderr` for utilities is not accurate. I've heard of this before, even the claim that this is the original UNIX way, but it's not. I don't know the origin of this [cargo-culting](https://en.wikipedia.org/wiki/Cargo_cult) factoid but I assure you that it does not hold true. (The origin I suspect may be Microsoft with its Powershell, i.e. see [about_Output_Streams](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.5)) There is a lot of value in `--null` since it allows `git clang-format` to be used in git hooks. Why would a Python script designed as a git subcommand not work well with git?

https://github.com/llvm/llvm-project/pull/123926


More information about the cfe-commits mailing list