whitespace: correct bit assignment comments
A comment in diff.c claimed that bits up to 12th (counting from 0th) are whitespace rules, and 13th thru 15th are for new/old/context, but it turns out it was miscounting. Correct them, and clarify where the whitespace rule bits come from in the comment. Extend bit assignment comments to cover bits used for color-moved, which weren't described. Also update the way these bit constants are defined to use (1 << N) notation, instead of octal constants, as it tends to make it easier to notice a breakage like this. Sprinkle a few blank lines between logically distinct groups of CPP macro definitions to make them easier to read. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 12, 2025 at 14:02 UTC
8d4725e48ef29bd857e21e689411878b6eb4df92
3 files changed
+22
-16
diff.c
+5
-2
@@ -801,16 +801,19 @@ enum diff_symbol {
801
DIFF_SYMBOL_CONTEXT_MARKER,
802
DIFF_SYMBOL_SEPARATOR
803
};
804
+
805
/*
806
* Flags for content lines:
806
- * 0..12 are whitespace rules
807
- * 13-15 are WSEH_NEW | WSEH_OLD | WSEH_CONTEXT
807
+ * 0..11 are whitespace rules (see ws.h)
808
+ * 12..14 are WSEH_NEW | WSEH_CONTEXT | WSEH_OLD
809
* 16 is marking if the line is blank at EOF
810
+ * 17..19 are used for color-moved.
811
*/
812
#define DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF (1<<16)
813
#define DIFF_SYMBOL_MOVED_LINE (1<<17)
814
#define DIFF_SYMBOL_MOVED_LINE_ALT (1<<18)
815
#define DIFF_SYMBOL_MOVED_LINE_UNINTERESTING (1<<19)
816
+
817
#define DIFF_SYMBOL_CONTENT_WS_MASK (WSEH_NEW | WSEH_OLD | WSEH_CONTEXT | WS_RULE_MASK)
818
819
/*
diff.h
+3
-3
@@ -331,9 +331,9 @@ struct diff_options {
331
332
int ita_invisible_in_index;
333
/* white-space error highlighting */
334
-#define WSEH_NEW (1<<12)
335
-#define WSEH_CONTEXT (1<<13)
336
-#define WSEH_OLD (1<<14)
334
+#define WSEH_NEW (1<<12)
335
+#define WSEH_CONTEXT (1<<13)
336
+#define WSEH_OLD (1<<14)
337
unsigned ws_error_highlight;
338
const char *prefix;
339
int prefix_length;
ws.h
+14
-11
@@ -7,19 +7,22 @@ struct strbuf;
7
/*
8
* whitespace rules.
9
* used by both diff and apply
10
- * last two digits are tab width
10
+ * last two octal-digits are tab width (we support only up to 63).
11
*/
12
-#define WS_BLANK_AT_EOL 0100
13
-#define WS_SPACE_BEFORE_TAB 0200
14
-#define WS_INDENT_WITH_NON_TAB 0400
15
-#define WS_CR_AT_EOL 01000
16
-#define WS_BLANK_AT_EOF 02000
17
-#define WS_TAB_IN_INDENT 04000
18
-#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
12
+#define WS_BLANK_AT_EOL (1<<6)
13
+#define WS_SPACE_BEFORE_TAB (1<<7)
14
+#define WS_INDENT_WITH_NON_TAB (1<<8)
15
+#define WS_CR_AT_EOL (1<<9)
16
+#define WS_BLANK_AT_EOF (1<<10)
17
+#define WS_TAB_IN_INDENT (1<<11)
18
+
19
+#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
20
#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8)
20
-#define WS_TAB_WIDTH_MASK 077
21
-/* All WS_* -- when extended, adapt diff.c emit_symbol */
22
-#define WS_RULE_MASK 07777
21
+#define WS_TAB_WIDTH_MASK ((1<<6)-1)
22
+
23
+/* All WS_* -- when extended, adapt constants defined after diff.c:diff_symbol */
24
+#define WS_RULE_MASK ((1<<12)-1)
25
+
26
extern unsigned whitespace_rule_cfg;
27
unsigned whitespace_rule(struct index_state *, const char *);
28
unsigned parse_whitespace_rule(const char *);