Skip to content

Commit 3f6f5c9

Browse files
committed
Merge branch 'jc/decorate-leaky-separator-color' into maint
"git log --decorate" did not reset colors correctly around the branch names. * jc/decorate-leaky-separator-color: log --decorate: do not leak "commit" color into the next item Documentation/config.txt: simplify boolean description in the syntax section Documentation/config.txt: describe 'color' value type in the "Values" section Documentation/config.txt: have a separate "Values" section Documentation/config.txt: describe the structure first and then meaning Documentation/config.txt: explain multi-valued variables once Documentation/config.txt: avoid unnecessary negation
2 parents c974184 + 5ee8758 commit 3f6f5c9

File tree

3 files changed

+84
-57
lines changed

3 files changed

+84
-57
lines changed

Documentation/config.txt

Lines changed: 75 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ the fully qualified variable name of the variable itself is the last
1414
dot-separated segment and the section name is everything before the last
1515
dot. The variable names are case-insensitive, allow only alphanumeric
1616
characters and `-`, and must start with an alphabetic character. Some
17-
variables may appear multiple times.
17+
variables may appear multiple times; we say then that the variable is
18+
multivalued.
1819

1920
Syntax
2021
~~~~~~
@@ -25,7 +26,7 @@ blank lines are ignored.
2526

2627
The file consists of sections and variables. A section begins with
2728
the name of the section in square brackets and continues until the next
28-
section begins. Section names are not case sensitive. Only alphanumeric
29+
section begins. Section names are case-insensitive. Only alphanumeric
2930
characters, `-` and `.` are allowed in section names. Each variable
3031
must belong to some section, which means that there must be a section
3132
header before the first setting of a variable.
@@ -40,8 +41,8 @@ in the section header, like in the example below:
4041
--------
4142

4243
Subsection names are case sensitive and can contain any characters except
43-
newline (doublequote `"` and backslash have to be escaped as `\"` and `\\`,
44-
respectively). Section headers cannot span multiple
44+
newline (doublequote `"` and backslash can be included by escaping them
45+
as `\"` and `\\`, respectively). Section headers cannot span multiple
4546
lines. Variables may belong directly to a section or to a given subsection.
4647
You can have `[section]` if you have `[section "subsection"]`, but you
4748
don't need to.
@@ -53,38 +54,27 @@ restrictions as section names.
5354

5455
All the other lines (and the remainder of the line after the section
5556
header) are recognized as setting variables, in the form
56-
'name = value'. If there is no equal sign on the line, the entire line
57-
is taken as 'name' and the variable is recognized as boolean "true".
57+
'name = value' (or just 'name', which is a short-hand to say that
58+
the variable is the boolean "true").
5859
The variable names are case-insensitive, allow only alphanumeric characters
59-
and `-`, and must start with an alphabetic character. There can be more
60-
than one value for a given variable; we say then that the variable is
61-
multivalued.
60+
and `-`, and must start with an alphabetic character.
6261

63-
Leading and trailing whitespace in a variable value is discarded.
64-
Internal whitespace within a variable value is retained verbatim.
62+
A line that defines a value can be continued to the next line by
63+
ending it with a `\`; the backquote and the end-of-line are
64+
stripped. Leading whitespaces after 'name =', the remainder of the
65+
line after the first comment character '#' or ';', and trailing
66+
whitespaces of the line are discarded unless they are enclosed in
67+
double quotes. Internal whitespaces within the value are retained
68+
verbatim.
6569

66-
The values following the equals sign in variable assign are all either
67-
a string, an integer, or a boolean. Boolean values may be given as yes/no,
68-
1/0, true/false or on/off. Case is not significant in boolean values, when
69-
converting value to the canonical form using '--bool' type specifier;
70-
'git config' will ensure that the output is "true" or "false".
71-
72-
String values may be entirely or partially enclosed in double quotes.
73-
You need to enclose variable values in double quotes if you want to
74-
preserve leading or trailing whitespace, or if the variable value contains
75-
comment characters (i.e. it contains '#' or ';').
76-
Double quote `"` and backslash `\` characters in variable values must
77-
be escaped: use `\"` for `"` and `\\` for `\`.
70+
Inside double quotes, double quote `"` and backslash `\` characters
71+
must be escaped: use `\"` for `"` and `\\` for `\`.
7872

7973
The following escape sequences (beside `\"` and `\\`) are recognized:
8074
`\n` for newline character (NL), `\t` for horizontal tabulation (HT, TAB)
8175
and `\b` for backspace (BS). Other char escape sequences (including octal
8276
escape sequences) are invalid.
8377

84-
Variable values ending in a `\` are continued on the next line in the
85-
customary UNIX fashion.
86-
87-
Some variables may require a special value format.
8878

8979
Includes
9080
~~~~~~~~
@@ -126,6 +116,61 @@ Example
126116
path = foo ; expand "foo" relative to the current file
127117
path = ~/foo ; expand "foo" in your $HOME directory
128118

119+
120+
Values
121+
~~~~~~
122+
123+
Values of many variables are treated as a simple string, but there
124+
are variables that take values of specific types and there are rules
125+
as to how to spell them.
126+
127+
boolean::
128+
129+
When a variable is said to take a boolean value, many
130+
synonyms are accepted for 'true' and 'false'; these are all
131+
case-insensitive.
132+
133+
true;; Boolean true can be spelled as `yes`, `on`, `true`,
134+
or `1`. Also, a variable defined without `= <value>`
135+
is taken as true.
136+
137+
false;; Boolean false can be spelled as `no`, `off`,
138+
`false`, or `0`.
139+
+
140+
When converting value to the canonical form using '--bool' type
141+
specifier; 'git config' will ensure that the output is "true" or
142+
"false" (spelled in lowercase).
143+
144+
integer::
145+
The value for many variables that specify various sizes can
146+
be suffixed with `k`, `M`,... to mean "scale the number by
147+
1024", "by 1024x1024", etc.
148+
149+
color::
150+
The value for a variables that takes a color is a list of
151+
colors (at most two) and attributes (at most one), separated
152+
by spaces. The colors accepted are `normal`, `black`,
153+
`red`, `green`, `yellow`, `blue`, `magenta`, `cyan` and
154+
`white`; the attributes are `bold`, `dim`, `ul`, `blink` and
155+
`reverse`. The first color given is the foreground; the
156+
second is the background. The position of the attribute, if
157+
any, doesn't matter. Attributes may be turned off
158+
specifically by prefixing them with `no` (e.g., `noreverse`,
159+
`noul`, etc).
160+
+
161+
Colors (foreground and background) may also be given as numbers between
162+
0 and 255; these use ANSI 256-color mode (but note that not all
163+
terminals may support this). If your terminal supports it, you may also
164+
specify 24-bit RGB values as hex, like `#ff0ab3`.
165+
+
166+
The attributes are meant to be reset at the beginning of each item
167+
in the colored output, so setting color.decorate.branch to `black`
168+
will paint that branch name in a plain `black`, even if the previous
169+
thing on the same output line (e.g. opening parenthesis before the
170+
list of branch names in `log --decorate` output) is set to be
171+
painted with `bold` or some other attribute.
172+
173+
129174
Variables
130175
~~~~~~~~~
131176

@@ -846,20 +891,6 @@ color.branch.<slot>::
846891
`remote` (a remote-tracking branch in refs/remotes/),
847892
`upstream` (upstream tracking branch), `plain` (other
848893
refs).
849-
+
850-
The value for these configuration variables is a list of colors (at most
851-
two) and attributes (at most one), separated by spaces. The colors
852-
accepted are `normal`, `black`, `red`, `green`, `yellow`, `blue`,
853-
`magenta`, `cyan` and `white`; the attributes are `bold`, `dim`, `ul`,
854-
`blink` and `reverse`. The first color given is the foreground; the
855-
second is the background. The position of the attribute, if any,
856-
doesn't matter. Attributes may be turned off specifically by prefixing
857-
them with `no` (e.g., `noreverse`, `noul`, etc).
858-
+
859-
Colors (foreground and background) may also be given as numbers between
860-
0 and 255; these use ANSI 256-color mode (but note that not all
861-
terminals may support this). If your terminal supports it, you may also
862-
specify 24-bit RGB values as hex, like `#ff0ab3`.
863894

864895
color.diff::
865896
Whether to use ANSI escape sequences to add color to patches.
@@ -879,8 +910,7 @@ color.diff.<slot>::
879910
of `plain` (context text), `meta` (metainformation), `frag`
880911
(hunk header), 'func' (function in hunk header), `old` (removed lines),
881912
`new` (added lines), `commit` (commit headers), or `whitespace`
882-
(highlighting whitespace errors). The values of these variables may be
883-
specified as in color.branch.<slot>.
913+
(highlighting whitespace errors).
884914

885915
color.decorate.<slot>::
886916
Use customized color for 'git log --decorate' output. `<slot>` is one
@@ -917,8 +947,6 @@ color.grep.<slot>::
917947
separators between fields on a line (`:`, `-`, and `=`)
918948
and between hunks (`--`)
919949
--
920-
+
921-
The values of these variables may be specified as in color.branch.<slot>.
922950

923951
color.interactive::
924952
When set to `always`, always use colors for interactive prompts
@@ -931,8 +959,7 @@ color.interactive.<slot>::
931959
Use customized color for 'git add --interactive' and 'git clean
932960
--interactive' output. `<slot>` may be `prompt`, `header`, `help`
933961
or `error`, for four distinct types of normal output from
934-
interactive commands. The values of these variables may be
935-
specified as in color.branch.<slot>.
962+
interactive commands.
936963

937964
color.pager::
938965
A boolean to enable/disable colored output when the pager is in
@@ -958,8 +985,7 @@ color.status.<slot>::
958985
`untracked` (files which are not tracked by Git),
959986
`branch` (the current branch), or
960987
`nobranch` (the color the 'no branch' warning is shown in, defaulting
961-
to red). The values of these variables may be specified as in
962-
color.branch.<slot>.
988+
to red).
963989

964990
color.ui::
965991
This variable determines the default value for variables such

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void format_decorations_extended(struct strbuf *sb,
195195
while (decoration) {
196196
strbuf_addstr(sb, color_commit);
197197
strbuf_addstr(sb, prefix);
198+
strbuf_addstr(sb, color_reset);
198199
strbuf_addstr(sb, decorate_get_color(use_color, decoration->type));
199200
if (decoration->type == DECORATION_REF_TAG)
200201
strbuf_addstr(sb, "tag: ");

t/t4207-log-decoration-colors.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ test_expect_success setup '
4444
'
4545

4646
cat >expected <<EOF
47-
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_HEAD}HEAD${c_reset}${c_commit},\
48-
${c_tag}tag: v1.0${c_reset}${c_commit},\
49-
${c_tag}tag: B${c_reset}${c_commit},\
50-
${c_branch}master${c_reset}${c_commit})${c_reset} B
51-
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_tag}tag: A1${c_reset}${c_commit},\
52-
${c_remoteBranch}other/master${c_reset}${c_commit})${c_reset} A1
53-
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_stash}refs/stash${c_reset}${c_commit})${c_reset}\
47+
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}${c_commit},\
48+
${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit},\
49+
${c_reset}${c_tag}tag: B${c_reset}${c_commit},\
50+
${c_reset}${c_branch}master${c_reset}${c_commit})${c_reset} B
51+
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit},\
52+
${c_reset}${c_remoteBranch}other/master${c_reset}${c_commit})${c_reset} A1
53+
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset}\
5454
On master: Changes to A.t
55-
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
55+
${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
5656
EOF
5757

5858
# We want log to show all, but the second parent to refs/stash is irrelevant

0 commit comments

Comments
 (0)