Skip to content

Commit 8d4725e

Browse files
committed
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>
1 parent 419c72c commit 8d4725e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

diff.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,19 @@ enum diff_symbol {
801801
DIFF_SYMBOL_CONTEXT_MARKER,
802802
DIFF_SYMBOL_SEPARATOR
803803
};
804+
804805
/*
805806
* 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
808809
* 16 is marking if the line is blank at EOF
810+
* 17..19 are used for color-moved.
809811
*/
810812
#define DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF (1<<16)
811813
#define DIFF_SYMBOL_MOVED_LINE (1<<17)
812814
#define DIFF_SYMBOL_MOVED_LINE_ALT (1<<18)
813815
#define DIFF_SYMBOL_MOVED_LINE_UNINTERESTING (1<<19)
816+
814817
#define DIFF_SYMBOL_CONTENT_WS_MASK (WSEH_NEW | WSEH_OLD | WSEH_CONTEXT | WS_RULE_MASK)
815818

816819
/*

diff.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ struct diff_options {
331331

332332
int ita_invisible_in_index;
333333
/* 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)
337337
unsigned ws_error_highlight;
338338
const char *prefix;
339339
int prefix_length;

ws.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ struct strbuf;
77
/*
88
* whitespace rules.
99
* 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).
1111
*/
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)
1920
#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+
2326
extern unsigned whitespace_rule_cfg;
2427
unsigned whitespace_rule(struct index_state *, const char *);
2528
unsigned parse_whitespace_rule(const char *);

0 commit comments

Comments
 (0)