339 Commits

Author SHA1 Message Date
Owen Pan
4b86a7f386 [clang-format] Update the minimum python version requirement
See https://llvm.org/docs/GettingStarted.html#software

Fix #131456
2025-03-16 16:42:19 -07:00
Ron Gut
d0170424b7
[emacs][clang-format] Suppress reference to free variable errors (#126254)
vc-git-program is referenced but not defined -- vc-git provides the
definition.
2025-02-07 11:04:24 -05:00
goldsteinn
32be90db26
[emacs][clang-format] Add elisp API for clang-format on git diffs (#112792)
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.
2025-02-04 17:17:43 -06:00
Owen Pan
e25c556abe [clang-format][NFC] Reformat git-clang-format with black -l80 2024-12-05 23:18:24 -08:00
Owen Pan
fb2cbc00e0 [clang-format] Reformat Python script git-clang-format with black 2024-12-05 20:26:02 -08:00
Jim B
56ab56c857
[clang-format] Add support for .cjs as JavaScript file extension (#118188)
Node uses `.cjs` as an extension for 'common javascript' modules.
2024-12-03 09:03:51 -08:00
루밀LuMir
6c7b988e64
[clang-format] Add mjs to default_extensions in git-clang-format (#117730) 2024-11-26 22:56:25 -08:00
Owen Pan
b9731a479c [clang-format][doc] Minor cleanup 2024-11-24 23:15:39 -08:00
Nagy-Egri Máté Ferenc
362273d143
[clang-format] Fix path expansion inside git-clang-format.bat (#114078)
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:`)
2024-10-30 00:51:11 -07:00
Owen Pan
801f3a5400
[clang-format] Print the names of unfound files in error messages (#113640)
Also fix the return status when `-i` is used with reading from stdin.

Fixes #113631.
2024-10-25 19:29:21 -07:00
Simon Pilgrim
f24c1dd08e Fix MSVC "signed/unsigned mismatch" warning. NFC. 2024-10-25 18:11:28 +01:00
kakkoko
efd8938d57
[clang-format] Fix working -assume-filename with .clang-format-ignore (#113100)
Fixes #113099.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-10-24 18:13:08 -07:00
Campbell Barton
093d4db2f3
Add "clang-format-on-save-mode" minor mode to clang-format.el (#104533)
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
2024-10-19 22:09:06 +02:00
Owen Pan
85df28180b
[clang-format] Fix a bug that always returns error for JSON (#112839)
Fixes #108556.
2024-10-18 21:10:00 -07:00
Owen Pan
12c0823d67
[clang-format] Handle spaces in file paths in git-clang-format.bat (#107041)
This patch is provided by @jeliebig.

Fixes #107017.
2024-09-03 19:06:40 -07:00
c8ef
4f4bd41f70
[NFC] Fix typos (#106817)
Fixes #106761.
2024-08-31 19:12:57 -07:00
Danial Klimkin
158ba731c9
Fix clang-format-test.el past 625841c (#106398) 2024-08-28 16:00:50 +02:00
MarcoFalke
fac484ccc6
[clang-format-diff.py][NFC] Document _stderr as unused
The stderr in the result tuple is always None and unused in this
context.

Document it with an underscore.
2024-08-27 11:07:17 +02:00
magic-akari
625841c3be
[clang-format] Use double hyphen for multiple-letter flags (#100978)
- Closes: #100974
2024-08-21 18:22:21 +02:00
Owen Pan
986bc3d071
[clang-format] Fix a serious bug in git clang-format -f (#102629)
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.
2024-08-10 13:31:35 -07:00
Owen Pan
9fa17fea3c
[clang-format] Handle parenthesized list in RemoveParentheses (#100852)
Also, reformat clang-format source to remove redundant parentheses
enclosing single list items.

Fixes #100768.
2024-08-02 01:29:05 -07:00
Nour
c967c7e022
[clang-format][NFC] Remove an else after a return statement (#94548) 2024-06-06 18:36:33 -07:00
Owen Pan
1c58208d89 [clang-format][NFC] Remove redundnat llvm::, clang::, etc. 2024-05-20 20:32:18 -07:00
Owen Pan
b11a6607cb [clang-format][NFC] Reformat with 18.1.5 2024-05-15 21:04:46 -07:00
Sean Perry
e22ce615fe
[z/OS] treat text files as text files so auto-conversion is done (#90128)
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.
2024-05-01 10:39:41 -04:00
Jing Wang
6dbd4bb3b4
Add txtpb to the list of supported TextProto extensions (#88355)
According to
https://protobuf.dev/reference/protobuf/textformat-spec/#text-format-files,
txtpb is the canonical extension

Co-authored-by: Jing Wang <99jingw@gmail.com>
2024-04-12 21:41:06 +02:00
Owen Pan
d9e3e11ae5
[clang-format] Exit clang-format-diff only after all diffs are printed (#86776)
See
https://github.com/llvm/llvm-project/pull/70883#issuecomment-2020811077.
2024-03-27 21:23:37 -07:00
Roberto Bampi
a29e9e32c5
[clang-format] Add --fail-on-incomplete-format. (#84346)
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>
2024-03-21 01:29:25 -07:00
Owen Pan
b2082a9817 Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"
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.
2024-03-19 21:28:22 -07:00
Owen Pan
b92d6dd704 [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files 2024-03-16 22:24:11 -07:00
Owen Pan
5ac784d1d0 Revert "[clang-format][NFC] Don't use clang-format style in config files"
This reverts commit c69ec700adec315b3daa55742f2ef655242fa297, which has been
obsolete since commit dec63221d56e because the clang-format style was added
in version 18.
2024-03-16 02:39:37 -07:00
Owen Pan
8f6e13e6da
[clang-format] Fix a regression in dumping the config (#80628)
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.
2024-02-07 21:35:43 -08:00
Ben Hamilton (Ben Gertzfield)
d813af73f7
[Format] Fix detection of languages when reading from stdin (#79051)
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
2024-01-23 13:32:41 -07:00
darkfeline
5b4abae763
[emacs] Fix Emacs library formatting (#76110)
This makes it easier to ship/install these using the builtin Emacs
package format (in particular, a Version is required).
2024-01-10 13:14:21 +01:00
Owen Pan
c69ec700ad [clang-format][NFC] Don't use clang-format style in config files
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.
2024-01-10 00:58:35 -08:00
Owen Pan
b53628a52d Reland "[clang-format] Optimize processing .clang-format-ignore 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.
2024-01-09 21:34:21 -08:00
Mitch Phillips
26993f6167 Revert "[clang-format] Optimize processing .clang-format-ignore files (#76733)"
This reverts commit 42ec976184acd40436acd7104ad715c60ca3e7ed.

Reason: Broke the sanitizer buildbots. See more information on the
github comment thread at
42ec976184
2024-01-04 10:47:51 +01:00
Owen Pan
42ec976184
[clang-format] Optimize processing .clang-format-ignore files (#76733)
Reuse the patterns governing the previous input file being formatted if
the current input file is from the same directory.
2024-01-03 21:12:28 -08:00
Owen Pan
09308122c6
[clang-format] Add .clang-format-ignore for ignoring files (#76327)
Closes #52975.
2023-12-29 19:40:44 -08:00
Owen Pan
c3fa4b788f
[clang-format] Fix a bug in git-clang-format.bat (#75268)
Pass the fully-qualified path name (less the file extension) of
git-clang-format.bat to py so that it can be run from anywhere.

Fixes #75265.
2023-12-13 14:00:06 -08:00
Owen Pan
3791b3fca6
[clang-format][NFC] Clean up the driver and getStyle() in Format.cpp (#74794) 2023-12-08 15:23:01 -08:00
Aiden Grossman
aeaae5311b
[clang-format] Add "three dot" diff option to git-clang-format (#74230)
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
2023-12-05 19:19:21 -08:00
Owen Pan
900bb318b5
[clang-format][NFC] Use prog in clang-format-diff.py (#74399)
This is a minor improvement to #73491.
2023-12-05 10:36:14 +00:00
Owen Pan
78940a4e1f
[clang-format] Fix a bug in git-clang-format --binary (#74293)
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.
2023-12-04 13:49:23 -08:00
Owen Pan
2a3f1195d6
[clang-format] Fix a bug in git-clang-format --binary (#74176)
Fixed #74165.
2023-12-03 02:07:07 -08:00
Owen Pan
5c60e2ce78 [clang-format][NFC] Reformat source code with clang-format style 2023-11-30 20:19:30 -08:00
serge-sans-paille
ced0f28a35
Improve clang-format-diff help output (#73491)
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.
2023-11-28 13:46:37 +00:00
Conrad Donahue
68d618f908
[clang-format] Add ability for clang-format-diff to exit with non-0 status (#70883)
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.
2023-11-08 18:13:03 -08:00
Chris B
7d7e4d20b0
[Windows] Add git-clang-format wrapper bat file (#69228)
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
2023-10-21 08:14:29 -05:00
Owen Pan
743659be87
[clang-format] Fix a serious bug in git-clang-format (#65723)
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.
2023-09-08 15:05:22 -07:00