]> git.ipfire.org Git - thirdparty/git.git/commitdiff
CodingGuidelines: document our style for flags
authorPatrick Steinhardt <ps@pks.im>
Tue, 31 Mar 2026 23:57:46 +0000 (01:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Apr 2026 03:43:13 +0000 (20:43 -0700)
We have recently iterated a bit on our style for flags. Document this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/CodingGuidelines

index b8670751f5c705ba5f411cd92cacafb33c3c95e0..4992e52093efdc80daa79efc714561d1d73961dd 100644 (file)
@@ -668,6 +668,18 @@ For C programs:
    unsigned other_field:1;
    unsigned field_with_longer_name:1;
 
+ - When a function `F` accepts flags, those flags should be defined as `enum
+   F_flags`. Individual flag definitions should start with `F` and be in
+   all-uppercase letters. Flag values should be represented via bit shifts.
+   E.g.
+
+        enum frobnicate_flags {
+                FROBNICATE_FOO = (1 << 0),
+                FROBNICATE_BAR = (1 << 1),
+        };
+
+        int frobnicate(enum frobnicate_flags flags);
+
  - Array names should be named in the singular form if the individual items are
    subject of use. E.g.: