Skip to content

Commit b567004

Browse files
pks-tgitster
authored andcommitted
global: improve const correctness when assigning string constants
We're about to enable `-Wwrite-strings`, which changes the type of string constants to `const char[]`. Fix various sites where we assign such constants to non-const variables. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5529cba commit b567004

38 files changed

+106
-102
lines changed

builtin/bisect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ static int bisect_reset(const char *commit)
262262
return bisect_clean_state();
263263
}
264264

265-
static void log_commit(FILE *fp, char *fmt, const char *state,
265+
static void log_commit(FILE *fp,
266+
const char *fmt, const char *state,
266267
struct commit *commit)
267268
{
268269
struct pretty_print_context pp = {0};

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void get_ac_line(const char *inbuf, const char *what,
134134
{
135135
struct ident_split ident;
136136
size_t len, maillen, namelen;
137-
char *tmp, *endp;
137+
const char *tmp, *endp;
138138
const char *namebuf, *mailbuf;
139139

140140
tmp = strstr(inbuf, what);

builtin/bugreport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
107107
struct tm tm;
108108
enum diagnose_mode diagnose = DIAGNOSE_NONE;
109109
char *option_output = NULL;
110-
char *option_suffix = "%Y-%m-%d-%H%M";
110+
const char *option_suffix = "%Y-%m-%d-%H%M";
111111
const char *user_relative_path = NULL;
112112
char *prefixed_filename;
113113
size_t output_path_len;

builtin/check-ignore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static const struct option check_ignore_options[] = {
3535

3636
static void output_pattern(const char *path, struct path_pattern *pattern)
3737
{
38-
char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
39-
char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
38+
const char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
39+
const char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
4040
if (!nul_term_line) {
4141
if (!verbose) {
4242
write_name_quoted(path, stdout, '\n');

builtin/clone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static char *option_branch = NULL;
7171
static struct string_list option_not = STRING_LIST_INIT_NODUP;
7272
static const char *real_git_dir;
7373
static const char *ref_format;
74-
static char *option_upload_pack = "git-upload-pack";
74+
static const char *option_upload_pack = "git-upload-pack";
7575
static int option_verbosity;
7676
static int option_progress = -1;
7777
static int option_sparse_checkout;
@@ -177,8 +177,8 @@ static struct option builtin_clone_options[] = {
177177

178178
static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
179179
{
180-
static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
181-
static char *bundle_suffix[] = { ".bundle", "" };
180+
static const char *suffix[] = { "/.git", "", ".git/.git", ".git" };
181+
static const char *bundle_suffix[] = { ".bundle", "" };
182182
size_t baselen = path->len;
183183
struct stat st;
184184
int i;

builtin/commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ static char *template_file;
113113
* the commit message and/or authorship.
114114
*/
115115
static const char *author_message, *author_message_buffer;
116-
static char *edit_message, *use_message;
116+
static const char *edit_message, *use_message;
117117
static char *fixup_message, *fixup_commit, *squash_message;
118118
static const char *fixup_prefix;
119119
static int all, also, interactive, patch_interactive, only, amend, signoff;
120120
static int edit_flag = -1; /* unspecified */
121121
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
122122
static int config_commit_verbose = -1; /* unspecified */
123123
static int no_post_rewrite, allow_empty_message, pathspec_file_nul;
124-
static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
125-
static char *sign_commit, *pathspec_from_file;
124+
static const char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
125+
static const char *sign_commit, *pathspec_from_file;
126126
static struct strvec trailer_args = STRVEC_INIT;
127127

128128
/*

builtin/diagnose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int cmd_diagnose(int argc, const char **argv, const char *prefix)
1818
struct tm tm;
1919
enum diagnose_mode mode = DIAGNOSE_STATS;
2020
char *option_output = NULL;
21-
char *option_suffix = "%Y-%m-%d-%H%M";
21+
const char *option_suffix = "%Y-%m-%d-%H%M";
2222
char *prefixed_filename;
2323

2424
const struct option diagnose_options[] = {

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
12831283
o2->flags = flags2;
12841284
}
12851285

1286-
static void gen_message_id(struct rev_info *info, char *base)
1286+
static void gen_message_id(struct rev_info *info, const char *base)
12871287
{
12881288
struct strbuf buf = STRBUF_INIT;
12891289
strbuf_addf(&buf, "%s.%"PRItime".git.%s", base,

builtin/mailsplit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static int populate_maildir_list(struct string_list *list, const char *path)
113113
DIR *dir;
114114
struct dirent *dent;
115115
char *name = NULL;
116-
char *subs[] = { "cur", "new", NULL };
117-
char **sub;
116+
const char *subs[] = { "cur", "new", NULL };
117+
const char **sub;
118118
int ret = -1;
119119

120120
for (sub = subs; *sub; ++sub) {

builtin/pull.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,48 +71,48 @@ static const char * const pull_usage[] = {
7171

7272
/* Shared options */
7373
static int opt_verbosity;
74-
static char *opt_progress;
74+
static const char *opt_progress;
7575
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
7676
static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT;
7777

7878
/* Options passed to git-merge or git-rebase */
7979
static enum rebase_type opt_rebase = -1;
80-
static char *opt_diffstat;
81-
static char *opt_log;
82-
static char *opt_signoff;
83-
static char *opt_squash;
84-
static char *opt_commit;
85-
static char *opt_edit;
86-
static char *cleanup_arg;
87-
static char *opt_ff;
88-
static char *opt_verify_signatures;
89-
static char *opt_verify;
80+
static const char *opt_diffstat;
81+
static const char *opt_log;
82+
static const char *opt_signoff;
83+
static const char *opt_squash;
84+
static const char *opt_commit;
85+
static const char *opt_edit;
86+
static const char *cleanup_arg;
87+
static const char *opt_ff;
88+
static const char *opt_verify_signatures;
89+
static const char *opt_verify;
9090
static int opt_autostash = -1;
9191
static int config_autostash;
9292
static int check_trust_level = 1;
9393
static struct strvec opt_strategies = STRVEC_INIT;
9494
static struct strvec opt_strategy_opts = STRVEC_INIT;
95-
static char *opt_gpg_sign;
95+
static const char *opt_gpg_sign;
9696
static int opt_allow_unrelated_histories;
9797

9898
/* Options passed to git-fetch */
99-
static char *opt_all;
100-
static char *opt_append;
101-
static char *opt_upload_pack;
99+
static const char *opt_all;
100+
static const char *opt_append;
101+
static const char *opt_upload_pack;
102102
static int opt_force;
103-
static char *opt_tags;
104-
static char *opt_prune;
105-
static char *max_children;
103+
static const char *opt_tags;
104+
static const char *opt_prune;
105+
static const char *max_children;
106106
static int opt_dry_run;
107-
static char *opt_keep;
108-
static char *opt_depth;
109-
static char *opt_unshallow;
110-
static char *opt_update_shallow;
111-
static char *opt_refmap;
112-
static char *opt_ipv4;
113-
static char *opt_ipv6;
107+
static const char *opt_keep;
108+
static const char *opt_depth;
109+
static const char *opt_unshallow;
110+
static const char *opt_update_shallow;
111+
static const char *opt_refmap;
112+
static const char *opt_ipv4;
113+
static const char *opt_ipv6;
114114
static int opt_show_forced_updates = -1;
115-
static char *set_upstream;
115+
static const char *set_upstream;
116116
static struct strvec opt_fetch = STRVEC_INIT;
117117

118118
static struct option pull_options[] = {

0 commit comments

Comments
 (0)