aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/CodingGuidelines (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-08-26Documentation: note styling for bit fieldsKarthik Nayak1-0/+6
Our codebase uses a lot of bit field variables, generally to mark boolean type variables. While there is a formatting rule in the '.clang-format', there is no guideline specified in the 'CodingGuidelines'. Since the '.clang-format' is not yet enforced, let's also add a guideline with the same rule as mentioned in the '.clang-format', which is to not use any spaces around the colon, like so: unsigned my_field:1; unsigned other_field:1; unsigned field_with_longer_name:1; This would allow us not to modify the clang-format file, and more importantly, discourage people from doing ugly alignment with spaces, i.e. unsigned my_field : 1; unsigned other_field : 1; unsigned field_with_longer_name : 1; Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-08-04Merge branch 'jc/doc-release-vs-clear'Junio C Hamano1-2/+3
Doc update. * jc/doc-release-vs-clear: CodingGuidelines: clarify that S_release() does not reinitialize
2025-08-01Merge branch 'jc/document-test-balloons-in-flight'Junio C Hamano1-0/+8
To help our developers, document what C99 language features are being considered for adoption, in addition to what past experiments have already decided. * jc/document-test-balloons-in-flight: CodingGuidelines: document test balloons in flight
2025-08-01CodingGuidelines: clarify that S_release() does not reinitializeJunio C Hamano1-2/+3
In the section for naming various API functions, the fact that S_release() only releases the resources without preparing the structure for immediate reuse becomes only apparent when you readentries for S_release() and S_clear(). Clarify the description of S_release() a bit to make the entry self sufficient. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-07-24Merge branch 'pw/adopt-c99-bool-officially'Junio C Hamano1-0/+3
Declare weather-balloon we raised for "bool" type 18 months ago a success and officially allow using the type in our codebase. * pw/adopt-c99-bool-officially: strbuf: convert predicates to return bool git-compat-util: convert string predicates to return bool CodingGuidelines: allow the use of bool
2025-07-24CodingGuidelines: document test balloons in flightJunio C Hamano1-0/+8
Due to portability concerns, we do not blindly say "It is in [[this standard]], so we will make liberal use of it" for many features, and use of C99 language features follow this same principle. When we contemplate adopting a language feature that we haven't used in our codebase, we typically first raise a test balloon, which - is a piece of code that exercises the language feature we are trying to see if it is OK to adopt - is in a small section of code that we know everybody who cares about having a working Git must be compiling - is in a fairly stable part of the code, to allow reverting it easily if some platforms do not understand it yet. After a few years, with no breakage report from the community, we'd declare that the feature is now safe to use in our codebase. Before that, we forbid the use of the language construct except for the designated test balloon code site. The CodingGuidelines document lists these selected features that we already have determined that they are safe, and also those features that we know some platforms had trouble with. Let's also start listing ongoing test balloons and expected timeline for adoption. Recently phillip proposed to adopt the syntax to spell a structure literally (i.e. compound literal) with a new test balloon, which Patrick made redundant by pointing out an existing one we had already.but without documenting it. Start the new section with an entry for that test balloon. Helped-by: Patrick Steinhardt <ps@pks.im> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-07-16CodingGuidelines: allow the use of boolPhillip Wood1-0/+3
We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-06-24Merge branch 'jc/cg-let-bss-do-its-job'Junio C Hamano1-0/+3
Clarify "do not explicitly initialize to zero" rule in the CodingGuidelines document. * jc/cg-let-bss-do-its-job: CodingGuidelines: let BSS do its job
2025-06-18Merge branch 'cf/guideline-documenting-config-vars'Junio C Hamano1-0/+11
CodingGuidelines update. * cf/guideline-documenting-config-vars: CodingGuidelines: document formatting of similar config variables.
2025-06-18CodingGuidelines: document formatting of similar config variables.Collin Funk1-0/+11
Document that related `git config` variables should be placed one-per-line instead of separated by commas. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Collin Funk <collin.funk1@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-06-11CodingGuidelines: let BSS do its jobJunio C Hamano1-0/+3
We have mentioned this in various reviews, but I didn't see it mentioned in the CodingGuildelines document. Let's add it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-04-14doc: add markup for characters in GuidelinesJean-Noël Avila1-0/+3
This rule was already implicitely applied in the converted man pages, so let's state it loudly. Signed-off-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-03-03CodingGuidelines: *.txt -> *.adoc fixesTodd Zullinger1-2/+2
Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-12-15Merge branch 'ps/build'Junio C Hamano1-1/+1
Build procedure update plus introduction of Meson based builds. * ps/build: (24 commits) Introduce support for the Meson build system Documentation: add comparison of build systems t: allow overriding build dir t: better support for out-of-tree builds Documentation: extract script to generate a list of mergetools Documentation: teach "cmd-list.perl" about out-of-tree builds Documentation: allow sourcing generated includes from separate dir Makefile: simplify building of templates Makefile: write absolute program path into bin-wrappers Makefile: allow "bin-wrappers/" directory to exist Makefile: refactor generators to be PWD-independent Makefile: extract script to generate gitweb.js Makefile: extract script to generate gitweb.cgi Makefile: extract script to massage Python scripts Makefile: extract script to massage Shell scripts Makefile: use "generate-perl.sh" to massage Perl library Makefile: extract script to massage Perl scripts Makefile: consistently use PERL_PATH Makefile: generate doc versions via GIT-VERSION-GEN Makefile: generate "git.rc" via GIT-VERSION-GEN ...
2024-12-13Merge branch 'jc/doc-error-message-guidelines'Junio C Hamano1-3/+17
Developer documentation update. * jc/doc-error-message-guidelines: CodingGuidelines: a handful of error message guidelines
2024-12-07Makefile: allow "bin-wrappers/" directory to existPatrick Steinhardt1-1/+1
The "bin-wrappers/" directory gets created by our build system and is populated with one script for each of our binaries. There isn't anything inherently wrong with the current layout, but it is somewhat hard to adapt for out-of-tree build systems. Adapt the layout such that our "bin-wrappers/" directory always exists and contains our "wrap-for-bin.sh" script to make things a little bit easier for subsequent steps. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-11-29CodingGuidelines: a handful of error message guidelinesJunio C Hamano1-3/+17
It is more efficient to have something in the coding guidelines document to point at, when we want to review and comment on a new message in the codebase to make sure it "fits" in the set of existing messages. Let's write down established best practice we are aware of. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-10-24CodingGuidelines: discourage arbitrary suffixes in function namesKarthik Nayak1-0/+14
We often name functions with arbitrary suffixes like `_1` as an extension of another existing function. This creates confusion and doesn't provide good clarity into the functions purpose. Let's document good function naming etiquette in our CodingGuidelines. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
2024-10-10Merge branch 'ja/doc-synopsis-markup'Junio C Hamano1-28/+30
The way AsciiDoc is used for SYNOPSIS part of the manual pages has been revamped. The sources, at least for the simple cases, got vastly pleasant to work with. * ja/doc-synopsis-markup: doc: apply synopsis simplification on git-clone and git-init doc: update the guidelines to reflect the current formatting rules doc: introduce a synopsis typesetting
2024-09-24doc: update the guidelines to reflect the current formatting rulesJean-Noël Avila1-28/+30
Signed-off-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-29CodingGuidelines: also mention MAYBE_UNUSEDJunio C Hamano1-2/+3
A function that uses a parameter in one build may lose all uses of the parameter in another build, depending on the configuration. A workaround for such a case, MAYBE_UNUSED, should also be mentioned when we recommend the use of UNUSED to our developers. Keep the addition to the guideline short and document the criteria to choose between UNUSED and MAYBE_UNUSED near their definition. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-28CodingGuidelines: mention -Wunused-parameter and UNUSEDJeff King1-0/+7
Now that -Wunused-parameter is on by default for DEVELOPER=1 builds, people may trigger it, blocking their build. When it's a mistake for the parameter to exist, the path forward is obvious: remove it. But sometimes you need to suppress the warning, and the "UNUSED" mechanism for that is specific to our project, so people may not know about it. Let's put some advice in CodingGuidelines, including an example warning message. That should help people who grep for the warning text after seeing it from the compiler. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-26Merge branch 'jc/coding-style-c-operator-with-spaces'Junio C Hamano1-1/+10
Write down whitespacing rules around C opeators. * jc/coding-style-c-operator-with-spaces: CodingGuidelines: spaces around C operators
2024-08-20CodingGuidelines: spaces around C operatorsJunio C Hamano1-1/+10
As we have operated with "write like how your surrounding code is written" for too long, after a huge code drop from another project, we'll end up being inconsistent before such an imported code is cleaned up. We have many uses of cast operator with a space before its operand, mostly in the reftable code. Spell the convention out before it spreads to other places. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-14Merge branch 'jc/document-use-of-local'Junio C Hamano1-2/+2
Doc update. * jc/document-use-of-local: doc: note that AT&T ksh does not work with our test suite
2024-08-08Merge branch 'ps/doc-more-c-coding-guidelines'Junio C Hamano1-1/+47
Some project conventions have been added to CodingGuidelines. * ps/doc-more-c-coding-guidelines: Documentation: consistently use spaces inside initializers Documentation: document idiomatic function names Documentation: document naming schema for structs and their functions Documentation: clarify indentation style for C preprocessor directives clang-format: fix indentation width for preprocessor directives
2024-07-30Documentation: consistently use spaces inside initializersPatrick Steinhardt1-1/+1
Our coding guide is inconsistent with how it uses spaces inside of initializers (`struct foo bar = { something }`). While we mostly carry the space between open and closing braces and the initialized members, in one case we don't. Fix this one instance such that we consistently carry the space. This is also consistent with how clang-format formats such initializers. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-30Documentation: document idiomatic function namesPatrick Steinhardt1-0/+17
We semi-regularly have discussions around whether a function shall be named `S_release()`, `S_clear()` or `S_free()`. Indeed, it may not be obvious which of these is preferable as we never really defined what each of these variants means exactly. Carve out a space where we can add idiomatic names for common functions in our coding guidelines and define each of those functions. Like this, we can get to a shared understanding of their respective semantics and can easily point towards our style guide in future discussions such that our codebase becomes more consistent over time. Note that the intent is not to rename all functions which violate these semantics right away. Rather, the intent is to slowly converge towards a common style over time. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-30Documentation: document naming schema for structs and their functionsPatrick Steinhardt1-0/+19
We nowadays have a proper mishmash of struct-related functions that are called `<verb>_<struct>` (e.g. `clear_prio_queue()`) versus functions that are called `<struct>_<verb>` (e.g. `strbuf_clear()`). While the former style may be easier to tie into a spoken conversation, most of our communication happens in text anyway. Furthermore, prefixing functions with the name of the structure they operate on makes it way easier to group them together, see which functions are related, and will also help folks who are using code completion. Let's thus settle on one style, namely the one where functions start with the name of the structure they operate on. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-30Documentation: clarify indentation style for C preprocessor directivesPatrick Steinhardt1-0/+10
In the preceding commit, we have settled on using a single space per nesting level to indent preprocessor directives. Clarify our coding guidelines accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-23CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func"Junio C Hamano1-0/+27
Over the years, we accumulated the community wisdom to avoid the common "one-short export" construct for shell functions, but seem to have lost on which exact platform it is known to fail. Now during an investigation on a breakage for a recent topic, we found one example of failing shell. Let's document that. This does *not* mean that we can freely start using the construct once Ubuntu 20.04 is retired. But it does mean that we cannot use the construct until Ubuntu 20.04 is fully retired from the machines that matter. Moreover, posix explicitly says that the behaviour for the construct is unspecified. Helped-by: Kyle Lippincott <spectral@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-15doc: note that AT&T ksh does not work with our test suiteJunio C Hamano1-2/+2
The scripted Porcelain commands do not allow use of "local" because it is not universally supported, but we use it liberally in our test scripts, which means some POSIX compliant shells (like "ksh93") can not be used to run our tests. Document the status quo, to help the next person who gets perplexed seeing our tests fail. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-04-16Merge branch 'jc/local-extern-shell-rules'Junio C Hamano1-0/+16
Document and apply workaround for a buggy version of dash that mishandles "local var=val" construct. * jc/local-extern-shell-rules: t1016: local VAR="VAL" fix t0610: local VAR="VAL" fix t: teach lint that RHS of 'local VAR=VAL' needs to be quoted t: local VAR="VAL" (quote ${magic-reference}) t: local VAR="VAL" (quote command substitution) t: local VAR="VAL" (quote positional parameters) CodingGuidelines: quote assigned value in 'local var=$val' CodingGuidelines: describe "export VAR=VAL" rule
2024-04-05CodingGuidelines: quote assigned value in 'local var=$val'Junio C Hamano1-0/+12
Dash bug https://bugs.launchpad.net/ubuntu/+source/dash/+bug/139097 lets the shell erroneously perform field splitting on the expansion of a command substitution during declaration of a local or an extern variable. The explanation was stolen from ebee5580 (parallel-checkout: avoid dash local bug in tests, 2021-06-06). Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-04-05CodingGuidelines: describe "export VAR=VAL" ruleJunio C Hamano1-0/+4
https://lore.kernel.org/git/201307081121.22769.tboegi@web.de/ resulted in 9968ffff (test-lint: detect 'export FOO=bar', 2013-07-08) to add a rule to t/check-non-portable-shell.pl script to reject export VAR=VAL and suggest us to instead write it as two statements, i.e., VAR=VAL export VAR This however was not spelled out in the CodingGuidelines document. We may want to re-evaluate the rule since it is from ages ago, but for now, let's make the written rule and what the automation enforces consistent. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-03-29doc: rework CodingGuidelines with new formatting rulesJean-Noël Avila1-68/+85
Literal and placeholder formatting is more heavily enforced, with some asciidoc magic. Basically, the markup is preserved everywhere. Signed-off-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-03-05Merge branch 'jc/doc-compat-util'Junio C Hamano1-6/+35
Clarify wording in the CodingGuidelines that requires <git-compat-util.h> to be the first header file. * jc/doc-compat-util: doc: clarify the wording on <git-compat-util.h> requirement
2024-03-01Merge branch 'ja/doc-placeholders-markup-rules' into HEADJunio C Hamano1-0/+7
The way placeholders are to be marked-up in documentation have been specified; use "_<placeholder>_" to typeset the word inside a pair of <angle-brakets> emphasized. * ja/doc-placeholders-markup-rules: doc: clarify the format of placeholders
2024-02-27doc: clarify the wording on <git-compat-util.h> requirementJunio C Hamano1-6/+35
The reason why we require the <git-compat-util.h> file to be the first header file to be included is because it insulates other header files and source files from platform differences, like which system header files must be included in what order, and what C preprocessor feature macros must be defined to trigger certain features we want out of the system. We tried to clarify the rule in the coding guidelines document, but the wording was a bit fuzzy that can lead to misinterpretations like you can include <xdiff/xinclude.h> only to avoid having to include <git-compat-util.h> even if you have nothing to do with the xdiff implementation, for example. "You do not have to include more than one of these" was also misleading and would have been puzzling if you _needed_ to depend on more than one of these approved headers (answer: you are allowed to include them all if you need the declarations in them for reasons other than that you want to avoid including compat-util yourself). Instead of using the phrase "approved headers", enumerate them as exceptions, each labeled with its intended audiences, to avoid such misinterpretations. The structure also makes it easier to add new exceptions, so add the description of "t/unit-tests/test-lib.h" being an exception only for the unit tests implementation as an example. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Kyle Lippincott <spectral@google.com> Acked-by: Elijah Newren <newren@gmail.com>
2024-02-21doc: clarify the format of placeholdersJean-Noël Avila1-0/+7
Add the new format rule when using placeholders in the description of commands and options. Signed-off-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-02-08Merge branch 'js/contributor-docs-updates' into maint-2.43Junio C Hamano1-2/+2
Doc update. * js/contributor-docs-updates: SubmittingPatches: hyphenate non-ASCII SubmittingPatches: clarify GitHub artifact format SubmittingPatches: clarify GitHub visual SubmittingPatches: provide tag naming advice SubmittingPatches: update extra tags list SubmittingPatches: discourage new trailers SubmittingPatches: drop ref to "What's in git.git" CodingGuidelines: write punctuation marks CodingGuidelines: move period inside parentheses
2024-02-08Merge branch 'js/update-urls-in-doc-and-comment' into maint-2.43Junio C Hamano1-1/+1
Stale URLs have been updated to their current counterparts (or archive.org) and HTTP links are replaced with working HTTPS links. * js/update-urls-in-doc-and-comment: doc: refer to internet archive doc: update links for andre-simon.de doc: switch links to https doc: update links to current pages
2024-02-08Merge branch 'tz/send-email-negatable-options' into maint-2.43Junio C Hamano1-1/+1
Newer versions of Getopt::Long started giving warnings against our (ab)use of it in "git send-email". Bump the minimum version requirement for Perl to 5.8.1 (from September 2002) to allow simplifying our implementation. * tz/send-email-negatable-options: send-email: avoid duplicate specification warnings perl: bump the required Perl version to 5.8.1 from 5.8.0
2024-01-12Merge branch 'js/contributor-docs-updates'Junio C Hamano1-2/+2
Doc update. * js/contributor-docs-updates: SubmittingPatches: hyphenate non-ASCII SubmittingPatches: clarify GitHub artifact format SubmittingPatches: clarify GitHub visual SubmittingPatches: provide tag naming advice SubmittingPatches: update extra tags list SubmittingPatches: discourage new trailers SubmittingPatches: drop ref to "What's in git.git" CodingGuidelines: write punctuation marks CodingGuidelines: move period inside parentheses
2023-12-27CodingGuidelines: write punctuation marksJosh Soref1-1/+1
- Match style in Release Notes Signed-off-by: Josh Soref <jsoref@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-12-27CodingGuidelines: move period inside parenthesesJosh Soref1-1/+1
The contents within parenthesis should be omittable without resulting in broken text. Eliding the parenthesis left a period to end a run without any content. Signed-off-by: Josh Soref <jsoref@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-12-18Merge branch 'js/update-urls-in-doc-and-comment'Junio C Hamano1-1/+1
Stale URLs have been updated to their current counterparts (or archive.org) and HTTP links are replaced with working HTTPS links. * js/update-urls-in-doc-and-comment: doc: refer to internet archive doc: update links for andre-simon.de doc: switch links to https doc: update links to current pages
2023-12-09Merge branch 'tz/send-email-negatable-options'Junio C Hamano1-1/+1
Newer versions of Getopt::Long started giving warnings against our (ab)use of it in "git send-email". Bump the minimum version requirement for Perl to 5.8.1 (from September 2002) to allow simplifying our implementation. * tz/send-email-negatable-options: send-email: avoid duplicate specification warnings perl: bump the required Perl version to 5.8.1 from 5.8.0
2023-11-26doc: update links to current pagesJosh Soref1-1/+1
It's somewhat traditional to respect sites' self-identification. Signed-off-by: Josh Soref <jsoref@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-11-17perl: bump the required Perl version to 5.8.1 from 5.8.0Todd Zullinger1-1/+1
The following commit will make use of a Getopt::Long feature which is only present in Perl >= 5.8.1. Document that as the minimum version we support. Many of our Perl scripts will continue to run with 5.8.0 but this change allows us to adjust them as needed without breaking any promises to our users. The Perl requirement was last changed in d48b284183 (perl: bump the required Perl version to 5.8 from 5.6.[21], 2010-09-24). At that time, 5.8.0 was 8 years old. It is now over 21 years old. Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>