Merge branch 'ps/no-writable-strings' into jk/imap-send-plug-all-msgs-leak

* ps/no-writable-strings: (46 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
  ...
This commit is contained in:
Junio C Hamano 2024-06-07 10:32:02 -07:00
commit 7986451963
149 changed files with 1565 additions and 936 deletions

View file

@ -1338,6 +1338,7 @@ UNIT_TEST_PROGRAMS += t-ctype
UNIT_TEST_PROGRAMS += t-mem-pool
UNIT_TEST_PROGRAMS += t-prio-queue
UNIT_TEST_PROGRAMS += t-strbuf
UNIT_TEST_PROGRAMS += t-strvec
UNIT_TEST_PROGRAMS += t-trailer
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))

View file

@ -21,9 +21,11 @@ static int config_alias_cb(const char *key, const char *value,
return 0;
if (data->alias) {
if (!strcasecmp(p, data->alias))
return git_config_string((const char **)&data->v,
if (!strcasecmp(p, data->alias)) {
FREE_AND_NULL(data->v);
return git_config_string(&data->v,
key, value);
}
} else if (data->list) {
string_list_append(data->list, p);
}

2
attr.c
View file

@ -25,7 +25,7 @@
#include "tree-walk.h"
#include "object-name.h"
const char *git_attr_tree;
char *git_attr_tree;
const char git_attr__true[] = "(builtin)true";
const char git_attr__false[] = "\0(builtin)false";

2
attr.h
View file

@ -236,6 +236,6 @@ const char *git_attr_global_file(void);
/* Return whether the system gitattributes file is enabled and should be used. */
int git_attr_system_is_enabled(void);
extern const char *git_attr_tree;
extern char *git_attr_tree;
#endif /* ATTR_H */

View file

@ -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};

View file

@ -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);
@ -718,7 +718,7 @@ static int git_blame_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "blame.ignorerevsfile")) {
const char *str;
char *str;
int ret;
ret = git_config_pathname(&str, var, value);

View file

@ -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;

View file

@ -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');

View file

@ -1275,12 +1275,12 @@ static void setup_new_branch_info_and_source_tree(
}
}
static const char *parse_remote_branch(const char *arg,
static char *parse_remote_branch(const char *arg,
struct object_id *rev,
int could_be_checkout_paths)
{
int num_matches = 0;
const char *remote = unique_tracking_name(arg, rev, &num_matches);
char *remote = unique_tracking_name(arg, rev, &num_matches);
if (remote && could_be_checkout_paths) {
die(_("'%s' could be both a local file and a tracking branch.\n"
@ -1316,6 +1316,7 @@ static int parse_branchname_arg(int argc, const char **argv,
const char **new_branch = &opts->new_branch;
int argcount = 0;
const char *arg;
char *remote = NULL;
int dash_dash_pos;
int has_dash_dash = 0;
int i;
@ -1416,7 +1417,7 @@ static int parse_branchname_arg(int argc, const char **argv,
recover_with_dwim = 0;
if (recover_with_dwim) {
const char *remote = parse_remote_branch(arg, rev,
remote = parse_remote_branch(arg, rev,
could_be_checkout_paths);
if (remote) {
*new_branch = arg;
@ -1459,6 +1460,7 @@ static int parse_branchname_arg(int argc, const char **argv,
argc--;
}
free(remote);
return argcount;
}

View file

@ -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;
@ -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;
@ -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;
@ -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 {
@ -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;
}

View file

@ -107,13 +107,13 @@ static enum {
} commit_style;
static const char *logfile, *force_author;
static const char *template_file;
static char *template_file;
/*
* The _message variables are commit names from which to take
* 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;
@ -121,8 +121,8 @@ 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;
/*
@ -133,7 +133,7 @@ static struct strvec trailer_args = STRVEC_INIT;
* is specified explicitly.
*/
static enum commit_msg_cleanup_mode cleanup_mode;
static const char *cleanup_arg;
static char *cleanup_arg;
static enum commit_whence whence;
static int use_editor = 1, include_status = 1;

View file

@ -289,7 +289,7 @@ static int format_config(const struct config_display_options *opts,
else
strbuf_addstr(buf, v ? "true" : "false");
} else if (opts->type == TYPE_PATH) {
const char *v;
char *v;
if (git_config_pathname(&v, key_, value_) < 0)
return -1;
strbuf_addstr(buf, v);

View file

@ -39,5 +39,7 @@ int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
} else {
usage(usage_msg);
}
credential_clear(&c);
return 0;
}

View file

@ -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[] = {

View file

@ -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;

File diff suppressed because it is too large Load diff

View file

@ -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) {

View file

@ -100,7 +100,7 @@ static struct strategy all_strategy[] = {
{ "subtree", NO_FAST_FORWARD | NO_TRIVIAL },
};
static const char *pull_twohead, *pull_octopus;
static char *pull_twohead, *pull_octopus;
enum ff_type {
FF_NO,
@ -110,7 +110,7 @@ enum ff_type {
static enum ff_type fast_forward = FF_ALLOW;
static const char *cleanup_arg;
static char *cleanup_arg;
static enum commit_msg_cleanup_mode cleanup_mode;
static int option_parse_message(const struct option *opt,
@ -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;
@ -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();
@ -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;
}

View file

@ -20,6 +20,7 @@
#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "strvec.h"
#include "submodule.h"
#include "entry.h"
@ -38,45 +39,35 @@ enum update_mode {
#define DUP_BASENAME 1
#define KEEP_TRAILING_SLASH 2
static const char **internal_prefix_pathspec(const char *prefix,
static void internal_prefix_pathspec(struct strvec *out,
const char *prefix,
const char **pathspec,
int count, unsigned flags)
{
int i;
const char **result;
int prefixlen = prefix ? strlen(prefix) : 0;
ALLOC_ARRAY(result, count + 1);
/* Create an intermediate copy of the pathspec based on the flags */
for (i = 0; i < count; i++) {
int length = strlen(pathspec[i]);
int to_copy = length;
char *it;
for (int i = 0; i < count; i++) {
size_t length = strlen(pathspec[i]);
size_t to_copy = length;
const char *maybe_basename;
char *trimmed, *prefixed_path;
while (!(flags & KEEP_TRAILING_SLASH) &&
to_copy > 0 && is_dir_sep(pathspec[i][to_copy - 1]))
to_copy--;
it = xmemdupz(pathspec[i], to_copy);
if (flags & DUP_BASENAME) {
result[i] = xstrdup(basename(it));
free(it);
} else {
result[i] = it;
}
}
result[count] = NULL;
trimmed = xmemdupz(pathspec[i], to_copy);
maybe_basename = (flags & DUP_BASENAME) ? basename(trimmed) : trimmed;
prefixed_path = prefix_path(prefix, prefixlen, maybe_basename);
strvec_push(out, prefixed_path);
/* Prefix the pathspec and free the old intermediate strings */
for (i = 0; i < count; i++) {
const char *match = prefix_path(prefix, prefixlen, result[i]);
free((char *) result[i]);
result[i] = match;
free(prefixed_path);
free(trimmed);
}
}
return result;
}
static const char *add_slash(const char *path)
static char *add_slash(const char *path)
{
size_t len = strlen(path);
if (len && path[len - 1] != '/') {
@ -86,32 +77,34 @@ static const char *add_slash(const char *path)
with_slash[len] = 0;
return with_slash;
}
return path;
return xstrdup(path);
}
#define SUBMODULE_WITH_GITDIR ((const char *)1)
static void prepare_move_submodule(const char *src, int first,
const char **submodule_gitfile)
static const char *submodule_gitfile_path(const char *src, int first)
{
struct strbuf submodule_dotgit = STRBUF_INIT;
const char *path;
if (!S_ISGITLINK(the_repository->index->cache[first]->ce_mode))
die(_("Directory %s is in index and no submodule?"), src);
if (!is_staging_gitmodules_ok(the_repository->index))
die(_("Please stage your changes to .gitmodules or stash them to proceed"));
strbuf_addf(&submodule_dotgit, "%s/.git", src);
*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
if (*submodule_gitfile)
*submodule_gitfile = xstrdup(*submodule_gitfile);
else
*submodule_gitfile = SUBMODULE_WITH_GITDIR;
path = read_gitfile(submodule_dotgit.buf);
strbuf_release(&submodule_dotgit);
if (path)
return path;
return SUBMODULE_WITH_GITDIR;
}
static int index_range_of_same_dir(const char *src, int length,
int *first_p, int *last_p)
{
const char *src_w_slash = add_slash(src);
char *src_w_slash = add_slash(src);
int first, last, len_w_slash = length + 1;
first = index_name_pos(the_repository->index, src_w_slash, len_w_slash);
@ -124,8 +117,8 @@ static int index_range_of_same_dir(const char *src, int length,
if (strncmp(path, src_w_slash, len_w_slash))
break;
}
if (src_w_slash != src)
free((char *)src_w_slash);
free(src_w_slash);
*first_p = first;
*last_p = last;
return last - first;
@ -141,7 +134,7 @@ static int index_range_of_same_dir(const char *src, int length,
static int empty_dir_has_sparse_contents(const char *name)
{
int ret = 0;
const char *with_slash = add_slash(name);
char *with_slash = add_slash(name);
int length = strlen(with_slash);
int pos = index_name_pos(the_repository->index, with_slash, length);
@ -159,8 +152,7 @@ static int empty_dir_has_sparse_contents(const char *name)
}
free_return:
if (with_slash != name)
free((char *)with_slash);
free(with_slash);
return ret;
}
@ -177,18 +169,23 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "sparse", &ignore_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
OPT_END(),
};
const char **source, **destination, **dest_path, **submodule_gitfile;
const char *dst_w_slash;
struct strvec sources = STRVEC_INIT;
struct strvec dest_paths = STRVEC_INIT;
struct strvec destinations = STRVEC_INIT;
struct strvec submodule_gitfiles_to_free = STRVEC_INIT;
const char **submodule_gitfiles;
char *dst_w_slash = NULL;
const char **src_dir = NULL;
int src_dir_nr = 0, src_dir_alloc = 0;
struct strbuf a_src_dir = STRBUF_INIT;
enum update_mode *modes, dst_mode = 0;
struct stat st, dest_st;
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
struct string_list src_for_dst = STRING_LIST_INIT_DUP;
struct lock_file lock_file = LOCK_INIT;
struct cache_entry *ce;
struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
struct string_list dirty_paths = STRING_LIST_INIT_NODUP;
struct string_list only_match_skip_worktree = STRING_LIST_INIT_DUP;
struct string_list dirty_paths = STRING_LIST_INIT_DUP;
int ret;
git_config(git_default_config, NULL);
@ -201,7 +198,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
if (repo_read_index(the_repository) < 0)
die(_("index file corrupt"));
source = internal_prefix_pathspec(prefix, argv, argc, 0);
internal_prefix_pathspec(&sources, prefix, argv, argc, 0);
CALLOC_ARRAY(modes, argc);
/*
@ -212,25 +209,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
flags = KEEP_TRAILING_SLASH;
if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1]))
flags = 0;
dest_path = internal_prefix_pathspec(prefix, argv + argc, 1, flags);
dst_w_slash = add_slash(dest_path[0]);
submodule_gitfile = xcalloc(argc, sizeof(char *));
internal_prefix_pathspec(&dest_paths, prefix, argv + argc, 1, flags);
dst_w_slash = add_slash(dest_paths.v[0]);
submodule_gitfiles = xcalloc(argc, sizeof(char *));
if (dest_path[0][0] == '\0')
if (dest_paths.v[0][0] == '\0')
/* special case: "." was normalized to "" */
destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
else if (!lstat(dest_path[0], &st) &&
S_ISDIR(st.st_mode)) {
destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);
} else {
if (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&
internal_prefix_pathspec(&destinations, dest_paths.v[0], argv, argc, DUP_BASENAME);
else if (!lstat(dest_paths.v[0], &st) && S_ISDIR(st.st_mode)) {
internal_prefix_pathspec(&destinations, dst_w_slash, argv, argc, DUP_BASENAME);
} else if (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&
empty_dir_has_sparse_contents(dst_w_slash)) {
destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);
internal_prefix_pathspec(&destinations, dst_w_slash, argv, argc, DUP_BASENAME);
dst_mode = SKIP_WORKTREE_DIR;
} else if (argc != 1) {
die(_("destination '%s' is not a directory"), dest_path[0]);
die(_("destination '%s' is not a directory"), dest_paths.v[0]);
} else {
destination = dest_path;
strvec_pushv(&destinations, dest_paths.v);
/*
* <destination> is a file outside of sparse-checkout
* cone. Insist on cone mode here for backward
@ -239,18 +235,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
* is deprecated at this point) sparse-checkout. As
* SPARSE here is only considering cone-mode situation.
*/
if (!path_in_cone_mode_sparse_checkout(destination[0], the_repository->index))
if (!path_in_cone_mode_sparse_checkout(destinations.v[0], the_repository->index))
dst_mode = SPARSE;
}
}
if (dst_w_slash != dest_path[0]) {
free((char *)dst_w_slash);
dst_w_slash = NULL;
}
/* Checking */
for (i = 0; i < argc; i++) {
const char *src = source[i], *dst = destination[i];
const char *src = sources.v[i], *dst = destinations.v[i];
int length;
const char *bad = NULL;
int skip_sparse = 0;
@ -265,12 +256,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
pos = index_name_pos(the_repository->index, src, length);
if (pos < 0) {
const char *src_w_slash = add_slash(src);
char *src_w_slash = add_slash(src);
if (!path_in_sparse_checkout(src_w_slash, the_repository->index) &&
empty_dir_has_sparse_contents(src)) {
free(src_w_slash);
modes[i] |= SKIP_WORKTREE_DIR;
goto dir_check;
}
free(src_w_slash);
/* only error if existence is expected. */
if (!(modes[i] & SPARSE))
bad = _("bad source");
@ -310,12 +303,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
dir_check:
if (S_ISDIR(st.st_mode)) {
int j, dst_len, n;
char *dst_with_slash;
size_t dst_with_slash_len;
int j, n;
int first = index_name_pos(the_repository->index, src, length), last;
if (first >= 0) {
prepare_move_submodule(src, first,
submodule_gitfile + i);
const char *path = submodule_gitfile_path(src, first);
if (path != SUBMODULE_WITH_GITDIR)
path = strvec_push(&submodule_gitfiles_to_free, path);
submodule_gitfiles[i] = path;
goto act_on_entry;
} else if (index_range_of_same_dir(src, length,
&first, &last) < 1) {
@ -330,24 +327,28 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
src_dir[src_dir_nr++] = src;
n = argc + last - first;
REALLOC_ARRAY(source, n);
REALLOC_ARRAY(destination, n);
REALLOC_ARRAY(modes, n);
REALLOC_ARRAY(submodule_gitfile, n);
REALLOC_ARRAY(submodule_gitfiles, n);
dst = add_slash(dst);
dst_len = strlen(dst);
dst_with_slash = add_slash(dst);
dst_with_slash_len = strlen(dst_with_slash);
for (j = 0; j < last - first; j++) {
const struct cache_entry *ce = the_repository->index->cache[first + j];
const char *path = ce->name;
source[argc + j] = path;
destination[argc + j] =
prefix_path(dst, dst_len, path + length + 1);
char *prefixed_path = prefix_path(dst_with_slash, dst_with_slash_len, path + length + 1);
strvec_push(&sources, path);
strvec_push(&destinations, prefixed_path);
memset(modes + argc + j, 0, sizeof(enum update_mode));
modes[argc + j] |= ce_skip_worktree(ce) ? SPARSE : INDEX;
submodule_gitfile[argc + j] = NULL;
submodule_gitfiles[argc + j] = NULL;
free(prefixed_path);
}
free(dst_with_slash);
argc += last - first;
goto act_on_entry;
}
@ -428,23 +429,25 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
remove_entry:
if (--argc > 0) {
int n = argc - i;
MOVE_ARRAY(source + i, source + i + 1, n);
MOVE_ARRAY(destination + i, destination + i + 1, n);
strvec_remove(&sources, i);
strvec_remove(&destinations, i);
MOVE_ARRAY(modes + i, modes + i + 1, n);
MOVE_ARRAY(submodule_gitfile + i,
submodule_gitfile + i + 1, n);
MOVE_ARRAY(submodule_gitfiles + i,
submodule_gitfiles + i + 1, n);
i--;
}
}
if (only_match_skip_worktree.nr) {
advise_on_updating_sparse_paths(&only_match_skip_worktree);
if (!ignore_errors)
return 1;
if (!ignore_errors) {
ret = 1;
goto out;
}
}
for (i = 0; i < argc; i++) {
const char *src = source[i], *dst = destination[i];
const char *src = sources.v[i], *dst = destinations.v[i];
enum update_mode mode = modes[i];
int pos;
int sparse_and_dirty = 0;
@ -464,12 +467,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
continue;
die_errno(_("renaming '%s' failed"), src);
}
if (submodule_gitfile[i]) {
if (submodule_gitfiles[i]) {
if (!update_path_in_gitmodules(src, dst))
gitmodules_modified = 1;
if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
if (submodule_gitfiles[i] != SUBMODULE_WITH_GITDIR)
connect_work_tree_and_git_dir(dst,
submodule_gitfile[i],
submodule_gitfiles[i],
1);
}
@ -565,11 +568,18 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
COMMIT_LOCK | SKIP_IF_UNCHANGED))
die(_("Unable to write new index file"));
ret = 0;
out:
free(dst_w_slash);
string_list_clear(&src_for_dst, 0);
string_list_clear(&dirty_paths, 0);
UNLEAK(source);
UNLEAK(dest_path);
free(submodule_gitfile);
string_list_clear(&only_match_skip_worktree, 0);
strvec_clear(&sources);
strvec_clear(&dest_paths);
strvec_clear(&destinations);
strvec_clear(&submodule_gitfiles_to_free);
free(submodule_gitfiles);
free(modes);
return 0;
return ret;
}

View file

@ -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[] = {

View file

@ -83,7 +83,7 @@ static const char *action_names[] = {
struct rebase_options {
enum rebase_type type;
enum empty_type empty;
const char *default_backend;
char *default_backend;
const char *state_dir;
struct commit *upstream;
const char *upstream_name;
@ -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, \
@ -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;
@ -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);
}
@ -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;
@ -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"),
@ -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");
@ -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;

View file

@ -88,7 +88,7 @@ static struct strbuf push_cert = STRBUF_INIT;
static struct object_id push_cert_oid;
static struct signature_check sigcheck;
static const char *push_cert_nonce;
static const char *cert_nonce_seed;
static char *cert_nonce_seed;
static struct strvec hidden_refs = STRVEC_INIT;
static const char *NONCE_UNSOLICITED = "UNSOLICITED";
@ -168,13 +168,13 @@ static int receive_pack_config(const char *var, const char *value,
}
if (strcmp(var, "receive.fsck.skiplist") == 0) {
const char *path;
char *path;
if (git_config_pathname(&path, var, value))
return 1;
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
fsck_msg_types.len ? ',' : '=', path);
free((char *)path);
free(path);
return 0;
}
@ -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"
@ -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"

View file

@ -493,12 +493,13 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
{
struct ref *ref, *matches;
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
struct refspec_item refspec;
struct refspec_item refspec = {
.force = 0,
.pattern = 1,
.src = (char *) "refs/heads/*",
.dst = (char *) "refs/heads/*",
};
memset(&refspec, 0, sizeof(refspec));
refspec.force = 0;
refspec.pattern = 1;
refspec.src = refspec.dst = "refs/heads/*";
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
fetch_map, 1);
@ -507,7 +508,6 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
free_refs(fetch_map);
free_refs(matches);
return 0;
}

View file

@ -48,10 +48,10 @@ static const char incremental_bitmap_conflict_error[] = N_(
);
struct pack_objects_args {
const char *window;
const char *window_memory;
const char *depth;
const char *threads;
char *window;
char *window_memory;
char *depth;
char *threads;
unsigned long max_pack_size;
int no_reuse_delta;
int no_reuse_object;

View file

@ -179,7 +179,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
/* Check for incompatible command line arguments */
if (cmd) {
char *this_operation;
const char *this_operation;
if (cmd == 'q')
this_operation = "--quit";
else if (cmd == 'c')

View file

@ -336,5 +336,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
/* stable plumbing output; do not modify or localize */
fprintf(stderr, "Everything up-to-date\n");
free_refs(remote_refs);
free_refs(local_refs);
return ret;
}

View file

@ -736,16 +736,14 @@ static int dwim_orphan(const struct add_opts *opts, int opt_track, int remote)
return 1;
}
static const char *dwim_branch(const char *path, const char **new_branch)
static char *dwim_branch(const char *path, char **new_branch)
{
int n;
int branch_exists;
const char *s = worktree_basename(path, &n);
const char *branchname = xstrndup(s, n);
char *branchname = xstrndup(s, n);
struct strbuf ref = STRBUF_INIT;
UNLEAK(branchname);
branch_exists = !strbuf_check_branch_ref(&ref, branchname) &&
refs_ref_exists(get_main_ref_store(the_repository),
ref.buf);
@ -756,8 +754,7 @@ static const char *dwim_branch(const char *path, const char **new_branch)
*new_branch = branchname;
if (guess_remote) {
struct object_id oid;
const char *remote =
unique_tracking_name(*new_branch, &oid, NULL);
char *remote = unique_tracking_name(*new_branch, &oid, NULL);
return remote;
}
return NULL;
@ -769,6 +766,8 @@ static int add(int ac, const char **av, const char *prefix)
const char *new_branch_force = NULL;
char *path;
const char *branch;
char *branch_to_free = NULL;
char *new_branch_to_free = NULL;
const char *new_branch = NULL;
const char *opt_track = NULL;
const char *lock_reason = NULL;
@ -859,16 +858,17 @@ static int add(int ac, const char **av, const char *prefix)
opts.orphan = dwim_orphan(&opts, !!opt_track, 0);
} else if (ac < 2) {
/* DWIM: Guess branch name from path. */
const char *s = dwim_branch(path, &new_branch);
char *s = dwim_branch(path, &new_branch_to_free);
if (s)
branch = s;
branch = branch_to_free = s;
new_branch = new_branch_to_free;
/* DWIM: Infer --orphan when repo has no refs. */
opts.orphan = (!s) && dwim_orphan(&opts, !!opt_track, 1);
} else if (ac == 2) {
struct object_id oid;
struct commit *commit;
const char *remote;
char *remote;
commit = lookup_commit_reference_by_name(branch);
if (!commit) {
@ -923,6 +923,8 @@ static int add(int ac, const char **av, const char *prefix)
ret = add_worktree(path, branch, &opts);
free(path);
free(branch_to_free);
free(new_branch_to_free);
return ret;
}

View file

@ -45,7 +45,7 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
return 0;
}
const char *unique_tracking_name(const char *name, struct object_id *oid,
char *unique_tracking_name(const char *name, struct object_id *oid,
int *dwim_remotes_matched)
{
struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;

View file

@ -8,7 +8,7 @@
* tracking branch. Return the name of the remote if such a branch
* exists, NULL otherwise.
*/
const char *unique_tracking_name(const char *name,
char *unique_tracking_name(const char *name,
struct object_id *oid,
int *dwim_remotes_matched);

View file

@ -1106,6 +1106,10 @@ void ahead_behind(struct repository *r,
/* STALE is used here, PARENT2 is used by insert_no_dup(). */
repo_clear_commit_marks(r, PARENT2 | STALE);
while (prio_queue_peek(&queue)) {
struct commit *c = prio_queue_get(&queue);
free_bit_array(c);
}
clear_bit_arrays(&bit_arrays);
clear_prio_queue(&queue);
}

View file

@ -10,7 +10,13 @@ char *gitbasename (char *path)
skip_dos_drive_prefix(&path);
if (!path || !*path)
return ".";
/*
* basename(3P) is mis-specified because it returns a
* non-constant pointer even though it is specified to return a
* pointer to internal memory at times. The cast is a result of
* that.
*/
return (char *) ".";
for (base = path; *path; path++) {
if (!is_dir_sep(*path))
@ -34,7 +40,13 @@ char *gitdirname(char *path)
int dos_drive_prefix;
if (!p)
return ".";
/*
* dirname(3P) is mis-specified because it returns a
* non-constant pointer even though it is specified to return a
* pointer to internal memory at times. The cast is a result of
* that.
*/
return (char *) ".";
if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p)
goto dot;

View file

@ -2279,7 +2279,11 @@ struct passwd *getpwuid(int uid)
p->pw_name = user_name;
p->pw_gecos = get_extended_user_info(NameDisplay);
if (!p->pw_gecos)
p->pw_gecos = "unknown";
/*
* Data returned by getpwuid(3P) is treated as internal and
* must never be written to or freed.
*/
p->pw_gecos = (char *) "unknown";
p->pw_dir = NULL;
initialized = 1;
@ -2800,16 +2804,16 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
strbuf_addf(report, "'%s' is on a file system that does "
"not record ownership\n", path);
} else if (report) {
LPSTR str1, str2, str3, str4, to_free1 = NULL,
to_free3 = NULL, to_local_free2 = NULL,
to_local_free4 = NULL;
PCSTR str1, str2, str3, str4;
LPSTR to_free1 = NULL, to_free3 = NULL,
to_local_free2 = NULL, to_local_free4 = NULL;
if (user_sid_to_user_name(sid, &str1))
to_free1 = str1;
if (user_sid_to_user_name(sid, &to_free1))
str1 = to_free1;
else
str1 = "(inconvertible)";
if (ConvertSidToStringSidA(sid, &str2))
to_local_free2 = str2;
if (ConvertSidToStringSidA(sid, &to_local_free2))
str2 = to_local_free2;
else
str2 = "(inconvertible)";
@ -2822,13 +2826,13 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
str4 = "(invalid)";
} else {
if (user_sid_to_user_name(current_user_sid,
&str3))
to_free3 = str3;
&to_free3))
str3 = to_free3;
else
str3 = "(inconvertible)";
if (ConvertSidToStringSidA(current_user_sid,
&str4))
to_local_free4 = str4;
&to_local_free4))
str4 = to_local_free4;
else
str4 = "(inconvertible)";
}

View file

@ -848,7 +848,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
{
unsigned int table_size;
#ifndef _LIBC
char *codeset_name;
const char *codeset_name;
#endif
memset (dfa, '\0', sizeof (re_dfa_t));

View file

@ -139,7 +139,7 @@ static void write_console(unsigned char *str, size_t len)
/* convert utf-8 to utf-16 */
int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len);
if (wlen < 0) {
wchar_t *err = L"[invalid]";
const wchar_t *err = L"[invalid]";
WriteConsoleW(console, err, wcslen(err), &dummy, NULL);
return;
}

View file

@ -1338,7 +1338,7 @@ int git_config_bool(const char *name, const char *value)
return v;
}
int git_config_string(const char **dest, const char *var, const char *value)
int git_config_string(char **dest, const char *var, const char *value)
{
if (!value)
return config_error_nonbool(var);
@ -1346,7 +1346,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
return 0;
}
int git_config_pathname(const char **dest, const char *var, const char *value)
int git_config_pathname(char **dest, const char *var, const char *value)
{
if (!value)
return config_error_nonbool(var);
@ -1414,8 +1414,10 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "core.attributesfile"))
if (!strcmp(var, "core.attributesfile")) {
FREE_AND_NULL(git_attributes_file);
return git_config_pathname(&git_attributes_file, var, value);
}
if (!strcmp(var, "core.hookspath")) {
if (ctx->kvi && ctx->kvi->scope == CONFIG_SCOPE_LOCAL &&
@ -1428,6 +1430,7 @@ static int git_default_core_config(const char *var, const char *value,
"again with "
"`GIT_CLONE_PROTECTION_ACTIVE=false`"),
value);
FREE_AND_NULL(git_hooks_path);
return git_config_pathname(&git_hooks_path, var, value);
}
@ -1564,8 +1567,10 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "core.checkroundtripencoding"))
if (!strcmp(var, "core.checkroundtripencoding")) {
FREE_AND_NULL(check_roundtrip_encoding);
return git_config_string(&check_roundtrip_encoding, var, value);
}
if (!strcmp(var, "core.notesref")) {
if (!value)
@ -1574,8 +1579,10 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "core.editor"))
if (!strcmp(var, "core.editor")) {
FREE_AND_NULL(editor_program);
return git_config_string(&editor_program, var, value);
}
if (!strcmp(var, "core.commentchar") ||
!strcmp(var, "core.commentstring")) {
@ -1593,11 +1600,13 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "core.askpass"))
if (!strcmp(var, "core.askpass")) {
FREE_AND_NULL(askpass_program);
return git_config_string(&askpass_program, var, value);
}
if (!strcmp(var, "core.excludesfile")) {
free((char *)excludes_file);
FREE_AND_NULL(excludes_file);
return git_config_pathname(&excludes_file, var, value);
}
@ -1700,11 +1709,15 @@ static int git_default_sparse_config(const char *var, const char *value)
static int git_default_i18n_config(const char *var, const char *value)
{
if (!strcmp(var, "i18n.commitencoding"))
if (!strcmp(var, "i18n.commitencoding")) {
FREE_AND_NULL(git_commit_encoding);
return git_config_string(&git_commit_encoding, var, value);
}
if (!strcmp(var, "i18n.logoutputencoding"))
if (!strcmp(var, "i18n.logoutputencoding")) {
FREE_AND_NULL(git_log_output_encoding);
return git_config_string(&git_log_output_encoding, var, value);
}
/* Add other config variables here and to Documentation/config.txt. */
return 0;
@ -1777,10 +1790,15 @@ static int git_default_push_config(const char *var, const char *value)
static int git_default_mailmap_config(const char *var, const char *value)
{
if (!strcmp(var, "mailmap.file"))
if (!strcmp(var, "mailmap.file")) {
FREE_AND_NULL(git_mailmap_file);
return git_config_pathname(&git_mailmap_file, var, value);
if (!strcmp(var, "mailmap.blob"))
}
if (!strcmp(var, "mailmap.blob")) {
FREE_AND_NULL(git_mailmap_blob);
return git_config_string(&git_mailmap_blob, var, value);
}
/* Add other config variables here and to Documentation/config.txt. */
return 0;
@ -1788,8 +1806,10 @@ static int git_default_mailmap_config(const char *var, const char *value)
static int git_default_attr_config(const char *var, const char *value)
{
if (!strcmp(var, "attr.tree"))
if (!strcmp(var, "attr.tree")) {
FREE_AND_NULL(git_attr_tree);
return git_config_string(&git_attr_tree, var, value);
}
/*
* Add other attribute related config variables here and to
@ -2416,7 +2436,7 @@ int git_configset_get_string(struct config_set *set, const char *key, char **des
{
const char *value;
if (!git_configset_get_value(set, key, &value, NULL))
return git_config_string((const char **)dest, key, value);
return git_config_string(dest, key, value);
else
return 1;
}
@ -2494,7 +2514,7 @@ int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *d
return 1;
}
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
int git_configset_get_pathname(struct config_set *set, const char *key, char **dest)
{
const char *value;
if (!git_configset_get_value(set, key, &value, NULL))
@ -2639,7 +2659,7 @@ int repo_config_get_maybe_bool(struct repository *repo,
}
int repo_config_get_pathname(struct repository *repo,
const char *key, const char **dest)
const char *key, char **dest)
{
int ret;
git_config_check_init(repo);
@ -2738,7 +2758,7 @@ int git_config_get_maybe_bool(const char *key, int *dest)
return repo_config_get_maybe_bool(the_repository, key, dest);
}
int git_config_get_pathname(const char *key, const char **dest)
int git_config_get_pathname(const char *key, char **dest)
{
return repo_config_get_pathname(the_repository, key, dest);
}

View file

@ -280,13 +280,13 @@ int git_config_bool(const char *, const char *);
* Allocates and copies the value string into the `dest` parameter; if no
* string is given, prints an error message and returns -1.
*/
int git_config_string(const char **, const char *, const char *);
int git_config_string(char **, const char *, const char *);
/**
* Similar to `git_config_string`, but expands `~` or `~user` into the
* user's home directory when found at the beginning of the path.
*/
int git_config_pathname(const char **, const char *, const char *);
int git_config_pathname(char **, const char *, const char *);
int git_config_expiry_date(timestamp_t *, const char *, const char *);
int git_config_color(char *, const char *, const char *);
@ -541,7 +541,7 @@ int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned lon
int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
int git_configset_get_pathname(struct config_set *cs, const char *key, char **dest);
/* Functions for reading a repository's config */
struct repository;
@ -577,7 +577,7 @@ int repo_config_get_bool_or_int(struct repository *repo,
int repo_config_get_maybe_bool(struct repository *repo,
const char *key, int *dest);
int repo_config_get_pathname(struct repository *repo,
const char *key, const char **dest);
const char *key, char **dest);
/*
* Functions for reading protected config. By definition, protected
@ -687,7 +687,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);
* Similar to `git_config_get_string`, but expands `~` or `~user` into
* the user's home directory when found at the beginning of the path.
*/
int git_config_get_pathname(const char *key, const char **dest);
int git_config_get_pathname(const char *key, char **dest);
int git_config_get_index_threads(int *dest);
int git_config_get_split_index(void);

View file

@ -37,6 +37,7 @@ DEVELOPER_CFLAGS += -Wpointer-arith
DEVELOPER_CFLAGS += -Wstrict-prototypes
DEVELOPER_CFLAGS += -Wunused
DEVELOPER_CFLAGS += -Wvla
DEVELOPER_CFLAGS += -Wwrite-strings
DEVELOPER_CFLAGS += -fno-common
ifneq ($(filter clang4,$(COMPILER_FEATURES)),)

View file

@ -345,30 +345,32 @@ static int check_roundtrip(const char *enc_name)
* space separated encodings (eg. "UTF-16, ASCII, CP1125").
* Search for the given encoding in that string.
*/
const char *found = strcasestr(check_roundtrip_encoding, enc_name);
const char *encoding = check_roundtrip_encoding ?
check_roundtrip_encoding : "SHIFT-JIS";
const char *found = strcasestr(encoding, enc_name);
const char *next;
int len;
if (!found)
return 0;
next = found + strlen(enc_name);
len = strlen(check_roundtrip_encoding);
len = strlen(encoding);
return (found && (
/*
* check that the found encoding is at the
* beginning of check_roundtrip_encoding or
* that it is prefixed with a space or comma
* Check that the found encoding is at the beginning of
* encoding or that it is prefixed with a space or
* comma.
*/
found == check_roundtrip_encoding || (
found == encoding || (
(isspace(found[-1]) || found[-1] == ',')
)
) && (
/*
* check that the found encoding is at the
* end of check_roundtrip_encoding or
* that it is suffixed with a space or comma
* Check that the found encoding is at the end of
* encoding or that it is suffixed with a space
* or comma.
*/
next == check_roundtrip_encoding + len || (
next < check_roundtrip_encoding + len &&
next == encoding + len || (
next < encoding + len &&
(isspace(next[0]) || next[0] == ',')
)
));
@ -979,9 +981,9 @@ int async_query_available_blobs(const char *cmd, struct string_list *available_p
static struct convert_driver {
const char *name;
struct convert_driver *next;
const char *smudge;
const char *clean;
const char *process;
char *smudge;
char *clean;
char *process;
int required;
} *user_convert, **user_convert_tail;

View file

@ -92,7 +92,7 @@ void convert_attrs(struct index_state *istate,
struct conv_attrs *ca, const char *path);
extern enum eol core_eol;
extern const char *check_roundtrip_encoding;
extern char *check_roundtrip_encoding;
const char *get_cached_convert_stats_ascii(struct index_state *istate,
const char *path);
const char *get_wt_convert_stats_ascii(const char *path);

View file

@ -313,7 +313,7 @@ struct island_load_data {
size_t nr;
size_t alloc;
};
static const char *core_island_name;
static char *core_island_name;
static void free_config_regexes(struct island_load_data *ild)
{

26
diff.c
View file

@ -56,14 +56,14 @@ static int diff_color_moved_default;
static int diff_color_moved_ws_default;
static int diff_context_default = 3;
static int diff_interhunk_context_default;
static const char *diff_word_regex_cfg;
static const char *external_diff_cmd_cfg;
static const char *diff_order_file_cfg;
static char *diff_word_regex_cfg;
static char *external_diff_cmd_cfg;
static char *diff_order_file_cfg;
int diff_auto_refresh_index = 1;
static int diff_mnemonic_prefix;
static int diff_no_prefix;
static const char *diff_src_prefix = "a/";
static const char *diff_dst_prefix = "b/";
static char *diff_src_prefix;
static char *diff_dst_prefix;
static int diff_relative;
static int diff_stat_name_width;
static int diff_stat_graph_width;
@ -411,9 +411,11 @@ int git_diff_ui_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "diff.srcprefix")) {
FREE_AND_NULL(diff_src_prefix);
return git_config_string(&diff_src_prefix, var, value);
}
if (!strcmp(var, "diff.dstprefix")) {
FREE_AND_NULL(diff_dst_prefix);
return git_config_string(&diff_dst_prefix, var, value);
}
if (!strcmp(var, "diff.relative")) {
@ -3433,8 +3435,8 @@ void diff_set_noprefix(struct diff_options *options)
void diff_set_default_prefix(struct diff_options *options)
{
options->a_prefix = diff_src_prefix;
options->b_prefix = diff_dst_prefix;
options->a_prefix = diff_src_prefix ? diff_src_prefix : "a/";
options->b_prefix = diff_dst_prefix ? diff_dst_prefix : "b/";
}
struct userdiff_driver *get_textconv(struct repository *r,
@ -3762,7 +3764,7 @@ static void builtin_diff(const char *name_a,
return;
}
static char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
static const char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
{
if (!is_renamed) {
if (p->status == DIFF_STATUS_ADDED) {
@ -4074,7 +4076,7 @@ static int reuse_worktree_file(struct index_state *istate,
static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
{
struct strbuf buf = STRBUF_INIT;
char *dirty = "";
const char *dirty = "";
/* Are we looking at the work tree? */
if (s->dirty_submodule)
@ -5371,8 +5373,8 @@ static int diff_opt_default_prefix(const struct option *opt,
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(optarg);
diff_src_prefix = "a/";
diff_dst_prefix = "b/";
FREE_AND_NULL(diff_src_prefix);
FREE_AND_NULL(diff_dst_prefix);
diff_set_default_prefix(options);
return 0;
}
@ -7233,7 +7235,7 @@ size_t fill_textconv(struct repository *r,
if (!driver) {
if (!DIFF_FILE_VALID(df)) {
*outbuf = "";
*outbuf = (char *) "";
return 0;
}
if (diff_populate_filespec(r, df, NULL))

View file

@ -406,7 +406,7 @@ static const char *get_highest_rename_path(struct strintmap *counts)
return highest_destination_dir;
}
static char *UNKNOWN_DIR = "/"; /* placeholder -- short, illegal directory */
static const char *UNKNOWN_DIR = "/"; /* placeholder -- short, illegal directory */
static int dir_rename_already_determinable(struct strintmap *counts)
{
@ -429,8 +429,8 @@ static int dir_rename_already_determinable(struct strintmap *counts)
}
static void increment_count(struct dir_rename_info *info,
char *old_dir,
char *new_dir)
const char *old_dir,
const char *new_dir)
{
struct strintmap *counts;
struct strmap_entry *e;

14
entry.c
View file

@ -167,6 +167,11 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
return !available;
}
static int string_is_not_null(struct string_list_item *item, void *data UNUSED)
{
return !!item->string;
}
int finish_delayed_checkout(struct checkout *state, int show_progress)
{
int errs = 0;
@ -189,7 +194,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
if (!async_query_available_blobs(filter->string, &available_paths)) {
/* Filter reported an error */
errs = 1;
filter->string = "";
filter->string = NULL;
continue;
}
if (available_paths.nr <= 0) {
@ -199,7 +204,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
* filter from the list (see
* "string_list_remove_empty_items" call below).
*/
filter->string = "";
filter->string = NULL;
continue;
}
@ -225,7 +230,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
* Do not ask the filter for available blobs,
* again, as the filter is likely buggy.
*/
filter->string = "";
filter->string = NULL;
continue;
}
ce = index_file_exists(state->istate, path->string,
@ -239,7 +244,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
errs = 1;
}
}
string_list_remove_empty_items(&dco->filters, 0);
filter_string_list(&dco->filters, 0, string_is_not_null, NULL);
}
stop_progress(&progress);
string_list_clear(&dco->filters, 0);

View file

@ -42,12 +42,12 @@ int is_bare_repository_cfg = -1; /* unspecified */
int warn_ambiguous_refs = 1;
int warn_on_object_refname_ambiguity = 1;
int repository_format_precious_objects;
const char *git_commit_encoding;
const char *git_log_output_encoding;
char *git_commit_encoding;
char *git_log_output_encoding;
char *apply_default_whitespace;
char *apply_default_ignorewhitespace;
const char *git_attributes_file;
const char *git_hooks_path;
char *git_attributes_file;
char *git_hooks_path;
int zlib_compression_level = Z_BEST_SPEED;
int pack_compression_level = Z_DEFAULT_COMPRESSION;
int fsync_object_files = -1;
@ -58,13 +58,13 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
size_t delta_base_cache_limit = 96 * 1024 * 1024;
unsigned long big_file_threshold = 512 * 1024 * 1024;
const char *editor_program;
const char *askpass_program;
const char *excludes_file;
char *editor_program;
char *askpass_program;
char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
enum eol core_eol = EOL_UNSET;
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
const char *check_roundtrip_encoding = "SHIFT-JIS";
char *check_roundtrip_encoding;
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;

View file

@ -131,8 +131,8 @@ extern int warn_ambiguous_refs;
extern int warn_on_object_refname_ambiguity;
extern char *apply_default_whitespace;
extern char *apply_default_ignorewhitespace;
extern const char *git_attributes_file;
extern const char *git_hooks_path;
extern char *git_attributes_file;
extern char *git_hooks_path;
extern int zlib_compression_level;
extern int pack_compression_level;
extern size_t packed_git_window_size;
@ -224,12 +224,12 @@ int odb_pack_keep(const char *name);
const char *get_log_output_encoding(void);
const char *get_commit_output_encoding(void);
extern const char *git_commit_encoding;
extern const char *git_log_output_encoding;
extern char *git_commit_encoding;
extern char *git_log_output_encoding;
extern const char *editor_program;
extern const char *askpass_program;
extern const char *excludes_file;
extern char *editor_program;
extern char *askpass_program;
extern char *excludes_file;
/*
* Should we print an ellipsis after an abbreviated SHA-1 value

View file

@ -1860,13 +1860,13 @@ static int fetch_pack_config_cb(const char *var, const char *value,
const char *msg_id;
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
const char *path;
char *path ;
if (git_config_pathname(&path, var, value))
return 1;
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
fsck_msg_types.len ? ',' : '=', path);
free((char *)path);
free(path);
return 0;
}

View file

@ -447,7 +447,7 @@ static void fmt_merge_msg_title(struct strbuf *out,
const char *current_branch)
{
int i = 0;
char *sep = "";
const char *sep = "";
strbuf_addstr(out, "Merge ");
for (i = 0; i < srcs.nr; i++) {

6
fsck.c
View file

@ -1231,7 +1231,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
}
int fsck_buffer(const struct object_id *oid, enum object_type type,
void *data, unsigned long size,
const void *data, unsigned long size,
struct fsck_options *options)
{
if (type == OBJ_BLOB)
@ -1330,13 +1330,13 @@ int git_fsck_config(const char *var, const char *value,
const char *msg_id;
if (strcmp(var, "fsck.skiplist") == 0) {
const char *path;
char *path;
struct strbuf sb = STRBUF_INIT;
if (git_config_pathname(&path, var, value))
return 1;
strbuf_addf(&sb, "skiplist=%s", path);
free((char *)path);
free(path);
fsck_set_msg_types(options, sb.buf);
strbuf_release(&sb);
return 0;

2
fsck.h
View file

@ -202,7 +202,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
* struct.
*/
int fsck_buffer(const struct object_id *oid, enum object_type,
void *data, unsigned long size,
const void *data, unsigned long size,
struct fsck_options *options);
/*

View file

@ -103,6 +103,7 @@ static struct fsmonitor_settings *alloc_settings(void)
static void lookup_fsmonitor_settings(struct repository *r)
{
const char *const_str;
char *to_free = NULL;
int bool_value;
if (r->settings.fsmonitor)
@ -129,8 +130,9 @@ static void lookup_fsmonitor_settings(struct repository *r)
break;
case -1: /* config value set to an arbitrary string */
if (repo_config_get_pathname(r, "core.fsmonitor", &const_str))
if (repo_config_get_pathname(r, "core.fsmonitor", &to_free))
return; /* should not happen */
const_str = to_free;
break;
default: /* should not happen */
@ -141,6 +143,7 @@ static void lookup_fsmonitor_settings(struct repository *r)
fsm_settings__set_hook(r, const_str);
else
fsm_settings__set_disabled(r);
free(to_free);
}
enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)

View file

@ -27,7 +27,9 @@ static void gpg_interface_lazy_init(void)
}
static char *configured_signing_key;
static const char *ssh_default_key_command, *ssh_allowed_signers, *ssh_revocation_file;
static char *ssh_default_key_command;
static char *ssh_allowed_signers;
static char *ssh_revocation_file;
static enum signature_trust_level configured_min_trust_level = TRUST_UNDEFINED;
struct gpg_format {
@ -725,7 +727,7 @@ static int git_gpg_config(const char *var, const char *value,
void *cb UNUSED)
{
struct gpg_format *fmt = NULL;
char *fmtname = NULL;
const char *fmtname = NULL;
char *trust;
int ret;
@ -781,7 +783,7 @@ static int git_gpg_config(const char *var, const char *value,
if (fmtname) {
fmt = get_format_by_name(fmtname);
return git_config_string(&fmt->program, var, value);
return git_config_string((char **) &fmt->program, var, value);
}
return 0;

View file

@ -753,7 +753,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
int cmd_main(int argc UNUSED, const char **argv UNUSED)
{
char *method = getenv("REQUEST_METHOD");
const char *method = getenv("REQUEST_METHOD");
const char *proto_header;
char *dir;
struct service_cmd *cmd = NULL;

55
http.c
View file

@ -38,11 +38,11 @@ char curl_errorstr[CURL_ERROR_SIZE];
static int curl_ssl_verify = -1;
static int curl_ssl_try;
static const char *curl_http_version = NULL;
static const char *ssl_cert;
static const char *ssl_cert_type;
static const char *ssl_cipherlist;
static const char *ssl_version;
static char *curl_http_version;
static char *ssl_cert;
static char *ssl_cert_type;
static char *ssl_cipherlist;
static char *ssl_version;
static struct {
const char *name;
long ssl_version;
@ -59,23 +59,23 @@ static struct {
{ "tlsv1.3", CURL_SSLVERSION_TLSv1_3 },
#endif
};
static const char *ssl_key;
static const char *ssl_key_type;
static const char *ssl_capath;
static const char *curl_no_proxy;
static char *ssl_key;
static char *ssl_key_type;
static char *ssl_capath;
static char *curl_no_proxy;
#ifdef GIT_CURL_HAVE_CURLOPT_PINNEDPUBLICKEY
static const char *ssl_pinnedkey;
static char *ssl_pinnedkey;
#endif
static const char *ssl_cainfo;
static char *ssl_cainfo;
static long curl_low_speed_limit = -1;
static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv;
static const char *curl_http_proxy;
static const char *http_proxy_authmethod;
static char *curl_http_proxy;
static char *http_proxy_authmethod;
static const char *http_proxy_ssl_cert;
static const char *http_proxy_ssl_key;
static const char *http_proxy_ssl_ca_info;
static char *http_proxy_ssl_cert;
static char *http_proxy_ssl_key;
static char *http_proxy_ssl_ca_info;
static struct credential proxy_cert_auth = CREDENTIAL_INIT;
static int proxy_ssl_cert_password_required;
@ -95,7 +95,7 @@ static struct {
*/
};
#ifdef CURLGSSAPI_DELEGATION_FLAG
static const char *curl_deleg;
static char *curl_deleg;
static struct {
const char *name;
long curl_deleg_param;
@ -108,11 +108,11 @@ static struct {
static struct credential proxy_auth = CREDENTIAL_INIT;
static const char *curl_proxyuserpwd;
static const char *curl_cookie_file;
static char *curl_cookie_file;
static int curl_save_cookies;
struct credential http_auth = CREDENTIAL_INIT;
static int http_proactive_auth;
static const char *user_agent;
static char *user_agent;
static int curl_empty_auth = -1;
enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
@ -592,10 +592,10 @@ static void init_curl_http_auth(CURL *result)
}
/* *var must be free-able */
static void var_override(const char **var, char *value)
static void var_override(char **var, char *value)
{
if (value) {
free((void *)*var);
free(*var);
*var = xstrdup(value);
}
}
@ -1233,11 +1233,13 @@ static CURL *get_curl_handle(void)
return result;
}
static void set_from_env(const char **var, const char *envname)
static void set_from_env(char **var, const char *envname)
{
const char *val = getenv(envname);
if (val)
*var = val;
if (val) {
FREE_AND_NULL(*var);
*var = xstrdup(val);
}
}
void http_init(struct remote *remote, const char *url, int proactive_auth)
@ -1972,7 +1974,7 @@ static void write_accept_language(struct strbuf *buf)
/* add '*' */
REALLOC_ARRAY(language_tags, num_langs + 1);
language_tags[num_langs++] = "*"; /* it's OK; this won't be freed */
language_tags[num_langs++] = xstrdup("*");
/* compute decimal_places */
for (max_q = 1, decimal_places = 0;
@ -2002,8 +2004,7 @@ static void write_accept_language(struct strbuf *buf)
}
}
/* free language tags -- last one is a static '*' */
for (i = 0; i < num_langs - 1; i++)
for (i = 0; i < num_langs; i++)
free(language_tags[i]);
free(language_tags);
}

View file

@ -46,9 +46,9 @@ static struct passwd *xgetpwuid_self(int *is_bogus)
pw = getpwuid(getuid());
if (!pw) {
static struct passwd fallback;
fallback.pw_name = "unknown";
fallback.pw_name = (char *) "unknown";
#ifndef NO_GECOS_IN_PWENT
fallback.pw_gecos = "Unknown";
fallback.pw_gecos = (char *) "Unknown";
#endif
pw = &fallback;
if (is_bogus)

View file

@ -69,21 +69,16 @@ static void imap_warn(const char *, ...);
static char *next_arg(char **);
struct imap_server_conf {
const char *name;
const char *tunnel;
const char *host;
char *tunnel;
char *host;
int port;
const char *folder;
const char *user;
const char *pass;
char *folder;
char *user;
char *pass;
int use_ssl;
int ssl_verify;
int use_html;
const char *auth_method;
};
static struct imap_server_conf server = {
.ssl_verify = 1,
char *auth_method;
};
struct imap_socket {
@ -110,6 +105,7 @@ struct imap {
};
struct imap_store {
const struct imap_server_conf *cfg;
/* currently open mailbox */
const char *name; /* foreign! maybe preset? */
int uidvalidity;
@ -194,8 +190,8 @@ static void socket_perror(const char *func, struct imap_socket *sock, int ret)
#ifdef NO_OPENSSL
static int ssl_socket_connect(struct imap_socket *sock UNUSED,
int use_tls_only UNUSED,
int verify UNUSED)
const struct imap_server_conf *cfg,
int use_tls_only UNUSED)
{
fprintf(stderr, "SSL requested but SSL support not compiled in\n");
return -1;
@ -250,7 +246,9 @@ static int verify_hostname(X509 *cert, const char *hostname)
cname, hostname);
}
static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int verify)
static int ssl_socket_connect(struct imap_socket *sock,
const struct imap_server_conf *cfg,
int use_tls_only)
{
#if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
const SSL_METHOD *meth;
@ -279,7 +277,7 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
if (use_tls_only)
SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
if (verify)
if (cfg->ssl_verify)
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
if (!SSL_CTX_set_default_verify_paths(ctx)) {
@ -306,9 +304,9 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
* OpenSSL does not document this function, but the implementation
* returns 1 on success, 0 on failure after calling SSLerr().
*/
ret = SSL_set_tlsext_host_name(sock->ssl, server.host);
ret = SSL_set_tlsext_host_name(sock->ssl, cfg->host);
if (ret != 1)
warning("SSL_set_tlsext_host_name(%s) failed.", server.host);
warning("SSL_set_tlsext_host_name(%s) failed.", cfg->host);
#endif
ret = SSL_connect(sock->ssl);
@ -317,12 +315,12 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
return -1;
}
if (verify) {
if (cfg->ssl_verify) {
/* make sure the hostname matches that of the certificate */
cert = SSL_get_peer_certificate(sock->ssl);
if (!cert)
return error("unable to get peer certificate.");
if (verify_hostname(cert, server.host) < 0)
if (verify_hostname(cert, cfg->host) < 0)
return -1;
}
@ -895,7 +893,7 @@ static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
int ret;
char *response;
response = cram(prompt, server.user, server.pass);
response = cram(prompt, ctx->cfg->user, ctx->cfg->pass);
ret = socket_write(&ctx->imap->buf.sock, response, strlen(response));
if (ret != strlen(response))
@ -935,6 +933,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
CALLOC_ARRAY(ctx, 1);
ctx->cfg = srvc;
ctx->imap = CALLOC_ARRAY(imap, 1);
imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;
imap->in_progress_append = &imap->in_progress;
@ -1035,7 +1034,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
imap->buf.sock.fd[1] = dup(s);
if (srvc->use_ssl &&
ssl_socket_connect(&imap->buf.sock, 0, srvc->ssl_verify)) {
ssl_socket_connect(&imap->buf.sock, srvc, 0)) {
close(s);
goto bail;
}
@ -1068,8 +1067,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
if (!srvc->use_ssl && CAP(STARTTLS)) {
if (imap_exec(ctx, NULL, "STARTTLS") != RESP_OK)
goto bail;
if (ssl_socket_connect(&imap->buf.sock, 1,
srvc->ssl_verify))
if (ssl_socket_connect(&imap->buf.sock, srvc, 1))
goto bail;
/* capabilities may have changed, so get the new capabilities */
if (imap_exec(ctx, NULL, "CAPABILITY") != RESP_OK)
@ -1215,9 +1213,9 @@ static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg)
static void wrap_in_html(struct strbuf *msg)
{
struct strbuf buf = STRBUF_INIT;
static char *content_type = "Content-Type: text/html;\n";
static char *pre_open = "<pre>\n";
static char *pre_close = "</pre>\n";
static const char *content_type = "Content-Type: text/html;\n";
static const char *pre_open = "<pre>\n";
static const char *pre_close = "</pre>\n";
const char *body = strstr(msg->buf, "\n\n");
if (!body)
@ -1299,24 +1297,30 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
static int git_imap_config(const char *var, const char *val,
const struct config_context *ctx, void *cb)
{
struct imap_server_conf *cfg = cb;
if (!strcmp("imap.sslverify", var))
server.ssl_verify = git_config_bool(var, val);
else if (!strcmp("imap.preformattedhtml", var))
server.use_html = git_config_bool(var, val);
else if (!strcmp("imap.folder", var))
return git_config_string(&server.folder, var, val);
else if (!strcmp("imap.user", var))
return git_config_string(&server.user, var, val);
else if (!strcmp("imap.pass", var))
return git_config_string(&server.pass, var, val);
else if (!strcmp("imap.tunnel", var))
return git_config_string(&server.tunnel, var, val);
else if (!strcmp("imap.authmethod", var))
return git_config_string(&server.auth_method, var, val);
else if (!strcmp("imap.port", var))
server.port = git_config_int(var, val, ctx->kvi);
else if (!strcmp("imap.host", var)) {
if (!strcmp("imap.sslverify", var)) {
cfg->ssl_verify = git_config_bool(var, val);
} else if (!strcmp("imap.preformattedhtml", var)) {
cfg->use_html = git_config_bool(var, val);
} else if (!strcmp("imap.folder", var)) {
FREE_AND_NULL(cfg->folder);
return git_config_string(&cfg->folder, var, val);
} else if (!strcmp("imap.user", var)) {
FREE_AND_NULL(cfg->folder);
return git_config_string(&cfg->user, var, val);
} else if (!strcmp("imap.pass", var)) {
FREE_AND_NULL(cfg->folder);
return git_config_string(&cfg->pass, var, val);
} else if (!strcmp("imap.tunnel", var)) {
FREE_AND_NULL(cfg->folder);
return git_config_string(&cfg->tunnel, var, val);
} else if (!strcmp("imap.authmethod", var)) {
FREE_AND_NULL(cfg->folder);
return git_config_string(&cfg->auth_method, var, val);
} else if (!strcmp("imap.port", var)) {
cfg->port = git_config_int(var, val, ctx->kvi);
} else if (!strcmp("imap.host", var)) {
if (!val) {
return config_error_nonbool(var);
} else {
@ -1324,14 +1328,15 @@ static int git_imap_config(const char *var, const char *val,
val += 5;
else if (starts_with(val, "imaps:")) {
val += 6;
server.use_ssl = 1;
cfg->use_ssl = 1;
}
if (starts_with(val, "//"))
val += 2;
server.host = xstrdup(val);
cfg->host = xstrdup(val);
}
} else
} else {
return git_default_config(var, val, ctx, cb);
}
return 0;
}
@ -1497,12 +1502,16 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
int cmd_main(int argc, const char **argv)
{
struct imap_server_conf server = {
.ssl_verify = 1,
};
struct strbuf all_msgs = STRBUF_INIT;
int total;
int nongit_ok;
int ret;
setup_git_directory_gently(&nongit_ok);
git_config(git_imap_config, NULL);
git_config(git_imap_config, &server);
argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
@ -1526,42 +1535,55 @@ int cmd_main(int argc, const char **argv)
if (!server.folder) {
fprintf(stderr, "no imap store specified\n");
return 1;
ret = 1;
goto out;
}
if (!server.host) {
if (!server.tunnel) {
fprintf(stderr, "no imap host specified\n");
return 1;
ret = 1;
goto out;
}
server.host = "tunnel";
server.host = xstrdup("tunnel");
}
/* read the messages */
if (strbuf_read(&all_msgs, 0, 0) < 0) {
error_errno(_("could not read from stdin"));
return 1;
ret = 1;
goto out;
}
if (all_msgs.len == 0) {
fprintf(stderr, "nothing to send\n");
return 1;
ret = 1;
goto out;
}
total = count_messages(&all_msgs);
if (!total) {
fprintf(stderr, "no messages to send\n");
return 1;
ret = 1;
goto out;
}
/* write it to the imap server */
if (server.tunnel)
return append_msgs_to_imap(&server, &all_msgs, total);
ret = append_msgs_to_imap(&server, &all_msgs, total);
#ifdef USE_CURL_FOR_IMAP_SEND
if (use_curl)
return curl_append_msgs_to_imap(&server, &all_msgs, total);
else if (use_curl)
ret = curl_append_msgs_to_imap(&server, &all_msgs, total);
#endif
else
ret = append_msgs_to_imap(&server, &all_msgs, total);
return append_msgs_to_imap(&server, &all_msgs, total);
out:
free(server.tunnel);
free(server.host);
free(server.folder);
free(server.user);
free(server.pass);
free(server.auth_method);
return ret;
}

View file

@ -899,14 +899,12 @@ static void print_line(const char *prefix, char first,
static char *output_prefix(struct diff_options *opt)
{
char *prefix = "";
if (opt->output_prefix) {
struct strbuf *sb = opt->output_prefix(opt, opt->output_prefix_data);
prefix = sb->buf;
return sb->buf;
} else {
return xstrdup("");
}
return prefix;
}
static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *range)
@ -927,7 +925,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
const char *c_context = diff_get_color(opt->use_color, DIFF_CONTEXT);
if (!pair || !diff)
return;
goto out;
if (pair->one->oid_valid)
fill_line_ends(rev->diffopt.repo, pair->one, &p_lines, &p_ends);
@ -1002,8 +1000,10 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
c_context, c_reset, opt->file);
}
out:
free(p_ends);
free(t_ends);
free(prefix);
}
/*
@ -1012,7 +1012,11 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
*/
static void dump_diff_hacky(struct rev_info *rev, struct line_log_data *range)
{
fprintf(rev->diffopt.file, "%s\n", output_prefix(&rev->diffopt));
char *prefix = output_prefix(&rev->diffopt);
fprintf(rev->diffopt.file, "%s\n", prefix);
free(prefix);
while (range) {
dump_diff_hacky_one(rev, range);
range = range->next;
@ -1032,6 +1036,7 @@ static int process_diff_filepair(struct rev_info *rev,
struct range_set tmp;
struct diff_ranges diff;
mmfile_t file_parent, file_target;
char *parent_data_to_free = NULL;
assert(pair->two->path);
while (rg) {
@ -1056,7 +1061,7 @@ static int process_diff_filepair(struct rev_info *rev,
file_parent.ptr = pair->one->data;
file_parent.size = pair->one->size;
} else {
file_parent.ptr = "";
file_parent.ptr = parent_data_to_free = xstrdup("");
file_parent.size = 0;
}
@ -1075,6 +1080,7 @@ static int process_diff_filepair(struct rev_info *rev,
diff_ranges_release(&diff);
free(parent_data_to_free);
return ((*diff_out)->parent.nr > 0);
}

View file

@ -6,8 +6,8 @@
#include "object-store-ll.h"
#include "setup.h"
const char *git_mailmap_file;
const char *git_mailmap_blob;
char *git_mailmap_file;
char *git_mailmap_blob;
struct mailmap_info {
char *name;
@ -216,7 +216,7 @@ int read_mailmap(struct string_list *map)
map->cmp = namemap_cmp;
if (!git_mailmap_blob && is_bare_repository())
git_mailmap_blob = "HEAD:.mailmap";
git_mailmap_blob = xstrdup("HEAD:.mailmap");
if (!startup_info->have_repository || !is_bare_repository())
err |= read_mailmap_file(map, ".mailmap",

View file

@ -3,8 +3,8 @@
struct string_list;
extern const char *git_mailmap_file;
extern const char *git_mailmap_blob;
extern char *git_mailmap_file;
extern char *git_mailmap_blob;
int read_mailmap(struct string_list *map);
void clear_mailmap(struct string_list *map);

View file

@ -29,7 +29,7 @@ struct ll_merge_driver {
const char *name;
const char *description;
ll_merge_fn fn;
const char *recursive;
char *recursive;
struct ll_merge_driver *next;
char *cmdline;
};
@ -268,7 +268,7 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
* merge.default and merge.driver configuration items
*/
static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
static const char *default_ll_merge;
static char *default_ll_merge;
static int read_merge_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
@ -304,8 +304,13 @@ static int read_merge_config(const char *var, const char *value,
ll_user_merge_tail = &(fn->next);
}
if (!strcmp("name", key))
return git_config_string(&fn->description, var, value);
if (!strcmp("name", key)) {
/*
* The description is leaking, but that's okay as we want to
* keep around the merge drivers anyway.
*/
return git_config_string((char **) &fn->description, var, value);
}
if (!strcmp("driver", key)) {
if (!value)

View file

@ -277,7 +277,7 @@ int hash_algo_by_length(int len)
static struct cached_object {
struct object_id oid;
enum object_type type;
void *buf;
const void *buf;
unsigned long size;
} *cached_objects;
static int cached_object_nr, cached_object_alloc;
@ -1778,6 +1778,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
struct object_id *oid)
{
struct cached_object *co;
char *co_buf;
hash_object_file(the_hash_algo, buf, len, type, oid);
if (repo_has_object_file_with_flags(the_repository, oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) ||
@ -1787,8 +1788,9 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
co = &cached_objects[cached_object_nr++];
co->size = len;
co->type = type;
co->buf = xmalloc(len);
memcpy(co->buf, buf, len);
co_buf = xmalloc(len);
memcpy(co_buf, buf, len);
co->buf = co_buf;
oidcpy(&co->oid, oid);
return 0;
}
@ -2482,12 +2484,13 @@ static int hash_format_check_report(struct fsck_options *opts UNUSED,
}
static int index_mem(struct index_state *istate,
struct object_id *oid, void *buf, size_t size,
struct object_id *oid,
const void *buf, size_t size,
enum object_type type,
const char *path, unsigned flags)
{
struct strbuf nbuf = STRBUF_INIT;
int ret = 0;
int re_allocated = 0;
int write_object = flags & HASH_WRITE_OBJECT;
if (!type)
@ -2497,11 +2500,10 @@ static int index_mem(struct index_state *istate,
* Convert blobs to git internal format
*/
if ((type == OBJ_BLOB) && path) {
struct strbuf nbuf = STRBUF_INIT;
if (convert_to_git(istate, path, buf, size, &nbuf,
get_conv_flags(flags))) {
buf = strbuf_detach(&nbuf, &size);
re_allocated = 1;
buf = nbuf.buf;
size = nbuf.len;
}
}
if (flags & HASH_FORMAT_CHECK) {
@ -2518,8 +2520,8 @@ static int index_mem(struct index_state *istate,
ret = write_object_file(buf, size, type, oid);
else
hash_object_file(the_hash_algo, buf, size, type, oid);
if (re_allocated)
free(buf);
strbuf_release(&nbuf);
return ret;
}

View file

@ -13,7 +13,7 @@ int pager_use_color = 1;
#endif
static struct child_process pager_process;
static const char *pager_program;
static char *pager_program;
/* Is the value coming back from term_columns() just a guess? */
static int term_columns_guessed;

View file

@ -355,7 +355,7 @@ struct option {
.type = OPTION_ALIAS, \
.short_name = (s), \
.long_name = (l), \
.value = (source_long_name), \
.value = (char *)(source_long_name), \
}
#define OPT_SUBCOMMAND_F(l, v, fn, f) { \

View file

@ -62,7 +62,7 @@ static int git_pretty_formats_config(const char *var, const char *value,
{
struct cmt_fmt_map *commit_format = NULL;
const char *name;
const char *fmt;
char *fmt;
int i;
if (!skip_prefix(var, "pretty.", &name))
@ -93,13 +93,17 @@ static int git_pretty_formats_config(const char *var, const char *value,
if (git_config_string(&fmt, var, value))
return -1;
if (skip_prefix(fmt, "format:", &fmt))
if (skip_prefix(fmt, "format:", &commit_format->user_format)) {
commit_format->is_tformat = 0;
else if (skip_prefix(fmt, "tformat:", &fmt) || strchr(fmt, '%'))
} else if (skip_prefix(fmt, "tformat:", &commit_format->user_format)) {
commit_format->is_tformat = 1;
else
} else if (strchr(fmt, '%')) {
commit_format->is_tformat = 1;
commit_format->user_format = fmt;
} else {
commit_format->is_alias = 1;
commit_format->user_format = fmt;
}
return 0;
}
@ -1321,7 +1325,7 @@ int format_set_trailers_options(struct process_trailer_options *opts,
static size_t parse_describe_args(const char *start, struct strvec *args)
{
struct {
char *name;
const char *name;
enum {
DESCRIBE_ARG_BOOL,
DESCRIBE_ARG_INTEGER,
@ -1580,8 +1584,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
case 'D':
{
const struct decoration_options opts = {
.prefix = "",
.suffix = ""
.prefix = (char *) "",
.suffix = (char *) "",
};
format_decorations(sb, commit, c->auto_color, &opts);

View file

@ -13,7 +13,7 @@ struct object_id;
*/
struct promisor_remote {
struct promisor_remote *next;
const char *partial_clone_filter;
char *partial_clone_filter;
const char name[FLEX_ARRAY];
};

2
refs.c
View file

@ -158,7 +158,7 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref)
{
struct ref_namespace_info *info = &ref_namespace[namespace];
if (info->ref_updated)
free(info->ref);
free((char *)info->ref);
info->ref = ref;
info->ref_updated = 1;
}

2
refs.h
View file

@ -968,7 +968,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt);
*/
struct ref_namespace_info {
char *ref;
const char *ref;
enum decoration_type decoration;
/*

View file

@ -1398,10 +1398,10 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
* old reference.
*/
refs[0] = old_ref;
refs[0].refname = (char *)arg->newname;
refs[0].refname = xstrdup(arg->newname);
refs[0].update_index = creation_ts;
if (arg->delete_old) {
refs[1].refname = (char *)arg->oldname;
refs[1].refname = xstrdup(arg->oldname);
refs[1].value_type = REFTABLE_REF_DELETION;
refs[1].update_index = deletion_ts;
}
@ -1424,7 +1424,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
memset(&logs[logs_nr], 0, sizeof(logs[logs_nr]));
fill_reftable_log_record(&logs[logs_nr], &committer_ident);
logs[logs_nr].refname = (char *)arg->newname;
logs[logs_nr].refname = xstrdup(arg->newname);
logs[logs_nr].update_index = deletion_ts;
logs[logs_nr].value.update.message =
xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
@ -1445,7 +1445,13 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
if (append_head_reflog) {
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
logs[logs_nr] = logs[logs_nr - 1];
logs[logs_nr].refname = "HEAD";
logs[logs_nr].refname = xstrdup("HEAD");
logs[logs_nr].value.update.name =
xstrdup(logs[logs_nr].value.update.name);
logs[logs_nr].value.update.email =
xstrdup(logs[logs_nr].value.update.email);
logs[logs_nr].value.update.message =
xstrdup(logs[logs_nr].value.update.message);
logs_nr++;
}
}
@ -1456,7 +1462,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
memset(&logs[logs_nr], 0, sizeof(logs[logs_nr]));
fill_reftable_log_record(&logs[logs_nr], &committer_ident);
logs[logs_nr].refname = (char *)arg->newname;
logs[logs_nr].refname = xstrdup(arg->newname);
logs[logs_nr].update_index = creation_ts;
logs[logs_nr].value.update.message =
xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
@ -1489,7 +1495,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
*/
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
logs[logs_nr] = old_log;
logs[logs_nr].refname = (char *)arg->newname;
logs[logs_nr].refname = xstrdup(arg->newname);
logs_nr++;
/*
@ -1498,7 +1504,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
if (arg->delete_old) {
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
memset(&logs[logs_nr], 0, sizeof(logs[logs_nr]));
logs[logs_nr].refname = (char *)arg->oldname;
logs[logs_nr].refname = xstrdup(arg->oldname);
logs[logs_nr].value_type = REFTABLE_LOG_DELETION;
logs[logs_nr].update_index = old_log.update_index;
logs_nr++;
@ -1521,13 +1527,11 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
reftable_iterator_destroy(&it);
string_list_clear(&skip, 0);
strbuf_release(&errbuf);
for (i = 0; i < logs_nr; i++) {
if (!strcmp(logs[i].refname, "HEAD"))
continue;
logs[i].refname = NULL;
for (i = 0; i < logs_nr; i++)
reftable_log_record_release(&logs[i]);
}
free(logs);
for (i = 0; i < ARRAY_SIZE(refs); i++)
reftable_ref_record_release(&refs[i]);
reftable_ref_record_release(&old_ref);
reftable_log_record_release(&old_log);
return ret;

View file

@ -7,19 +7,6 @@
#include "refspec.h"
#include "strbuf.h"
static struct refspec_item s_tag_refspec = {
.force = 0,
.pattern = 1,
.matching = 0,
.exact_sha1 = 0,
.negative = 0,
.src = "refs/tags/*",
.dst = "refs/tags/*",
};
/* See TAG_REFSPEC for the string version */
const struct refspec_item *tag_refspec = &s_tag_refspec;
/*
* Parses the provided refspec 'refspec' and populates the refspec_item 'item'.
* Returns 1 if successful and 0 if the refspec is invalid.

View file

@ -2,7 +2,6 @@
#define REFSPEC_H
#define TAG_REFSPEC "refs/tags/*:refs/tags/*"
extern const struct refspec_item *tag_refspec;
/**
* A struct refspec_item holds the parsed interpretation of a refspec. If it

View file

@ -67,9 +67,9 @@ void free_names(char **a)
reftable_free(a);
}
size_t names_length(char **names)
size_t names_length(const char **names)
{
char **p = names;
const char **p = names;
while (*p)
p++;
return p - names;
@ -102,15 +102,12 @@ void parse_names(char *buf, int size, char ***namesp)
*namesp = names;
}
int names_equal(char **a, char **b)
int names_equal(const char **a, const char **b)
{
int i = 0;
for (; a[i] && b[i]; i++) {
if (strcmp(a[i], b[i])) {
size_t i = 0;
for (; a[i] && b[i]; i++)
if (strcmp(a[i], b[i]))
return 0;
}
}
return a[i] == b[i];
}

View file

@ -42,10 +42,10 @@ void free_names(char **a);
void parse_names(char *buf, int size, char ***namesp);
/* compares two NULL-terminated arrays of strings. */
int names_equal(char **a, char **b);
int names_equal(const char **a, const char **b);
/* returns the array size of a NULL-terminated array of strings. */
size_t names_length(char **names);
size_t names_length(const char **names);
/* Allocation routines; they invoke the functions set through
* reftable_set_alloc() */

View file

@ -58,8 +58,8 @@ static void test_binsearch(void)
static void test_names_length(void)
{
char *a[] = { "a", "b", NULL };
EXPECT(names_length(a) == 2);
const char *names[] = { "a", "b", NULL };
EXPECT(names_length(names) == 2);
}
static void test_parse_names_normal(void)

View file

@ -42,7 +42,7 @@ static void test_block_read_write(void)
block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
rec.u.ref.refname = "";
rec.u.ref.refname = (char *) "";
rec.u.ref.value_type = REFTABLE_REF_DELETION;
n = block_writer_add(&bw, &rec);
EXPECT(n == REFTABLE_API_ERROR);

View file

@ -125,13 +125,13 @@ static void readers_destroy(struct reftable_reader **readers, size_t n)
static void test_merged_between(void)
{
struct reftable_ref_record r1[] = { {
.refname = "b",
.refname = (char *) "b",
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 1, 2, 3, 0 },
} };
struct reftable_ref_record r2[] = { {
.refname = "a",
.refname = (char *) "a",
.update_index = 2,
.value_type = REFTABLE_REF_DELETION,
} };
@ -169,38 +169,38 @@ static void test_merged(void)
{
struct reftable_ref_record r1[] = {
{
.refname = "a",
.refname = (char *) "a",
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 1 },
},
{
.refname = "b",
.refname = (char *) "b",
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 1 },
},
{
.refname = "c",
.refname = (char *) "c",
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 1 },
}
};
struct reftable_ref_record r2[] = { {
.refname = "a",
.refname = (char *) "a",
.update_index = 2,
.value_type = REFTABLE_REF_DELETION,
} };
struct reftable_ref_record r3[] = {
{
.refname = "c",
.refname = (char *) "c",
.update_index = 3,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 2 },
},
{
.refname = "d",
.refname = (char *) "d",
.update_index = 3,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = { 1 },
@ -296,46 +296,46 @@ static void test_merged_logs(void)
{
struct reftable_log_record r1[] = {
{
.refname = "a",
.refname = (char *) "a",
.update_index = 2,
.value_type = REFTABLE_LOG_UPDATE,
.value.update = {
.old_hash = { 2 },
/* deletion */
.name = "jane doe",
.email = "jane@invalid",
.message = "message2",
.name = (char *) "jane doe",
.email = (char *) "jane@invalid",
.message = (char *) "message2",
}
},
{
.refname = "a",
.refname = (char *) "a",
.update_index = 1,
.value_type = REFTABLE_LOG_UPDATE,
.value.update = {
.old_hash = { 1 },
.new_hash = { 2 },
.name = "jane doe",
.email = "jane@invalid",
.message = "message1",
.name = (char *) "jane doe",
.email = (char *) "jane@invalid",
.message = (char *) "message1",
}
},
};
struct reftable_log_record r2[] = {
{
.refname = "a",
.refname = (char *) "a",
.update_index = 3,
.value_type = REFTABLE_LOG_UPDATE,
.value.update = {
.new_hash = { 3 },
.name = "jane doe",
.email = "jane@invalid",
.message = "message3",
.name = (char *) "jane doe",
.email = (char *) "jane@invalid",
.message = (char *) "message3",
}
},
};
struct reftable_log_record r3[] = {
{
.refname = "a",
.refname = (char *) "a",
.update_index = 2,
.value_type = REFTABLE_LOG_DELETION,
},
@ -413,7 +413,7 @@ static void test_default_write_opts(void)
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
struct reftable_ref_record rec = {
.refname = "master",
.refname = (char *) "master",
.update_index = 1,
};
int err;

View file

@ -86,7 +86,7 @@ static void write_table(char ***names, struct strbuf *buf, int N,
log.update_index = update_index;
log.value_type = REFTABLE_LOG_UPDATE;
set_test_hash(log.value.update.new_hash, i);
log.value.update.message = "message";
log.value.update.message = (char *) "message";
n = reftable_writer_add_log(w, &log);
EXPECT(n == 0);
@ -118,15 +118,15 @@ static void test_log_buffer_size(void)
int err;
int i;
struct reftable_log_record
log = { .refname = "refs/heads/master",
log = { .refname = (char *) "refs/heads/master",
.update_index = 0xa,
.value_type = REFTABLE_LOG_UPDATE,
.value = { .update = {
.name = "Han-Wen Nienhuys",
.email = "hanwen@google.com",
.name = (char *) "Han-Wen Nienhuys",
.email = (char *) "hanwen@google.com",
.tz_offset = 100,
.time = 0x5e430672,
.message = "commit: 9\n",
.message = (char *) "commit: 9\n",
} } };
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
@ -156,15 +156,15 @@ static void test_log_overflow(void)
};
int err;
struct reftable_log_record log = {
.refname = "refs/heads/master",
.refname = (char *) "refs/heads/master",
.update_index = 0xa,
.value_type = REFTABLE_LOG_UPDATE,
.value = {
.update = {
.old_hash = { 1 },
.new_hash = { 2 },
.name = "Han-Wen Nienhuys",
.email = "hanwen@google.com",
.name = (char *) "Han-Wen Nienhuys",
.email = (char *) "hanwen@google.com",
.tz_offset = 100,
.time = 0x5e430672,
.message = msg,
@ -297,14 +297,14 @@ static void test_log_zlib_corruption(void)
char message[100] = { 0 };
int err, i, n;
struct reftable_log_record log = {
.refname = "refname",
.refname = (char *) "refname",
.value_type = REFTABLE_LOG_UPDATE,
.value = {
.update = {
.new_hash = { 1 },
.old_hash = { 2 },
.name = "My Name",
.email = "myname@invalid",
.name = (char *) "My Name",
.email = (char *) "myname@invalid",
.message = message,
},
},
@ -739,7 +739,7 @@ static void test_write_empty_key(void)
struct reftable_writer *w =
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
struct reftable_ref_record ref = {
.refname = "",
.refname = (char *) "",
.update_index = 1,
.value_type = REFTABLE_REF_DELETION,
};
@ -763,18 +763,18 @@ static void test_write_key_order(void)
reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
struct reftable_ref_record refs[2] = {
{
.refname = "b",
.refname = (char *) "b",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value = {
.symref = "target",
.symref = (char *) "target",
},
}, {
.refname = "a",
.refname = (char *) "a",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value = {
.symref = "target",
.symref = (char *) "target",
},
}
};

View file

@ -116,7 +116,7 @@ static int decode_string(struct strbuf *dest, struct string_view in)
return start_len - in.len;
}
static int encode_string(char *str, struct string_view s)
static int encode_string(const char *str, struct string_view s)
{
struct string_view start = s;
int l = strlen(str);
@ -969,9 +969,9 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
return REFTABLE_FORMAT_ERROR;
}
static int null_streq(char *a, char *b)
static int null_streq(const char *a, const char *b)
{
char *empty = "";
const char *empty = "";
if (!a)
a = empty;

View file

@ -221,7 +221,8 @@ static struct reftable_reader **stack_copy_readers(struct reftable_stack *st,
return cur;
}
static int reftable_stack_reload_once(struct reftable_stack *st, char **names,
static int reftable_stack_reload_once(struct reftable_stack *st,
const char **names,
int reuse_open)
{
size_t cur_len = !st->merged ? 0 : st->merged->stack_len;
@ -239,7 +240,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names,
while (*names) {
struct reftable_reader *rd = NULL;
char *name = *names++;
const char *name = *names++;
/* this is linear; we assume compaction keeps the number of
tables under control so this is not quadratic. */
@ -371,7 +372,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
goto out;
}
err = reftable_stack_reload_once(st, names, reuse_open);
err = reftable_stack_reload_once(st, (const char **) names, reuse_open);
if (!err)
break;
if (err != REFTABLE_NOT_EXIST_ERROR)
@ -385,7 +386,8 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
err = read_lines(st->list_file, &names_after);
if (err < 0)
goto out;
if (names_equal(names_after, names)) {
if (names_equal((const char **) names_after,
(const char **) names)) {
err = REFTABLE_NOT_EXIST_ERROR;
goto out;
}

View file

@ -83,7 +83,7 @@ static void test_read_file(void)
char out[1024] = "line1\n\nline2\nline3";
int n, err;
char **names = NULL;
char *want[] = { "line1", "line2", "line3" };
const char *want[] = { "line1", "line2", "line3" };
int i = 0;
EXPECT(fd > 0);
@ -116,9 +116,9 @@ static void test_parse_names(void)
static void test_names_equal(void)
{
char *a[] = { "a", "b", "c", NULL };
char *b[] = { "a", "b", "d", NULL };
char *c[] = { "a", "b", NULL };
const char *a[] = { "a", "b", "c", NULL };
const char *b[] = { "a", "b", "d", NULL };
const char *c[] = { "a", "b", NULL };
EXPECT(names_equal(a, a));
EXPECT(!names_equal(a, b));
@ -156,10 +156,10 @@ static void test_reftable_stack_add_one(void)
struct reftable_stack *st = NULL;
int err;
struct reftable_ref_record ref = {
.refname = "HEAD",
.refname = (char *) "HEAD",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
struct reftable_ref_record dest = { NULL };
struct stat stat_result = { 0 };
@ -216,16 +216,16 @@ static void test_reftable_stack_uptodate(void)
int err;
struct reftable_ref_record ref1 = {
.refname = "HEAD",
.refname = (char *) "HEAD",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
struct reftable_ref_record ref2 = {
.refname = "branch2",
.refname = (char *) "branch2",
.update_index = 2,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
@ -263,10 +263,10 @@ static void test_reftable_stack_transaction_api(void)
struct reftable_addition *add = NULL;
struct reftable_ref_record ref = {
.refname = "HEAD",
.refname = (char *) "HEAD",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
struct reftable_ref_record dest = { NULL };
@ -311,7 +311,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
struct reftable_ref_record ref = {
.update_index = reftable_stack_next_update_index(st),
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
char name[100];
@ -354,7 +354,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
static void test_reftable_stack_auto_compaction_fails_gracefully(void)
{
struct reftable_ref_record ref = {
.refname = "refs/heads/master",
.refname = (char *) "refs/heads/master",
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = {0x01},
@ -406,16 +406,16 @@ static void test_reftable_stack_update_index_check(void)
struct reftable_stack *st = NULL;
int err;
struct reftable_ref_record ref1 = {
.refname = "name1",
.refname = (char *) "name1",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
struct reftable_ref_record ref2 = {
.refname = "name2",
.refname = (char *) "name2",
.update_index = 1,
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
err = reftable_new_stack(&st, dir, &opts);
@ -557,7 +557,7 @@ static void test_reftable_stack_log_normalize(void)
struct reftable_stack *st = NULL;
char *dir = get_tmp_dir(__LINE__);
struct reftable_log_record input = {
.refname = "branch",
.refname = (char *) "branch",
.update_index = 1,
.value_type = REFTABLE_LOG_UPDATE,
.value = {
@ -578,11 +578,11 @@ static void test_reftable_stack_log_normalize(void)
err = reftable_new_stack(&st, dir, &opts);
EXPECT_ERR(err);
input.value.update.message = "one\ntwo";
input.value.update.message = (char *) "one\ntwo";
err = reftable_stack_add(st, &write_test_log, &arg);
EXPECT(err == REFTABLE_API_ERROR);
input.value.update.message = "one";
input.value.update.message = (char *) "one";
err = reftable_stack_add(st, &write_test_log, &arg);
EXPECT_ERR(err);
@ -590,7 +590,7 @@ static void test_reftable_stack_log_normalize(void)
EXPECT_ERR(err);
EXPECT(0 == strcmp(dest.value.update.message, "one\n"));
input.value.update.message = "two\n";
input.value.update.message = (char *) "two\n";
arg.update_index = 2;
err = reftable_stack_add(st, &write_test_log, &arg);
EXPECT_ERR(err);
@ -690,9 +690,9 @@ static void test_reftable_stack_hash_id(void)
int err;
struct reftable_ref_record ref = {
.refname = "master",
.refname = (char *) "master",
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "target",
.value.symref = (char *) "target",
.update_index = 1,
};
struct reftable_write_options opts32 = { .hash_id = GIT_SHA256_FORMAT_ID };
@ -867,7 +867,7 @@ static void test_reftable_stack_auto_compaction(void)
.refname = name,
.update_index = reftable_stack_next_update_index(st),
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
snprintf(name, sizeof(name), "branch%04d", i);
@ -901,7 +901,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
struct reftable_ref_record ref = {
.update_index = reftable_stack_next_update_index(st),
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
/*
@ -951,7 +951,7 @@ static void test_reftable_stack_compaction_concurrent(void)
.refname = name,
.update_index = reftable_stack_next_update_index(st1),
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
snprintf(name, sizeof(name), "branch%04d", i);
@ -1000,7 +1000,7 @@ static void test_reftable_stack_compaction_concurrent_clean(void)
.refname = name,
.update_index = reftable_stack_next_update_index(st1),
.value_type = REFTABLE_REF_SYMREF,
.value.symref = "master",
.value.symref = (char *) "master",
};
snprintf(name, sizeof(name), "branch%04d", i);

View file

@ -58,9 +58,9 @@ struct options {
static struct options options;
static struct string_list cas_options = STRING_LIST_INIT_DUP;
static int set_option(const char *name, const char *value)
static int set_option(const char *name, size_t namelen, const char *value)
{
if (!strcmp(name, "verbosity")) {
if (!strncmp(name, "verbosity", namelen)) {
char *end;
int v = strtol(value, &end, 10);
if (value == end || *end)
@ -68,7 +68,7 @@ static int set_option(const char *name, const char *value)
options.verbosity = v;
return 0;
}
else if (!strcmp(name, "progress")) {
else if (!strncmp(name, "progress", namelen)) {
if (!strcmp(value, "true"))
options.progress = 1;
else if (!strcmp(value, "false"))
@ -77,7 +77,7 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
}
else if (!strcmp(name, "depth")) {
else if (!strncmp(name, "depth", namelen)) {
char *end;
unsigned long v = strtoul(value, &end, 10);
if (value == end || *end)
@ -85,15 +85,15 @@ static int set_option(const char *name, const char *value)
options.depth = v;
return 0;
}
else if (!strcmp(name, "deepen-since")) {
else if (!strncmp(name, "deepen-since", namelen)) {
options.deepen_since = xstrdup(value);
return 0;
}
else if (!strcmp(name, "deepen-not")) {
else if (!strncmp(name, "deepen-not", namelen)) {
string_list_append(&options.deepen_not, value);
return 0;
}
else if (!strcmp(name, "deepen-relative")) {
else if (!strncmp(name, "deepen-relative", namelen)) {
if (!strcmp(value, "true"))
options.deepen_relative = 1;
else if (!strcmp(value, "false"))
@ -102,7 +102,7 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
}
else if (!strcmp(name, "followtags")) {
else if (!strncmp(name, "followtags", namelen)) {
if (!strcmp(value, "true"))
options.followtags = 1;
else if (!strcmp(value, "false"))
@ -111,7 +111,7 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
}
else if (!strcmp(name, "dry-run")) {
else if (!strncmp(name, "dry-run", namelen)) {
if (!strcmp(value, "true"))
options.dry_run = 1;
else if (!strcmp(value, "false"))
@ -120,7 +120,7 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
}
else if (!strcmp(name, "check-connectivity")) {
else if (!strncmp(name, "check-connectivity", namelen)) {
if (!strcmp(value, "true"))
options.check_self_contained_and_connected = 1;
else if (!strcmp(value, "false"))
@ -129,7 +129,7 @@ static int set_option(const char *name, const char *value)
return -1;
return 0;
}
else if (!strcmp(name, "cas")) {
else if (!strncmp(name, "cas", namelen)) {
struct strbuf val = STRBUF_INIT;
strbuf_addstr(&val, "--force-with-lease=");
if (*value != '"')
@ -139,7 +139,7 @@ static int set_option(const char *name, const char *value)
string_list_append(&cas_options, val.buf);
strbuf_release(&val);
return 0;
} else if (!strcmp(name, TRANS_OPT_FORCE_IF_INCLUDES)) {
} else if (!strncmp(name, TRANS_OPT_FORCE_IF_INCLUDES, namelen)) {
if (!strcmp(value, "true"))
options.force_if_includes = 1;
else if (!strcmp(value, "false"))
@ -147,7 +147,7 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "cloning")) {
} else if (!strncmp(name, "cloning", namelen)) {
if (!strcmp(value, "true"))
options.cloning = 1;
else if (!strcmp(value, "false"))
@ -155,7 +155,7 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "update-shallow")) {
} else if (!strncmp(name, "update-shallow", namelen)) {
if (!strcmp(value, "true"))
options.update_shallow = 1;
else if (!strcmp(value, "false"))
@ -163,7 +163,7 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "pushcert")) {
} else if (!strncmp(name, "pushcert", namelen)) {
if (!strcmp(value, "true"))
options.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
else if (!strcmp(value, "false"))
@ -173,7 +173,7 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "atomic")) {
} else if (!strncmp(name, "atomic", namelen)) {
if (!strcmp(value, "true"))
options.atomic = 1;
else if (!strcmp(value, "false"))
@ -181,7 +181,7 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "push-option")) {
} else if (!strncmp(name, "push-option", namelen)) {
if (*value != '"')
string_list_append(&options.push_options, value);
else {
@ -192,7 +192,7 @@ static int set_option(const char *name, const char *value)
strbuf_detach(&unquoted, NULL));
}
return 0;
} else if (!strcmp(name, "family")) {
} else if (!strncmp(name, "family", namelen)) {
if (!strcmp(value, "ipv4"))
git_curl_ipresolve = CURL_IPRESOLVE_V4;
else if (!strcmp(value, "ipv6"))
@ -202,16 +202,16 @@ static int set_option(const char *name, const char *value)
else
return -1;
return 0;
} else if (!strcmp(name, "from-promisor")) {
} else if (!strncmp(name, "from-promisor", namelen)) {
options.from_promisor = 1;
return 0;
} else if (!strcmp(name, "refetch")) {
} else if (!strncmp(name, "refetch", namelen)) {
options.refetch = 1;
return 0;
} else if (!strcmp(name, "filter")) {
} else if (!strncmp(name, "filter", namelen)) {
options.filter = xstrdup(value);
return 0;
} else if (!strcmp(name, "object-format")) {
} else if (!strncmp(name, "object-format", namelen)) {
options.object_format = 1;
if (strcmp(value, "true"))
die(_("unknown value for object-format: %s"), value);
@ -1605,15 +1605,16 @@ int cmd_main(int argc, const char **argv)
parse_push(&buf);
} else if (skip_prefix(buf.buf, "option ", &arg)) {
char *value = strchr(arg, ' ');
const char *value = strchrnul(arg, ' ');
size_t arglen = value - arg;
int result;
if (value)
*value++ = '\0';
if (*value)
value++; /* skip over SP */
else
value = "true";
result = set_option(arg, value);
result = set_option(arg, arglen, value);
if (!result)
printf("ok\n");
else if (result < 0)

View file

@ -430,29 +430,29 @@ static int handle_config(const char *key, const char *value,
else if (!strcmp(subkey, "prunetags"))
remote->prune_tags = git_config_bool(key, value);
else if (!strcmp(subkey, "url")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
add_url(remote, v);
} else if (!strcmp(subkey, "pushurl")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
add_pushurl(remote, v);
} else if (!strcmp(subkey, "push")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
refspec_append(&remote->push, v);
free((char *)v);
free(v);
} else if (!strcmp(subkey, "fetch")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
refspec_append(&remote->fetch, v);
free((char *)v);
free(v);
} else if (!strcmp(subkey, "receivepack")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
if (!remote->receivepack)
@ -460,7 +460,7 @@ static int handle_config(const char *key, const char *value,
else
error(_("more than one receivepack given, using the first"));
} else if (!strcmp(subkey, "uploadpack")) {
const char *v;
char *v;
if (git_config_string(&v, key, value))
return -1;
if (!remote->uploadpack)
@ -473,10 +473,10 @@ static int handle_config(const char *key, const char *value,
else if (!strcmp(value, "--tags"))
remote->fetch_tags = 2;
} else if (!strcmp(subkey, "proxy")) {
return git_config_string((const char **)&remote->http_proxy,
return git_config_string(&remote->http_proxy,
key, value);
} else if (!strcmp(subkey, "proxyauthmethod")) {
return git_config_string((const char **)&remote->http_proxy_authmethod,
return git_config_string(&remote->http_proxy_authmethod,
key, value);
} else if (!strcmp(subkey, "vcs")) {
return git_config_string(&remote->foreign_vcs, key, value);

View file

@ -46,7 +46,7 @@ struct remote_state {
struct hashmap branches_hash;
struct branch *current_branch;
const char *pushremote_name;
char *pushremote_name;
struct rewrites rewrites;
struct rewrites rewrites_push;
@ -65,7 +65,7 @@ struct remote {
int origin, configured_in_repo;
const char *foreign_vcs;
char *foreign_vcs;
/* An array of all of the url_nr URLs configured for the remote */
const char **url;
@ -309,9 +309,9 @@ struct branch {
const char *refname;
/* The name of the remote listed in the configuration. */
const char *remote_name;
char *remote_name;
const char *pushremote_name;
char *pushremote_name;
/* An array of the "merge" lines in the configuration. */
const char **merge_name;

View file

@ -2650,10 +2650,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
} else if (!strcmp(arg, "--invert-grep")) {
revs->grep_filter.no_body_match = 1;
} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
free(git_log_output_encoding);
if (strcmp(optarg, "none"))
git_log_output_encoding = xstrdup(optarg);
else
git_log_output_encoding = "";
git_log_output_encoding = xstrdup("");
return argcount;
} else if (!strcmp(arg, "--reverse")) {
revs->reverse ^= 1;

View file

@ -663,7 +663,7 @@ int start_command(struct child_process *cmd)
int need_in, need_out, need_err;
int fdin[2], fdout[2], fderr[2];
int failed_errno;
char *str;
const char *str;
/*
* In case of errors we must keep the promise to close FDs

View file

@ -259,7 +259,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
if (p)
hint->remote_status = xstrdup(p);
else
hint->remote_status = "failed";
hint->remote_status = xstrdup("failed");
} else {
hint->status = REF_STATUS_OK;
hint->remote_status = xstrdup_or_null(p);

View file

@ -306,7 +306,7 @@ static int git_sequencer_config(const char *k, const char *v,
}
if (!opts->default_strategy && !strcmp(k, "pull.twohead")) {
int ret = git_config_string((const char**)&opts->default_strategy, k, v);
int ret = git_config_string(&opts->default_strategy, k, v);
if (ret == 0) {
/*
* pull.twohead is allowed to be multi-valued; we only

View file

@ -1230,13 +1230,13 @@ static int safe_directory_cb(const char *key, const char *value,
} else if (!strcmp(value, "*")) {
data->is_safe = 1;
} else {
const char *interpolated = NULL;
char *interpolated = NULL;
if (!git_config_pathname(&interpolated, key, value) &&
!fspathcmp(data->path, interpolated ? interpolated : value))
data->is_safe = 1;
free((char *)interpolated);
free(interpolated);
}
return 0;
@ -1875,7 +1875,7 @@ static int template_dir_cb(const char *key, const char *value,
char *path = NULL;
FREE_AND_NULL(data->path);
if (!git_config_pathname((const char **)&path, key, value))
if (!git_config_pathname(&path, key, value))
data->path = path ? path : xstrdup(value);
}

View file

@ -691,8 +691,10 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
int strbuf_appendwholeline(struct strbuf *sb, FILE *fp, int term)
{
struct strbuf line = STRBUF_INIT;
if (strbuf_getwholeline(&line, fp, term))
if (strbuf_getwholeline(&line, fp, term)) {
strbuf_release(&line);
return EOF;
}
strbuf_addbuf(sb, &line);
strbuf_release(&line);
return 0;

View file

@ -56,6 +56,26 @@ void strvec_pushv(struct strvec *array, const char **items)
strvec_push(array, *items);
}
const char *strvec_replace(struct strvec *array, size_t idx, const char *replacement)
{
char *to_free;
if (idx >= array->nr)
BUG("index outside of array boundary");
to_free = (char *) array->v[idx];
array->v[idx] = xstrdup(replacement);
free(to_free);
return array->v[idx];
}
void strvec_remove(struct strvec *array, size_t idx)
{
if (idx >= array->nr)
BUG("index outside of array boundary");
free((char *)array->v[idx]);
memmove(array->v + idx, array->v + idx + 1, (array->nr - idx) * sizeof(char *));
array->nr--;
}
void strvec_pop(struct strvec *array)
{
if (!array->nr)

View file

@ -64,6 +64,19 @@ void strvec_pushl(struct strvec *, ...);
/* Push a null-terminated array of strings onto the end of the array. */
void strvec_pushv(struct strvec *, const char **);
/**
* Replace the value at the given index with a new value. The index must be
* valid. Returns a pointer to the inserted value.
*/
const char *strvec_replace(struct strvec *array, size_t idx, const char *replacement);
/*
* Remove the value at the given index. The remainder of the array will be
* moved to fill the resulting gap. The provided index must point into the
* array.
*/
void strvec_remove(struct strvec *array, size_t idx);
/**
* Remove the final element from the array. If there are no
* elements in the array, do nothing.

View file

@ -91,6 +91,8 @@ static void free_one_config(struct submodule_entry *entry)
free((void *) entry->config->path);
free((void *) entry->config->name);
free((void *) entry->config->branch);
free((void *) entry->config->url);
free((void *) entry->config->ignore);
free((void *) entry->config->update_strategy.command);
free(entry->config);
}

View file

@ -36,7 +36,8 @@ static int test_entry_cmp(const void *cmp_data,
}
static struct test_entry *alloc_test_entry(unsigned int hash,
char *key, char *value)
const char *key,
const char *value)
{
size_t klen = strlen(key);
size_t vlen = strlen(value);

View file

@ -174,7 +174,7 @@ static void make_arr4(int pretty)
jw_end(&arr4);
}
static char *expect_nest1 =
static const char *expect_nest1 =
"{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
static struct json_writer nest1 = JSON_WRITER_INIT;
@ -195,10 +195,10 @@ static void make_nest1(int pretty)
jw_release(&arr1);
}
static char *expect_inline1 =
static const char *expect_inline1 =
"{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
static char *pretty_inline1 =
static const char *pretty_inline1 =
("{\n"
" \"obj1\": {\n"
" \"a\": \"abc\",\n"
@ -236,10 +236,10 @@ static void make_inline1(int pretty)
jw_end(&inline1);
}
static char *expect_inline2 =
static const char *expect_inline2 =
"[[1,2],[3,4],{\"a\":\"abc\"}]";
static char *pretty_inline2 =
static const char *pretty_inline2 =
("[\n"
" [\n"
" 1,\n"

View file

@ -20,8 +20,8 @@ static struct reg_flag reg_flags[] = {
static int test_regex_bug(void)
{
char *pat = "[^={} \t]+";
char *str = "={}\nfred";
const char *pat = "[^={} \t]+";
const char *str = "={}\nfred";
regex_t r;
regmatch_t m[1];

View file

@ -136,7 +136,7 @@ static void free_delay_entries(void)
strmap_clear(&delay, 0);
}
static void add_delay_entry(char *pathname, int count, int requested)
static void add_delay_entry(const char *pathname, int count, int requested)
{
struct delay_entry *entry = xcalloc(1, sizeof(*entry));
entry->count = count;
@ -189,7 +189,8 @@ static void reply_list_available_blobs_cmd(void)
static void command_loop(void)
{
for (;;) {
char *buf, *output;
char *buf;
const char *output;
char *pathname;
struct delay_entry *entry;
struct strbuf input = STRBUF_INIT;

View file

@ -1,6 +1,8 @@
#!/bin/sh
test_description='basic credential helper tests'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-credential.sh

View file

@ -2,6 +2,7 @@
test_description='reftable HTTPD tests'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh

View file

@ -2,6 +2,7 @@
test_description='read-tree can handle submodules'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

View file

@ -7,6 +7,7 @@
test_description='Compatibility with $XDG_CONFIG_HOME/git/ files'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'read config: xdg file exists and ~/.gitconfig doesn'\''t' '

View file

@ -2,6 +2,7 @@
test_description='Test the core.hooksPath configuration variable'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'set up a pre-commit hook in core.hooksPath' '

View file

@ -4,6 +4,8 @@
#
test_description='Test git update-ref and basic ref logging'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
Z=$ZERO_OID

Some files were not shown because too many files have changed in this diff Show more