summaryrefslogtreecommitdiffstats
path: root/.clang-format (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'rs/unit-tests-test-run'Junio C Hamano2024-08-191-0/+5
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | Unit-test framework has learned a simple control structure to allow embedding test statements in-line instead of having to create a new function to contain them. * rs/unit-tests-test-run: t-strvec: use if_test t-reftable-basics: use if_test t-ctype: use if_test unit-tests: add if_test unit-tests: show location of checks outside of tests t0080: use here-doc test body
| * unit-tests: add if_testRené Scharfe2024-07-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | The macro TEST only allows defining a test that consists of a single expression. Add a new macro, if_test, which provides a way to define unit tests that are made up of one or more statements. if_test allows defining self-contained tests en bloc, a bit like test_expect_success does for regular tests. It acts like a conditional; the test body is executed if test_skip_all() had not been called before. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | clang-format: fix indentation width for preprocessor directivesPatrick Steinhardt2024-07-301-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In [1], we have improved our clang-format configuration to also specify the style for how to indent preprocessor directives. But while we have settled the question of where to put the indentation, either before or after the hash sign, we didn't specify exactly how to indent. With the current configuration, clang-format uses tabs to indent each level of nested preprocessor directives, which is in fact unintentional and never done in our codebase. Instead, we use a mixture of indenting by either one or two spaces, where using a single space is somewhat more common. Adapt our clang-format configuration accordingly by specifying an indentation width of one space. [1]: <20240708092317.267915-1-karthik.188@gmail.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'kn/ci-clang-format' into ps/doc-more-c-coding-guidelinesJunio C Hamano2024-07-301-0/+25
|\ \ | |/ |/| | | | | | | | | | | | | | | * kn/ci-clang-format: ci/style-check: add `RemoveBracesLLVM` in CI job check-whitespace: detect if no base_commit is provided ci: run style check on GitHub and GitLab clang-format: formalize some of the spacing rules clang-format: avoid spacing around bitfield colon clang-format: indent preprocessor directives after hash
| * clang-format: formalize some of the spacing rulesKarthik Nayak2024-07-231-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | There are some spacing rules that we follow in the project and it makes sense to formalize them: * Ensure there is no space inserted after the logical not '!' operator. * Ensure there is no space before the case statement's colon. * Ensure there is no space before the first bracket '[' of an array. * Ensure there is no space in empty blocks. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * clang-format: avoid spacing around bitfield colonKarthik Nayak2024-07-231-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The spacing around colons is currently not standardized and as such we have the following practices in our code base: - Spacing around the colon `int bf : 1`: 146 instances - No spacing around the colon `int bf:1`: 148 instances - Spacing before the colon `int bf :1`: 6 instances - Spacing after the colon `int bf: 1`: 12 instances Let's formalize this by picking the most followed pattern and add the corresponding style to '.clang-format'. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * clang-format: indent preprocessor directives after hashKarthik Nayak2024-07-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We do not have a rule around the indentation of preprocessor directives. This was also discussed on the list [1], noting how there is often inconsistency in the styling. While there was discussion, there was no conclusion around what is the preferred style here. One style being indenting after the hash: #if FOO # if BAR # include <foo> # endif #endif The other being before the hash: #if FOO #if BAR #include <foo> #endif #endif Let's pick the former and add 'IndentPPDirectives: AfterHash' value to our '.clang-format'. There is no clear reason to pick one over the other, but it would definitely be nicer to be consistent. [1]: https://lore.kernel.org/r/xmqqwmmm1bw6.fsf@gitster.g Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'rs/clang-format-updates'Junio C Hamano2024-07-151-4/+9
|\ \ | |/ |/| | | | | | | | | | | Custom control structures we invented more recently have been taught to the clang-format file. * rs/clang-format-updates: clang-format: include kh_foreach* macros in ForEachMacros
| * clang-format: include kh_foreach* macros in ForEachMacrosRené Scharfe2024-07-071-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The command for generating the list of ForEachMacros searches for macros whose name contains the string "for_each". Include those whose name contains "foreach" as well. That brings in kh_foreach and kh_foreach_value from khash.h. Regenerating the list also brings in hashmap-based macros added by 87571c3f71 (hashmap: use *_entry APIs for iteration, 2019-10-06), f0e63c4113 (hashmap: use *_entry APIs to wrap container_of, 2019-10-06), 4fa1d501f7 (strmap: add functions facilitating use as a string->int map, 2020-11-05), b70c82e6ed (strmap: add more utility functions, 2020-11-05), and 1201eb628a (strmap: add a strset sub-type, 2020-11-06). for_each_abbrev is no longer found because its definition was removed by d850b7a545 (cocci: apply the "cache.h" part of "the_repository.pending", 2023-03-28). Note that it had been a false positive, though, as it had been a function wrapper, not a for-like macro. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | clang-format: fix typo in commentAditya Neelamraju2023-11-011-3/+3
|/ | | | | Signed-off-by: Aditya Neelamraju <adityanv97@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* clang-format: use git grep to generate the ForEachMacros listMiguel Ojeda2019-06-041-2/+15
| | | | | | | | | | The ForEachMacros list can reasonably be generated grepping the C source code for macros with 'for_each' in their name. Taken almost verbatim from the .clang-format file in the Linux kernel. Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* trace2: add for_each macros to clang-formatJeff Hostetler2019-02-231-1/+1
| | | | | Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* editorconfig: indicate settings should be kept in syncbrian m. carlson2018-10-091-0/+2
| | | | | | | | | | | | Now that we have two places where we set code formatting settings, .editorconfig and .clang-format, it's possible that they could fall out of sync. This is relatively unlikely, since we're not likely to change the tab width or our preference for tabs, but just in case, add comments to both files reminding future developers to keep them in sync. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* clang-format: adjust penalty for return type line breakPatryk Obara2018-01-241-1/+1
| | | | | | | | | The penalty of 5 makes clang-format very eager to put even short type declarations (e.g. "extern int") into a separate line, even when breaking parameters list is sufficient. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* clang-format: add a comment about the meaning/status of theStephan Beyer2017-10-021-1/+5
| | | | | | | | | | | | | | | | Having a .clang-format file in a project can be understood in a way that code has to be in the style defined by the .clang-format file, i.e., you just have to run clang-format over all code and you are set. This unfortunately is not yet the case in the Git project, as the format file is still work in progress. Explain it with a comment in the beginning of the file. Additionally, the working clang-format version is mentioned because the config directives change from time to time (in a compatibility-breaking way). Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* clang-format: adjust line break penaltiesJohannes Schindelin2017-10-011-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We really, really, really want to limit the columns to 80 per line: One of the few consistent style comments on the Git mailing list is that the lines should not have more than 80 columns/line (even if 79 columns/line would make more sense, given that the code is frequently viewed as diff, and diffs adding an extra character). The penalty of 5 for excess characters is way too low to guarantee that, though, as pointed out by Brandon Williams. From the existing clang-format examples and documentation, it appears that 100 is a penalty deemed appropriate for Stuff You Really Don't Want, so let's assign that as the penalty for "excess characters", i.e. overly long lines. While at it, adjust the penalties further: we are actually not that keen on preventing new line breaks within comments or string literals, so the penalty of 100 seems awfully high. Likewise, we are not all that adamant about keeping line breaks away from assignment operators (a lot of Git's code breaks immediately after the `=` character just to keep that 80 columns/line limit). We do frown a little bit more about functions' return types being on their own line than the penalty 0 would suggest, so this was adjusted, too. Finally, we do not particularly fancy breaking before the first parameter in a call, but if it keeps the line shorter than 80 columns/line, that's what we do, so lower the penalty for breaking before a call's first parameter, but not quite as much as introducing new line breaks to comments. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* clang-format: outline the git project's coding styleBrandon Williams2017-08-151-0/+165
Add a '.clang-format' file which outlines the git project's coding style. This can be used with clang-format to auto-format .c and .h files to conform with git's style. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>