Skip to content

Commit d98d9ee

Browse files
committed
Refine the guidance on commit messages
1 parent 6313ad9 commit d98d9ee

File tree

1 file changed

+128
-5
lines changed

1 file changed

+128
-5
lines changed

CONTRIBUTING.md

+128-5
Original file line numberDiff line numberDiff line change
@@ -766,15 +766,13 @@ typedef struct {
766766
uint16_t periodic : 1; /* offset 6 bit 0 */
767767
} mytimer_t;
768768
769-
/* Preprocessor check of timer register layout byte count. */
770-
#if (sizeof(mytimer_t) != 8)
771-
#error mytimer_t struct size incorrect (expected 8 bytes)
772-
#endif
769+
_Static_assert(sizeof(mytimer_t) == 8,
770+
"mytimer_t struct size incorrect (expected 8 bytes)");
773771
```
774772
775773
To enhance portability, use standard-defined types (e.g., `uint16_t`, `uint32_t`) and avoid relying on compiler-specific behavior.
776774
Where precise control over memory layout is required, such as in embedded systems or when interfacing with hardware,
777-
always verify the structure size and layout using static assertions or preprocessor checks.
775+
always verify the structure size and layout using static assertions.
778776
779777
#### Avoid extreme portability
780778
@@ -789,6 +787,131 @@ mainstream architectures. PDP-11 era is long gone.
789787
- It is fair to assume that `NULL` is matching `(uintptr_t) 0` and it is fair
790788
to `memset()` structures with zero. Non-zero `NULL` is for retro computing.
791789
790+
## Git Commit Style
791+
792+
Effective version control is critical to modern software development.
793+
Git's powerful features—such as granular commits, branching,
794+
and a versatile staging area—offer unparalleled flexibility.
795+
However, this flexibility can sometimes lead to disorganized commit histories and
796+
merge conflicts if not managed with clear, consistent practices.
797+
798+
By committing often, writing clear messages, and adhering to a common workflow,
799+
developers can not only reduce the potential for errors but also simplify collaboration and future maintenance.
800+
We encourage every team to tailor these best practices to their specific needs while striving
801+
for a shared standard that promotes efficiency and code quality.
802+
803+
Below are the detailed guidelines that build on these principles.
804+
* Group Related Changes Together:
805+
Each commit should encapsulate a single, coherent change.
806+
e.g., if you are addressing two separate bugs, create two distinct commits.
807+
This approach produces focused, small commits that simplify understanding, enable quick rollbacks,
808+
and foster efficient peer reviews.
809+
By taking advantage of Git’s staging area and selective file staging,
810+
you can craft granular commits that make collaboration smoother and more transparent.
811+
* Commit Frequently:
812+
Making commits often ensures that your changes remain concise and logically grouped.
813+
Frequent commits not only help maintain a clean history but also allow you to share your progress with your teammates regularly.
814+
This regular sharing keeps everyone in sync,
815+
minimizes merge conflicts, and promotes a collaborative environment where integration happens seamlessly.
816+
* Avoid Committing Work in Progress:
817+
Only commit code when a logical component is in a stable, ready-to-integrate state.
818+
Break your feature's development into manageable segments that reach a functional milestone quickly,
819+
so you can commit regularly without compromising quality.
820+
If you feel the urge to commit merely to clear your working directory for actions like switching branches or pulling changes,
821+
use Git's stash feature instead.
822+
This practice helps maintain a stable repository and ensures that your team reviews well-tested, coherent code.
823+
* Test Your Code Before Committing:
824+
Before committing, ensure that your code has been thoroughly tested.
825+
Rather than assuming your changes are ready, run comprehensive tests to confirm they work as intended without unintended side effects.
826+
Testing is especially critical when sharing your code with others,
827+
as it maintains the overall stability of the project and builds trust among collaborators.
828+
* Utilize Branches for Parallel Development:
829+
Branches are a powerful tool that enables developers to isolate different lines of work—whether you are developing new features,
830+
fixing bugs, or exploring innovative ideas.
831+
By using branches extensively, you can work on your tasks independently and merge only after careful review and testing.
832+
This not only keeps the main branch stable but also encourages collaborative code reviews and a more organized integration process.
833+
834+
Clear and descriptive commit messages are crucial for maintaining a transparent history of changes and for facilitating effective debugging and tracking.
835+
Please adhere to the guidelines outlined in [How to Write a Git Commit Message](https://cbea.ms/git-commit/).
836+
1. Separate the subject from the body with a blank line.
837+
2. Limit the subject line to 50 characters.
838+
3. Capitalize the subject line.
839+
4. Do not end the subject line with a period.
840+
5. Use the imperative mood in the subject line.
841+
6. Wrap the body at 72 characters.
842+
7. Use the body to explain what and why, not how.
843+
844+
An example (derived from Chris' blog post) looks like the following:
845+
```text
846+
Summarize changes in around 50 characters or less
847+
848+
More detailed explanatory text, if necessary. Wrap it to about 72
849+
characters or so. In some contexts, the first line is treated as the
850+
subject of the commit and the rest of the text as the body. The
851+
blank line separating the summary from the body is critical (unless
852+
you omit the body entirely); various tools like `log`, `shortlog`
853+
and `rebase` can get confused if you run the two together.
854+
855+
Explain the problem that this commit is solving. Focus on why you
856+
are making this change as opposed to how (the code explains that).
857+
Are there side effects or other unintuitive consequences of this
858+
change? Here's the place to explain them.
859+
860+
Further paragraphs come after blank lines.
861+
862+
- Bullet points are okay, too
863+
864+
- Typically a hyphen or asterisk is used for the bullet, preceded
865+
by a single space, with blank lines in between, but conventions
866+
vary here
867+
868+
If you use an issue tracker, put references to them at the bottom,
869+
like this:
870+
Close #123
871+
```
872+
873+
Another illustration of effective practice.
874+
```text
875+
commit f1775422bb5a1aa6e79a685dfa7cb54a852b567b
876+
Author: Jim Huang <jserv@ccns.ncku.edu.tw>
877+
Date: Mon Feb 24 13:08:32 2025 +0800
878+
879+
Introduce CPU architecture filtering in scheduler
880+
881+
In environments with mixed CPU architectures, it is crucial to ensure
882+
that an instance runs only on a host with a compatible CPU
883+
type—preventing, for example, a RISC-V instance from being scheduled on
884+
an Arm host.
885+
886+
This new scheduler filter enforces that requirement by comparing an
887+
instance's architecture against the host's allowed architectures. For
888+
the libvirt driver, the host's guest capabilities are queried, and the
889+
permitted architectures are recorded in the permitted_instances_types
890+
list within the host's cpu_info dictionary.
891+
892+
The filter systematically excludes hosts that do not support the
893+
instance's CPU architecture. Additionally, RISC-V has been added to the
894+
set of acceptable architectures for scheduling.
895+
896+
Note that the CPU architecture filter is disabled by default.
897+
```
898+
899+
The above is a clear, unformatted description provided in plain text.
900+
901+
In addition, this project expects contributors to follow these additional rules:
902+
* If there is important, useful, or essential conversation or information,
903+
include a reference or copy it.
904+
* Do not write single-word commits. Provide a descriptive subject.
905+
* Avoid using abusive words.
906+
* Avoid using backticks in commit subjects.
907+
Backticks can be easily confused with single quotes on some terminals,
908+
reducing readability. Plain text or single quotes provide sufficient clarity and emphasis.
909+
* Avoid using parentheses in commit subjects.
910+
Excessive use of parentheses "()" can clutter the subject line,
911+
making it harder to quickly grasp the essential message.
912+
913+
Some conventions are automatically enforced by the [githooks](https://git-scm.com/docs/githooks).
914+
792915
## References
793916
- [Linux kernel coding style](https://www.kernel.org/doc/html/latest/process/coding-style.html)
794917
- 1999, Brian W. Kernighan and Rob Pike, The Practice of Programming, Addison–Wesley.

0 commit comments

Comments
 (0)