New proposed function `clang-format-vc-diff`.
It is the same as calling `clang-format-region` on all diffs between
the content of a buffer-file and the content of the file at git
revision HEAD. This is essentially the same thing as:
`git-clang-format -f {filename}`
If the current buffer is saved.
The motivation is many project (LLVM included) both have code that is
non-compliant with there clang-format style and disallow unrelated
format diffs in PRs. This means users can't just run
`clang-format-buffer` on the buffer they are working on, and need to
manually go through all the regions by hand to get them
formatted. This is both an error prone and annoying workflow.
The trampoline script used on Windows (due to the absence of shebang
support) doesn't properly expand the path to the Python script, as it
leaves out the drive letter.
Functionally equivalent reproducer in action
```
PS C:\Users\mate> gc (gcm git-clang-formatish.bat).Source
@ECHO OFF
echo "%~pn0" %*
PS C:\Users\mate> git-clang-formatish
"\Users\mate\git-clang-formatish"
```
Adding `d` to the variable modifiers [as per the
docs](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/for)
the drive letter is added. Even in the magical cases when it works.
(I couldn't reproduce, but I suspect it's only tested from some
bash/cygwin variant, where the path becomes `/c/Program Files/...`, but
the drive letter is needed. Without it, I also observed cases when used
via `git clang-format` (without the inital dash) it tries to infer the
drive letter based on the current working directory. In that case it
fails to find `D:\Program Files\LLVM\bin\clang-format.exe`, which
naturally fails, because `Program Files` is on `C:`)
Add an minor mode which can be optionally used to run clang-format on
save.
Formatting before saving works well and is convenient to avoid having to
remember to manually run clang format.
I've written this as it's own package but it's probably better if the
functionality is supported by clang-format.el.
See: https://github.com/melpa/melpa/pull/8762
With the --force (or -f) option, git-clang-format wipes out input files
excluded by a .clang-format-ignore file if they have unstaged changes.
This patch adds a hidden clang-format option --list-ignored that lists
such excluded files for git-clang-format to filter out.
Fixes#102459.
To support auto-conversion on z/OS text files need to be opened as text files. These changes will fix a number of LIT failures due to text files not being converted to the internal code page.
update a number of tools so they open the text files as text files
add support in the cat.py to open a text file as a text file (Windows will continue to treat all files as binary so new lines are handled correctly)
add env var definitions to enable auto-conversion in the lit config file.
At the moment clang-format will return exit code 0 on incomplete
results. In scripts it would sometimes be useful if clang-format would
instead fail in those cases, signalling that there was something wrong
with the code being formatted.
---------
Co-authored-by: Björn Schäpers <github@hazardy.de>
Co-authored-by: Owen Pan <owenpiano@gmail.com>
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. See
github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444
We should use a tool like Visual Studio to clean up the headers.
This reverts commit c69ec700adec315b3daa55742f2ef655242fa297, which has been
obsolete since commit dec63221d56e because the clang-format style was added
in version 18.
Commit d813af73f70f addressed a regression introduced by commit
3791b3fca6ea
but caused `clang-format -dump-config` to "hang".
This patch reverts changes to ClangFormat.cpp by both commits and
reworks the cleanup.
Fixes#80621.
The code cleanup in #74794 accidentally broke detection of languages by
reading file content from stdin, e.g. via `clang-format -dump-config - <
/path/to/filename`.
This PR adds unit and integration tests to reproduce the issue and adds
a fix.
Fixes: #79023
The current CI doesn't use the latest clang-format and fails most
clang-format patches on the code formatting check. This patch
temporarily removes the clang-format style from the .clang-format
files.
(42ec976184ac was reverted by 26993f61673e due to a use-after-scope bug.)
Reuse the patterns governing the previous input file being formatted if
the current input file is from the same directory.
This reverts commit 42ec976184acd40436acd7104ad715c60ca3e7ed.
Reason: Broke the sanitizer buildbots. See more information on the
github comment thread at
42ec976184
This patch adds in the ability to do a "three dot" git-clang-format
between two commits. This looks at the diff between the second commit
and the common merge base rather than comparing at the point of the
specified commits. This is needed to improve the reliability of the LLVM
code formatting CI action which currently breaks in some cases where
files have been modified in the upstream tree and when the person
created their branch, leaving phantom formatting diffs that weren't
touched by the PR author.
Part of a fix for #73873
This is a rework of #74176, which erroneously changed the default
clang-format filename (`clang-format`, `clang-format.exe`, etc.) to an
absolute pathname. Instead, we should do that only if the name is a
pathname, e.g. `./clang-format`,
`llvm-project/build/bin/clang-format.exe`, etc. See also
https://github.com/llvm/llvm-project/pull/74176#issuecomment-1837921351.
It is quite common to symlink clang-format-diff.py to clang-format-diff,
and in that case the help output still refers to the .py version.
Compute it instead to work in both setup.
This patch adds the ability for the clang-format-diff script to exit
with a non-zero status if it detects that formatting changes are
necessary. This makes it easier to use clang-format-diff as part of a
DevOps pipeline, since you could add a stage to run clang-format-diff
and fail if the formatting needs to be fixed.
This allows git-clang-format to be used on a Windows terminal without
manually needing to find the path and invoke the python interpreter. We
have a similar script for `scan-build`.
Fixes#69643
When applying format changes to staged files, git-clang-format
erroneously checks out all files in the index and thus may overwrite
unstaged changes.
Fixes#65643.