Skip to content

Commit 72a7d5d

Browse files
peffgitster
authored andcommitted
environment: store comment_line_char as a string
We'd like to eventually support multi-byte comment prefixes, but the comment_line_char variable is referenced in many spots, making the transition difficult. Let's start by storing the character in a NUL-terminated string. That will let us switch code over incrementally to the string format, and we can easily support the existing code with a macro wrapper (since we'll continue to allow only a single-byte prefix, this will behave identically). Once all references to the "char" variable have been converted, we can drop it and enable longer strings. We'll still have to touch all of the spots that create or set the variable in this patch, but there are only a few (reading the config, and the "auto" character selector). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2786d05 commit 72a7d5d

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static void adjust_comment_line_char(const struct strbuf *sb)
685685
const char *p;
686686

687687
if (!memchr(sb->buf, candidates[0], sb->len)) {
688-
comment_line_char = candidates[0];
688+
comment_line_str = xstrfmt("%c", candidates[0]);
689689
return;
690690
}
691691

@@ -706,7 +706,7 @@ static void adjust_comment_line_char(const struct strbuf *sb)
706706
if (!*p)
707707
die(_("unable to select a comment character that is not used\n"
708708
"in the current commit message"));
709-
comment_line_char = *p;
709+
comment_line_str = xstrfmt("%c", *p);
710710
}
711711

712712
static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ static int git_default_core_config(const char *var, const char *value,
15681568
else if (value[0] && !value[1]) {
15691569
if (value[0] == '\n')
15701570
return error(_("core.commentChar cannot be newline"));
1571-
comment_line_char = value[0];
1571+
comment_line_str = xstrfmt("%c", value[0]);
15721572
auto_comment_line_char = 0;
15731573
} else
15741574
return error(_("core.commentChar should only be one ASCII character"));

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int protect_ntfs = PROTECT_NTFS_DEFAULT;
110110
* The character that begins a commented line in user-editable file
111111
* that is subject to stripspace.
112112
*/
113-
char comment_line_char = '#';
113+
const char *comment_line_str = "#";
114114
int auto_comment_line_char;
115115

116116
/* Parallel index stat data preload? */

environment.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ struct strvec;
88
* The character that begins a commented line in user-editable file
99
* that is subject to stripspace.
1010
*/
11-
extern char comment_line_char;
11+
#define comment_line_char (comment_line_str[0])
12+
extern const char *comment_line_str;
1213
extern int auto_comment_line_char;
1314

1415
/*

0 commit comments

Comments
 (0)