Skip to content

Commit

Permalink
Merge branch 'ps/no-writable-strings'
Browse files Browse the repository at this point in the history
Building with "-Werror -Wwrite-strings" is now supported.

* ps/no-writable-strings: (27 commits)
  config.mak.dev: enable `-Wwrite-strings` warning
  builtin/merge: always store allocated strings in `pull_twohead`
  builtin/rebase: always store allocated string in `options.strategy`
  builtin/rebase: do not assign default backend to non-constant field
  imap-send: fix leaking memory in `imap_server_conf`
  imap-send: drop global `imap_server_conf` variable
  mailmap: always store allocated strings in mailmap blob
  revision: always store allocated strings in output encoding
  remote-curl: avoid assigning string constant to non-const variable
  send-pack: always allocate receive status
  parse-options: cast long name for OPTION_ALIAS
  http: do not assign string constant to non-const field
  compat/win32: fix const-correctness with string constants
  pretty: add casts for decoration option pointers
  object-file: make `buf` parameter of `index_mem()` a constant
  object-file: mark cached object buffers as const
  ident: add casts for fallback name and GECOS
  entry: refactor how we remove items for delayed checkouts
  line-log: always allocate the output prefix
  line-log: stop assigning string constant to file parent buffer
  ...
  • Loading branch information
gitster committed Jun 17, 2024
2 parents 42b8b5b + d66fe07 commit 4216329
Show file tree
Hide file tree
Showing 68 changed files with 443 additions and 366 deletions.
3 changes: 2 additions & 1 deletion builtin/bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ static int bisect_reset(const char *commit)
return bisect_clean_state();
}

static void log_commit(FILE *fp, char *fmt, const char *state,
static void log_commit(FILE *fp,
const char *fmt, const char *state,
struct commit *commit)
{
struct pretty_print_context pp = {0};
Expand Down
2 changes: 1 addition & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void get_ac_line(const char *inbuf, const char *what,
{
struct ident_split ident;
size_t len, maillen, namelen;
char *tmp, *endp;
const char *tmp, *endp;
const char *namebuf, *mailbuf;

tmp = strstr(inbuf, what);
Expand Down
2 changes: 1 addition & 1 deletion builtin/bugreport.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
struct tm tm;
enum diagnose_mode diagnose = DIAGNOSE_NONE;
char *option_output = NULL;
char *option_suffix = "%Y-%m-%d-%H%M";
const char *option_suffix = "%Y-%m-%d-%H%M";
const char *user_relative_path = NULL;
char *prefixed_filename;
size_t output_path_len;
Expand Down
4 changes: 2 additions & 2 deletions builtin/check-ignore.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static const struct option check_ignore_options[] = {

static void output_pattern(const char *path, struct path_pattern *pattern)
{
char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
const char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
const char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
if (!nul_term_line) {
if (!verbose) {
write_name_quoted(path, stdout, '\n');
Expand Down
14 changes: 9 additions & 5 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static char *option_branch = NULL;
static struct string_list option_not = STRING_LIST_INIT_NODUP;
static const char *real_git_dir;
static const char *ref_format;
static char *option_upload_pack = "git-upload-pack";
static const char *option_upload_pack = "git-upload-pack";
static int option_verbosity;
static int option_progress = -1;
static int option_sparse_checkout;
Expand Down Expand Up @@ -177,8 +177,8 @@ static struct option builtin_clone_options[] = {

static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
{
static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
static char *bundle_suffix[] = { ".bundle", "" };
static const char *suffix[] = { "/.git", "", ".git/.git", ".git" };
static const char *bundle_suffix[] = { ".bundle", "" };
size_t baselen = path->len;
struct stat st;
int i;
Expand Down Expand Up @@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
struct ref *local_refs = head;
struct ref **tail = head ? &head->next : &local_refs;
struct refspec_item tag_refspec;

refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);

if (option_single_branch) {
struct ref *remote_head = NULL;
Expand All @@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
&tail, 0);

/* if --branch=tag, pull the requested tag explicitly */
get_fetch_map(remote_head, tag_refspec, &tail, 0);
get_fetch_map(remote_head, &tag_refspec, &tail, 0);
}
free_refs(remote_head);
} else {
Expand All @@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
}

if (!option_mirror && !option_single_branch && !option_no_tags)
get_fetch_map(refs, tag_refspec, &tail, 0);
get_fetch_map(refs, &tag_refspec, &tail, 0);

refspec_item_clear(&tag_refspec);
return local_refs;
}

Expand Down
6 changes: 3 additions & 3 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ static char *template_file;
* the commit message and/or authorship.
*/
static const char *author_message, *author_message_buffer;
static char *edit_message, *use_message;
static const char *edit_message, *use_message;
static char *fixup_message, *fixup_commit, *squash_message;
static const char *fixup_prefix;
static int all, also, interactive, patch_interactive, only, amend, signoff;
static int edit_flag = -1; /* unspecified */
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
static int config_commit_verbose = -1; /* unspecified */
static int no_post_rewrite, allow_empty_message, pathspec_file_nul;
static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
static char *sign_commit, *pathspec_from_file;
static const char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
static const char *sign_commit, *pathspec_from_file;
static struct strvec trailer_args = STRVEC_INIT;

/*
Expand Down
2 changes: 1 addition & 1 deletion builtin/diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int cmd_diagnose(int argc, const char **argv, const char *prefix)
struct tm tm;
enum diagnose_mode mode = DIAGNOSE_STATS;
char *option_output = NULL;
char *option_suffix = "%Y-%m-%d-%H%M";
const char *option_suffix = "%Y-%m-%d-%H%M";
char *prefixed_filename;

const struct option diagnose_options[] = {
Expand Down
11 changes: 8 additions & 3 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,16 @@ static struct ref *get_ref_map(struct remote *remote,
}
}

if (tags == TAGS_SET)
if (tags == TAGS_SET) {
struct refspec_item tag_refspec;

/* also fetch all tags */
get_fetch_map(remote_refs, tag_refspec, &tail, 0);
else if (tags == TAGS_DEFAULT && *autotags)
refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
get_fetch_map(remote_refs, &tag_refspec, &tail, 0);
refspec_item_clear(&tag_refspec);
} else if (tags == TAGS_DEFAULT && *autotags) {
find_non_local_tags(remote_refs, NULL, &ref_map, &tail);
}

/* Now append any refs to be updated opportunistically: */
*tail = orefs;
Expand Down
2 changes: 1 addition & 1 deletion builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
o2->flags = flags2;
}

static void gen_message_id(struct rev_info *info, char *base)
static void gen_message_id(struct rev_info *info, const char *base)
{
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s.%"PRItime".git.%s", base,
Expand Down
4 changes: 2 additions & 2 deletions builtin/mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ static int populate_maildir_list(struct string_list *list, const char *path)
DIR *dir;
struct dirent *dent;
char *name = NULL;
char *subs[] = { "cur", "new", NULL };
char **sub;
const char *subs[] = { "cur", "new", NULL };
const char **sub;
int ret = -1;

for (sub = subs; *sub; ++sub) {
Expand Down
18 changes: 11 additions & 7 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,19 @@ static int git_merge_config(const char *k, const char *v,
return 0;
}

if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
show_diffstat = git_config_bool(k, v);
else if (!strcmp(k, "merge.verifysignatures"))
} else if (!strcmp(k, "merge.verifysignatures")) {
verify_signatures = git_config_bool(k, v);
else if (!strcmp(k, "pull.twohead"))
} else if (!strcmp(k, "pull.twohead")) {
FREE_AND_NULL(pull_twohead);
return git_config_string(&pull_twohead, k, v);
else if (!strcmp(k, "pull.octopus"))
} else if (!strcmp(k, "pull.octopus")) {
FREE_AND_NULL(pull_octopus);
return git_config_string(&pull_octopus, k, v);
else if (!strcmp(k, "commit.cleanup"))
} else if (!strcmp(k, "commit.cleanup")) {
return git_config_string(&cleanup_arg, k, v);
else if (!strcmp(k, "merge.ff")) {
} else if (!strcmp(k, "merge.ff")) {
int boolval = git_parse_maybe_bool(v);
if (0 <= boolval) {
fast_forward = boolval ? FF_ALLOW : FF_NO;
Expand Down Expand Up @@ -1294,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (!pull_twohead) {
char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
if (default_strategy && !strcmp(default_strategy, "ort"))
pull_twohead = "ort";
pull_twohead = xstrdup("ort");
}

init_diff_ui_defaults();
Expand Down Expand Up @@ -1793,6 +1795,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
strbuf_release(&buf);
free(branch_to_free);
free(pull_twohead);
free(pull_octopus);
discard_index(the_repository->index);
return ret;
}
52 changes: 26 additions & 26 deletions builtin/pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,48 @@ static const char * const pull_usage[] = {

/* Shared options */
static int opt_verbosity;
static char *opt_progress;
static const char *opt_progress;
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT;

/* Options passed to git-merge or git-rebase */
static enum rebase_type opt_rebase = -1;
static char *opt_diffstat;
static char *opt_log;
static char *opt_signoff;
static char *opt_squash;
static char *opt_commit;
static char *opt_edit;
static char *cleanup_arg;
static char *opt_ff;
static char *opt_verify_signatures;
static char *opt_verify;
static const char *opt_diffstat;
static const char *opt_log;
static const char *opt_signoff;
static const char *opt_squash;
static const char *opt_commit;
static const char *opt_edit;
static const char *cleanup_arg;
static const char *opt_ff;
static const char *opt_verify_signatures;
static const char *opt_verify;
static int opt_autostash = -1;
static int config_autostash;
static int check_trust_level = 1;
static struct strvec opt_strategies = STRVEC_INIT;
static struct strvec opt_strategy_opts = STRVEC_INIT;
static char *opt_gpg_sign;
static const char *opt_gpg_sign;
static int opt_allow_unrelated_histories;

/* Options passed to git-fetch */
static char *opt_all;
static char *opt_append;
static char *opt_upload_pack;
static const char *opt_all;
static const char *opt_append;
static const char *opt_upload_pack;
static int opt_force;
static char *opt_tags;
static char *opt_prune;
static char *max_children;
static const char *opt_tags;
static const char *opt_prune;
static const char *max_children;
static int opt_dry_run;
static char *opt_keep;
static char *opt_depth;
static char *opt_unshallow;
static char *opt_update_shallow;
static char *opt_refmap;
static char *opt_ipv4;
static char *opt_ipv6;
static const char *opt_keep;
static const char *opt_depth;
static const char *opt_unshallow;
static const char *opt_update_shallow;
static const char *opt_refmap;
static const char *opt_ipv4;
static const char *opt_ipv6;
static int opt_show_forced_updates = -1;
static char *set_upstream;
static const char *set_upstream;
static struct strvec opt_fetch = STRVEC_INIT;

static struct option pull_options[] = {
Expand Down
39 changes: 23 additions & 16 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct rebase_options {
.type = REBASE_UNSPECIFIED, \
.empty = EMPTY_UNSPECIFIED, \
.keep_empty = 1, \
.default_backend = "merge", \
.default_backend = xstrdup("merge"), \
.flags = REBASE_NO_QUIET, \
.git_am_opts = STRVEC_INIT, \
.exec = STRING_LIST_INIT_NODUP, \
Expand All @@ -151,6 +151,19 @@ struct rebase_options {
.strategy_opts = STRING_LIST_INIT_NODUP,\
}

static void rebase_options_release(struct rebase_options *opts)
{
free(opts->default_backend);
free(opts->reflog_action);
free(opts->head_name);
strvec_clear(&opts->git_am_opts);
free(opts->gpg_sign_opt);
string_list_clear(&opts->exec, 0);
free(opts->strategy);
string_list_clear(&opts->strategy_opts, 0);
strbuf_release(&opts->git_format_patch_opt);
}

static struct replay_opts get_replay_opts(const struct rebase_options *opts)
{
struct replay_opts replay = REPLAY_OPTS_INIT;
Expand Down Expand Up @@ -796,6 +809,7 @@ static int rebase_config(const char *var, const char *value,
}

if (!strcmp(var, "rebase.backend")) {
FREE_AND_NULL(opts->default_backend);
return git_config_string(&opts->default_backend, var, value);
}

Expand Down Expand Up @@ -1047,6 +1061,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
{
struct rebase_options options = REBASE_OPTIONS_INIT;
const char *branch_name;
const char *strategy_opt = NULL;
int ret, flags, total_argc, in_progress = 0;
int keep_base = 0;
int ok_to_skip_pre_rebase = 0;
Expand Down Expand Up @@ -1161,7 +1176,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, parse_opt_rebase_merges),
OPT_BOOL(0, "fork-point", &options.fork_point,
N_("use 'merge-base --fork-point' to refine upstream")),
OPT_STRING('s', "strategy", &options.strategy,
OPT_STRING('s', "strategy", &strategy_opt,
N_("strategy"), N_("use the given merge strategy")),
OPT_STRING_LIST('X', "strategy-option", &options.strategy_opts,
N_("option"),
Expand Down Expand Up @@ -1470,13 +1485,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
}
}

if (options.strategy_opts.nr && !options.strategy)
options.strategy = "ort";

if (options.strategy) {
options.strategy = xstrdup(options.strategy);
if (strategy_opt)
options.strategy = xstrdup(strategy_opt);
else if (options.strategy_opts.nr && !options.strategy)
options.strategy = xstrdup("ort");
if (options.strategy)
imply_merge(&options, "--strategy");
}

if (options.root && !options.onto_name)
imply_merge(&options, "--root without --onto");
Expand Down Expand Up @@ -1833,14 +1847,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
cleanup:
strbuf_release(&buf);
strbuf_release(&revisions);
free(options.reflog_action);
free(options.head_name);
strvec_clear(&options.git_am_opts);
free(options.gpg_sign_opt);
string_list_clear(&options.exec, 0);
free(options.strategy);
string_list_clear(&options.strategy_opts, 0);
strbuf_release(&options.git_format_patch_opt);
rebase_options_release(&options);
free(squash_onto_name);
free(keep_base_onto_name);
return !!ret;
Expand Down
4 changes: 2 additions & 2 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static int run_proc_receive_hook(struct command *commands,
return code;
}

static char *refuse_unconfigured_deny_msg =
static const char *refuse_unconfigured_deny_msg =
N_("By default, updating the current branch in a non-bare repository\n"
"is denied, because it will make the index and work tree inconsistent\n"
"with what you pushed, and will require 'git reset --hard' to match\n"
Expand All @@ -1269,7 +1269,7 @@ static void refuse_unconfigured_deny(void)
rp_error("%s", _(refuse_unconfigured_deny_msg));
}

static char *refuse_unconfigured_deny_delete_current_msg =
static const char *refuse_unconfigured_deny_delete_current_msg =
N_("By default, deleting the current branch is denied, because the next\n"
"'git clone' won't result in any file checked out, causing confusion.\n"
"\n"
Expand Down
Loading

0 comments on commit 4216329

Please sign in to comment.