From: Junio C Hamano Date: Tue, 24 Jul 2018 21:50:47 +0000 (-0700) Subject: Merge branch 'bb/pedantic' X-Git-Tag: v2.19.0-rc0~131 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/00da9b2091ef8d1955fa2f021b8ba111ce6a5fed?hp=-c Merge branch 'bb/pedantic' The codebase has been updated to compile cleanly with -pedantic option. * bb/pedantic: utf8.c: avoid char overflow string-list.c: avoid conversion from void * to function pointer sequencer.c: avoid empty statements at top level convert.c: replace "\e" escapes with "\033". fixup! refs/refs-internal.h: avoid forward declaration of an enum refs/refs-internal.h: avoid forward declaration of an enum fixup! connect.h: avoid forward declaration of an enum connect.h: avoid forward declaration of an enum --- 00da9b2091ef8d1955fa2f021b8ba111ce6a5fed diff --combined convert.c index 56cfe31ec5,edebb946f5..7907efd16f --- a/convert.c +++ b/convert.c @@@ -1,7 -1,6 +1,7 @@@ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" +#include "object-store.h" #include "attr.h" #include "run-command.h" #include "quote.h" @@@ -335,7 -334,7 +335,7 @@@ static void trace_encoding(const char * strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding); for (i = 0; i < len && buf; ++i) { strbuf_addf( - &trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c", + &trace, "| \033[2m%2i:\033[0m %2x \033[2m%c\033[0m%c", i, (unsigned char) buf[i], (buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '), diff --combined path.h index 5263f40519,fc9d3487a0..ed6732e5a2 --- a/path.h +++ b/path.h @@@ -147,7 -147,7 +147,7 @@@ extern void report_linked_checkout_garb /* * You can define a static memoized git path like: * - * static GIT_PATH_FUNC(git_path_foo, "FOO"); + * static GIT_PATH_FUNC(git_path_foo, "FOO") * * or use one of the global ones below. */ @@@ -160,36 -160,14 +160,36 @@@ return ret; \ } -const char *git_path_cherry_pick_head(void); -const char *git_path_revert_head(void); -const char *git_path_squash_msg(void); -const char *git_path_merge_msg(void); -const char *git_path_merge_rr(void); -const char *git_path_merge_mode(void); -const char *git_path_merge_head(void); -const char *git_path_fetch_head(void); -const char *git_path_shallow(void); +#define REPO_GIT_PATH_FUNC(var, filename) \ + const char *git_path_##var(struct repository *r) \ + { \ + if (!r->cached_paths.var) \ + r->cached_paths.var = git_pathdup(filename); \ + return r->cached_paths.var; \ + } + +struct path_cache { + const char *cherry_pick_head; + const char *revert_head; + const char *squash_msg; + const char *merge_msg; + const char *merge_rr; + const char *merge_mode; + const char *merge_head; + const char *fetch_head; + const char *shallow; +}; + +#define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } + +const char *git_path_cherry_pick_head(struct repository *r); +const char *git_path_revert_head(struct repository *r); +const char *git_path_squash_msg(struct repository *r); +const char *git_path_merge_msg(struct repository *r); +const char *git_path_merge_rr(struct repository *r); +const char *git_path_merge_mode(struct repository *r); +const char *git_path_merge_head(struct repository *r); +const char *git_path_fetch_head(struct repository *r); +const char *git_path_shallow(struct repository *r); #endif /* PATH_H */ diff --combined sequencer.c index 03c47405fb,0e9b1d99c9..349ae04ffd --- a/sequencer.c +++ b/sequencer.c @@@ -2,7 -2,6 +2,7 @@@ #include "config.h" #include "lockfile.h" #include "dir.h" +#include "object-store.h" #include "object.h" #include "commit.h" #include "sequencer.h" @@@ -28,7 -27,6 +28,7 @@@ #include "worktree.h" #include "oidmap.h" #include "oidset.h" +#include "commit-slab.h" #include "alias.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@@ -63,12 -61,12 +63,12 @@@ static GIT_PATH_FUNC(rebase_path_done, * The file to keep track of how many commands were already processed (e.g. * for the prompt). */ - static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum"); + static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum") /* * The file to keep track of how many commands are to be processed in total * (e.g. for the prompt). */ - static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end"); + static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end") /* * The commit message that is planned to be used for any changes that * need to be committed following a user interaction. @@@ -177,7 -175,6 +177,7 @@@ static int git_sequencer_config(const c warning(_("invalid commit message cleanup mode '%s'"), s); + free((char *)s); return status; } @@@ -358,7 -355,7 +358,7 @@@ static void print_advice(int show_hint * (typically rebase --interactive) wants to take care * of the commit itself so remove CHERRY_PICK_HEAD */ - unlink(git_path_cherry_pick_head()); + unlink(git_path_cherry_pick_head(the_repository)); return; } @@@ -1325,8 -1322,8 +1325,8 @@@ static int do_commit(const char *msg_fi &oid); strbuf_release(&sb); if (!res) { - unlink(git_path_cherry_pick_head()); - unlink(git_path_merge_msg()); + unlink(git_path_cherry_pick_head(the_repository)); + unlink(git_path_merge_msg(the_repository)); if (!is_rebase_i(opts)) print_commit_summary(NULL, &oid, SUMMARY_SHOW_AUTHOR_DATE); @@@ -1614,7 -1611,7 +1614,7 @@@ static int do_pick_commit(enum todo_com struct replay_opts *opts, int final_fixup) { unsigned int flags = opts->edit ? EDIT_MSG : 0; - const char *msg_file = opts->edit ? NULL : git_path_merge_msg(); + const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository); struct object_id head; struct commit *base, *next, *parent; const char *base_label, *next_label; @@@ -1756,12 -1753,12 +1756,12 @@@ flags |= CLEANUP_MSG; msg_file = rebase_path_fixup_msg(); } else { - const char *dest = git_path_squash_msg(); + const char *dest = git_path_squash_msg(the_repository); unlink(dest); if (copy_file(dest, rebase_path_squash_msg(), 0666)) return error(_("could not rename '%s' to '%s'"), rebase_path_squash_msg(), dest); - unlink(git_path_merge_msg()); + unlink(git_path_merge_msg(the_repository)); msg_file = dest; flags |= EDIT_MSG; } @@@ -1776,16 -1773,15 +1776,16 @@@ res = do_recursive_merge(base, next, base_label, next_label, &head, &msgbuf, opts); if (res < 0) - return res; + goto leave; + res |= write_message(msgbuf.buf, msgbuf.len, - git_path_merge_msg(), 0); + git_path_merge_msg(the_repository), 0); } else { struct commit_list *common = NULL; struct commit_list *remotes = NULL; res = write_message(msgbuf.buf, msgbuf.len, - git_path_merge_msg(), 0); + git_path_merge_msg(the_repository), 0); commit_list_insert(base, &common); commit_list_insert(next, &remotes); @@@ -2207,7 -2203,6 +2207,7 @@@ static int populate_opts_cb(const char static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf) { int i; + char *strategy_opts_string; strbuf_reset(buf); if (!read_oneliner(buf, rebase_path_strategy(), 0)) @@@ -2216,11 -2211,7 +2216,11 @@@ if (!read_oneliner(buf, rebase_path_strategy_opts(), 0)) return; - opts->xopts_nr = split_cmdline(buf->buf, (const char ***)&opts->xopts); + strategy_opts_string = buf->buf; + if (*strategy_opts_string == ' ') + strategy_opts_string++; + opts->xopts_nr = split_cmdline(strategy_opts_string, + (const char ***)&opts->xopts); for (i = 0; i < opts->xopts_nr; i++) { const char *arg = opts->xopts[i]; @@@ -2400,8 -2391,8 +2400,8 @@@ static int rollback_single_pick(void { struct object_id head_oid; - if (!file_exists(git_path_cherry_pick_head()) && - !file_exists(git_path_revert_head())) + if (!file_exists(git_path_cherry_pick_head(the_repository)) && + !file_exists(git_path_revert_head(the_repository))) return error(_("no cherry-pick or revert in progress")); if (read_ref_full("HEAD", 0, &head_oid, NULL)) return error(_("cannot resolve HEAD")); @@@ -2626,11 -2617,10 +2626,11 @@@ static int error_failed_squash(struct c if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666)) return error(_("could not copy '%s' to '%s'"), rebase_path_squash_msg(), rebase_path_message()); - unlink(git_path_merge_msg()); - if (copy_file(git_path_merge_msg(), rebase_path_message(), 0666)) + unlink(git_path_merge_msg(the_repository)); + if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666)) return error(_("could not copy '%s' to '%s'"), - rebase_path_message(), git_path_merge_msg()); + rebase_path_message(), + git_path_merge_msg(the_repository)); return error_with_patch(commit, subject, subject_len, opts, 1, 0); } @@@ -2920,11 -2910,11 +2920,11 @@@ static int do_merge(struct commit *comm write_author_script(message); find_commit_subject(message, &body); len = strlen(body); - ret = write_message(body, len, git_path_merge_msg(), 0); + ret = write_message(body, len, git_path_merge_msg(the_repository), 0); unuse_commit_buffer(commit, message); if (ret) { error_errno(_("could not write '%s'"), - git_path_merge_msg()); + git_path_merge_msg(the_repository)); goto leave_merge; } } else { @@@ -2945,11 -2935,11 +2945,11 @@@ len = buf.len; } - ret = write_message(p, len, git_path_merge_msg(), 0); + ret = write_message(p, len, git_path_merge_msg(the_repository), 0); strbuf_release(&buf); if (ret) { error_errno(_("could not write '%s'"), - git_path_merge_msg()); + git_path_merge_msg(the_repository)); goto leave_merge; } } @@@ -2986,8 -2976,8 +2986,8 @@@ } write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ, - git_path_merge_head(), 0); - write_message("no-ff", 5, git_path_merge_mode(), 0); + git_path_merge_head(the_repository), 0); + write_message("no-ff", 5, git_path_merge_mode(the_repository), 0); bases = get_merge_bases(head_commit, merge_commit); if (bases && !oidcmp(&merge_commit->object.oid, @@@ -3041,7 -3031,7 +3041,7 @@@ * value (a negative one would indicate that the `merge` * command needs to be rescheduled). */ - ret = !!run_git_commit(git_path_merge_msg(), opts, + ret = !!run_git_commit(git_path_merge_msg(the_repository), opts, run_commit_flags); leave_merge: @@@ -3224,27 -3214,10 +3224,27 @@@ static int pick_commits(struct todo_lis intend_to_amend(); return error_failed_squash(item->commit, opts, item->arg_len, item->arg); - } else if (res && is_rebase_i(opts) && item->commit) + } else if (res && is_rebase_i(opts) && item->commit) { + int to_amend = 0; + struct object_id oid; + + /* + * If we are rewording and have either + * fast-forwarded already, or are about to + * create a new root commit, we want to amend, + * otherwise we do not. + */ + if (item->command == TODO_REWORD && + !get_oid("HEAD", &oid) && + (!oidcmp(&item->commit->object.oid, &oid) || + (opts->have_squash_onto && + !oidcmp(&opts->squash_onto, &oid)))) + to_amend = 1; + return res | error_with_patch(item->commit, - item->arg, item->arg_len, opts, res, - item->command == TODO_REWORD); + item->arg, item->arg_len, opts, + res, to_amend); + } } else if (item->command == TODO_EXEC) { char *end_of_arg = (char *)(item->arg + item->arg_len); int saved = *end_of_arg; @@@ -3425,8 -3398,8 +3425,8 @@@ static int continue_single_pick(void { const char *argv[] = { "commit", NULL }; - if (!file_exists(git_path_cherry_pick_head()) && - !file_exists(git_path_revert_head())) + if (!file_exists(git_path_cherry_pick_head(the_repository)) && + !file_exists(git_path_revert_head(the_repository))) return error(_("no cherry-pick or revert in progress")); return run_command_v_opt(argv, RUN_GIT_CMD); } @@@ -3529,7 -3502,7 +3529,7 @@@ static int commit_staged_changes(struc } if (is_clean) { - const char *cherry_pick_head = git_path_cherry_pick_head(); + const char *cherry_pick_head = git_path_cherry_pick_head(the_repository); if (file_exists(cherry_pick_head) && unlink(cherry_pick_head)) return error(_("could not remove CHERRY_PICK_HEAD")); @@@ -3579,8 -3552,8 +3579,8 @@@ int sequencer_continue(struct replay_op if (!is_rebase_i(opts)) { /* Verify that the conflict has been resolved */ - if (file_exists(git_path_cherry_pick_head()) || - file_exists(git_path_revert_head())) { + if (file_exists(git_path_cherry_pick_head(the_repository)) || + file_exists(git_path_revert_head(the_repository))) { res = continue_single_pick(); if (res) goto release_todo_list; @@@ -4265,7 -4238,6 +4265,7 @@@ static enum check_level get_missing_com return CHECK_IGNORE; } +define_commit_slab(commit_seen, unsigned char); /* * Check if the user dropped some commits by mistake * Behaviour determined by rebase.missingCommitsCheck. @@@ -4279,9 -4251,6 +4279,9 @@@ int check_todo_list(void struct todo_list todo_list = TODO_LIST_INIT; struct strbuf missing = STRBUF_INIT; int advise_to_edit_todo = 0, res = 0, i; + struct commit_seen commit_seen; + + init_commit_seen(&commit_seen); strbuf_addstr(&todo_file, rebase_path_todo()); if (strbuf_read_file_or_whine(&todo_list.buf, todo_file.buf) < 0) { @@@ -4298,7 -4267,7 +4298,7 @@@ for (i = 0; i < todo_list.nr; i++) { struct commit *commit = todo_list.items[i].commit; if (commit) - commit->util = (void *)1; + *commit_seen_at(&commit_seen, commit) = 1; } todo_list_release(&todo_list); @@@ -4314,11 -4283,11 +4314,11 @@@ for (i = todo_list.nr - 1; i >= 0; i--) { struct todo_item *item = todo_list.items + i; struct commit *commit = item->commit; - if (commit && !commit->util) { + if (commit && !*commit_seen_at(&commit_seen, commit)) { strbuf_addf(&missing, " - %s %.*s\n", short_commit_name(commit), item->arg_len, item->arg); - commit->util = (void *)1; + *commit_seen_at(&commit_seen, commit) = 1; } } @@@ -4344,7 -4313,6 +4344,7 @@@ "The possible behaviours are: ignore, warn, error.\n\n")); leave_check: + clear_commit_seen(&commit_seen); strbuf_release(&todo_file); todo_list_release(&todo_list); @@@ -4465,8 -4433,6 +4465,8 @@@ static int subject2item_cmp(const void return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject); } +define_commit_slab(commit_todo_item, struct todo_item *); + /* * Rearrange the todo list that has both "pick commit-id msg" and "pick * commit-id fixup!/squash! msg" in it so that the latter is put immediately @@@ -4483,7 -4449,6 +4483,7 @@@ int rearrange_squash(void struct hashmap subject2item; int res = 0, rearranged = 0, *next, *tail, i; char **subjects; + struct commit_todo_item commit_todo; if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; @@@ -4492,7 -4457,6 +4492,7 @@@ return -1; } + init_commit_todo_item(&commit_todo); /* * The hashmap maps onelines to the respective todo list index. * @@@ -4523,11 -4487,10 +4523,11 @@@ if (is_fixup(item->command)) { todo_list_release(&todo_list); + clear_commit_todo_item(&commit_todo); return error(_("the script was already rearranged.")); } - item->commit->util = item; + *commit_todo_item_at(&commit_todo, item->commit) = item; parse_commit(item->commit); commit_buffer = get_commit_buffer(item->commit, NULL); @@@ -4554,9 -4517,9 +4554,9 @@@ else if (!strchr(p, ' ') && (commit2 = lookup_commit_reference_by_name(p)) && - commit2->util) + *commit_todo_item_at(&commit_todo, commit2)) /* found by commit name */ - i2 = (struct todo_item *)commit2->util + i2 = *commit_todo_item_at(&commit_todo, commit2) - todo_list.items; else { /* copy can be a prefix of the commit subject */ @@@ -4633,6 -4596,5 +4633,6 @@@ hashmap_free(&subject2item, 1); todo_list_release(&todo_list); + clear_commit_todo_item(&commit_todo); return res; }