diff --git a/Documentation/RelNotes/2.56.0.adoc b/Documentation/RelNotes/2.56.0.adoc index fda10a014f85ba..2d01f5cdc0ab74 100644 --- a/Documentation/RelNotes/2.56.0.adoc +++ b/Documentation/RelNotes/2.56.0.adoc @@ -27,6 +27,10 @@ UI, Workflows & Features absolute and relative paths for "gitdir" and "commondir", supported by a new path-formatting helper extracted from "git rev-parse". + * When 'git push origin/main' or 'git branch origin main' is run, the + command is now recognized as a potential typo, and advice has been + added to offer a typo fix. + Performance, Internal Implementation, Development Support etc. -------------------------------------------------------------- @@ -74,6 +78,16 @@ Performance, Internal Implementation, Development Support etc. a default limit of at most one reroll per day to give reviewers across different time zones enough time to participate. + * The lazy priority queue optimization pattern (deferring actual removal + in 'prio_queue_get()' to allow get+put fusion) has been folded + directly into 'prio_queue' itself, speeding up commit traversal + workflows and simplifying callers. + + * The 'reprepare()' callback for object database sources has been + generalized into a 'prepare()' callback with an optional flush cache + flag, and a new 'odb_prepare()' wrapper has been introduced to allow + pre-opening object database sources. + Fixes since v2.55 ----------------- @@ -111,3 +125,18 @@ Fixes since v2.55 test_path_is_missing instead of ! grep on a file that shouldn't exist in the conflicted state. (merge eaad121fef sg/t3420-do-not-grep-in-missing-file later to maint). + + * The GPG and SSH signature parsing code has been corrected to strip + carriage return characters only when they immediately precede line + feeds, instead of unconditionally stripping all carriage returns. + (merge 5dea8b690b ad/gpg-strip-cr-before-lf later to maint). + + * A memory leak in the 'reftable_writer_new()' initialization function + has been fixed by delaying the allocation of 'struct reftable_writer' + until after input options are validated. + (merge c6fb3b9c3e jk/reftable-leakfix later to maint). + + * A memory leak in the '--base' handling of 'git format-patch' has been + plugged, and the leak reporting of the test suite when running under a + TAP harness has been improved. + (merge 973a0373ff jk/format-patch-leakfix later to maint). diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc index c3c190ba6a4fb8..81f80a92745123 100644 --- a/Documentation/config/advice.adoc +++ b/Documentation/config/advice.adoc @@ -94,6 +94,11 @@ all advice messages. Shown when linkgit:git-push[1] rejects a forced update of a branch when its remote-tracking ref has updates that we do not have locally. + pushRepoLooksLikeRef:: + Shown when the repository given to linkgit:git-push[1] is not + a configured remote but looks like a `/` ref, + suggesting that the remote and branch be given as separate + arguments. pushUnqualifiedRefname:: Shown when linkgit:git-push[1] gives up trying to guess based on the source and destination refs what diff --git a/advice.c b/advice.c index 0018501b7bc103..63bf8b0c5f0481 100644 --- a/advice.c +++ b/advice.c @@ -69,6 +69,7 @@ static struct { [ADVICE_PUSH_NON_FF_CURRENT] = { "pushNonFFCurrent" }, [ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching" }, [ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate" }, + [ADVICE_PUSH_REPO_LOOKS_LIKE_REF] = { "pushRepoLooksLikeRef" }, [ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName" }, [ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected" }, [ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward" }, /* backwards compatibility */ diff --git a/advice.h b/advice.h index 8def28068861df..66f6cd6a772d8c 100644 --- a/advice.h +++ b/advice.h @@ -36,6 +36,7 @@ enum advice_type { ADVICE_PUSH_NON_FF_CURRENT, ADVICE_PUSH_NON_FF_MATCHING, ADVICE_PUSH_REF_NEEDS_UPDATE, + ADVICE_PUSH_REPO_LOOKS_LIKE_REF, ADVICE_PUSH_UNQUALIFIED_REF_NAME, ADVICE_PUSH_UPDATE_REJECTED, ADVICE_PUSH_UPDATE_REJECTED_ALIAS, diff --git a/builtin/branch.c b/builtin/branch.c index 1572a4f9ef2ab6..dede60d27b69ea 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -706,6 +706,29 @@ static int edit_branch_description(const char *branch_name) return 0; } +static void die_if_upstream_looks_like_remote(const char *new_upstream, const char *branch_name) +{ + struct strbuf remote_ref = STRBUF_INIT; + int code; + + if (strchr(new_upstream, '/') || + !remote_is_configured(remote_get(new_upstream), 0)) + return; + + strbuf_addf(&remote_ref, "refs/remotes/%s/%s", new_upstream, branch_name); + if (!refs_ref_exists(get_main_ref_store(the_repository), remote_ref.buf)) { + strbuf_release(&remote_ref); + return; + } + + code = die_message(_("--set-upstream-to takes a single / argument")); + advise_if_enabled(ADVICE_SET_UPSTREAM_FAILURE, + _("Did you mean to use: git branch --set-upstream-to=%s/%s?"), + new_upstream, branch_name); + strbuf_release(&remote_ref); + exit(code); +} + int cmd_branch(int argc, const char **argv, const char *prefix, @@ -957,6 +980,15 @@ int cmd_branch(int argc, if (!refs_ref_exists(get_main_ref_store(the_repository), branch->refname)) { if (!argc || branch_checked_out(branch->refname)) die(_("no commit on branch '%s' yet"), branch->name); + /* + * Check the advice up front to avoid the ref + * lookups when the hint is off. The helper still + * calls advise_if_enabled() so the hint carries the + * standard "disable this message" instructions. + */ + if (argc == 1 && + advice_enabled(ADVICE_SET_UPSTREAM_FAILURE)) + die_if_upstream_looks_like_remote(new_upstream, argv[0]); die(_("branch '%s' does not exist"), branch->name); } diff --git a/builtin/describe.c b/builtin/describe.c index a94dad998cddd7..c0abc931a5948d 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -251,56 +251,19 @@ static int compare_pt(const void *a_, const void *b_) return 0; } -struct lazy_queue { - struct prio_queue queue; - bool get_pending; -}; - -#define LAZY_QUEUE_INIT { { compare_commits_by_commit_date }, false } - -static void *lazy_queue_get(struct lazy_queue *queue) -{ - if (queue->get_pending) - prio_queue_get(&queue->queue); - else - queue->get_pending = true; - return prio_queue_peek(&queue->queue); -} - -static void lazy_queue_put(struct lazy_queue *queue, void *thing) -{ - if (queue->get_pending) - prio_queue_replace(&queue->queue, thing); - else - prio_queue_put(&queue->queue, thing); - queue->get_pending = false; -} - -static bool lazy_queue_empty(const struct lazy_queue *queue) -{ - return queue->queue.nr == (queue->get_pending ? 1 : 0); -} - -static void lazy_queue_clear(struct lazy_queue *queue) -{ - clear_prio_queue(&queue->queue); - queue->get_pending = false; -} - -static unsigned long finish_depth_computation(struct lazy_queue *queue, +static unsigned long finish_depth_computation(struct prio_queue *queue, struct possible_tag *best) { unsigned long seen_commits = 0; struct oidset unflagged = OIDSET_INIT; + struct commit *c; - for (size_t i = queue->get_pending ? 1 : 0; i < queue->queue.nr; i++) { - struct commit *commit = queue->queue.array[i].data; - if (!(commit->object.flags & best->flag_within)) - oidset_insert(&unflagged, &commit->object.oid); + prio_queue_for_each(queue, c) { + if (!(c->object.flags & best->flag_within)) + oidset_insert(&unflagged, &c->object.oid); } - while (!lazy_queue_empty(queue)) { - struct commit *c = lazy_queue_get(queue); + while ((c = prio_queue_get(queue))) { struct commit_list *parents = c->parents; seen_commits++; if (c->object.flags & best->flag_within) { @@ -316,7 +279,7 @@ static unsigned long finish_depth_computation(struct lazy_queue *queue, repo_parse_commit(the_repository, p); seen = p->object.flags & SEEN; if (!seen) - lazy_queue_put(queue, p); + prio_queue_put(queue, p); flag_before = p->object.flags & best->flag_within; p->object.flags |= c->object.flags; flag_after = p->object.flags & best->flag_within; @@ -364,8 +327,8 @@ static void append_suffix(int depth, const struct object_id *oid, struct strbuf static void describe_commit(struct commit *cmit, struct strbuf *dst) { - struct commit *gave_up_on = NULL; - struct lazy_queue queue = LAZY_QUEUE_INIT; + struct commit *c, *gave_up_on = NULL; + struct prio_queue queue = { compare_commits_by_commit_date }; struct commit_name *n; struct possible_tag all_matches[MAX_TAGS]; unsigned int match_cnt = 0, annotated_cnt = 0, cur_match; @@ -407,9 +370,8 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst) } cmit->object.flags = SEEN; - lazy_queue_put(&queue, cmit); - while (!lazy_queue_empty(&queue)) { - struct commit *c = lazy_queue_get(&queue); + prio_queue_put(&queue, cmit); + while ((c = prio_queue_get(&queue))) { struct commit_list *parents = c->parents; struct commit_name **slot; @@ -443,7 +405,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst) t->depth++; } /* Stop if last remaining path already covered by best candidate(s) */ - if (annotated_cnt && lazy_queue_empty(&queue)) { + if (annotated_cnt && !prio_queue_size(&queue)) { int best_depth = INT_MAX; unsigned best_within = 0; for (cur_match = 0; cur_match < match_cnt; cur_match++) { @@ -466,7 +428,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst) struct commit *p = parents->item; repo_parse_commit(the_repository, p); if (!(p->object.flags & SEEN)) - lazy_queue_put(&queue, p); + prio_queue_put(&queue, p); p->object.flags |= c->object.flags; parents = parents->next; @@ -481,7 +443,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst) strbuf_add_unique_abbrev(dst, cmit_oid, abbrev); if (suffix) strbuf_addstr(dst, suffix); - lazy_queue_clear(&queue); + clear_prio_queue(&queue); return; } if (unannotated_cnt) @@ -497,11 +459,11 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst) QSORT(all_matches, match_cnt, compare_pt); if (gave_up_on) { - lazy_queue_put(&queue, gave_up_on); + prio_queue_put(&queue, gave_up_on); seen_commits--; } seen_commits += finish_depth_computation(&queue, &all_matches[0]); - lazy_queue_clear(&queue); + clear_prio_queue(&queue); if (debug) { static int label_width = -1; diff --git a/builtin/grep.c b/builtin/grep.c index 77f0c4dc90c4f5..d3d86abe01e032 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -25,12 +25,11 @@ #include "setup.h" #include "submodule.h" #include "submodule-config.h" -#include "object-file.h" #include "object-name.h" #include "odb.h" +#include "odb/source.h" #include "oid-array.h" #include "oidset.h" -#include "packfile.h" #include "pager.h" #include "path.h" #include "promisor-remote.h" @@ -1357,15 +1356,8 @@ int cmd_grep(int argc, if (recurse_submodules) repo_read_gitmodules(the_repository, 1); - if (startup_info->have_repository) { - struct odb_source *source; - - odb_prepare_alternates(the_repository->objects); - for (source = the_repository->objects->sources; source; source = source->next) { - struct odb_source_files *files = odb_source_files_downcast(source); - odb_source_packed_prepare(files->packed); - } - } + if (startup_info->have_repository) + odb_prepare(the_repository->objects, 0); start_threads(&opt); } else { diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 8900ceece1cdf3..5478182f2e95c2 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -344,6 +344,7 @@ static void process_parent(struct last_modified *lm, static int last_modified_run(struct last_modified *lm) { int max_count, queue_popped = 0; + struct commit *c, *n; struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; struct prio_queue not_queue = { compare_commits_by_gen_then_commit_date }; struct commit_list *list; @@ -389,10 +390,9 @@ static int last_modified_run(struct last_modified *lm) } } - while (queue.nr) { + while ((c = prio_queue_get(&queue))) { int parent_i; struct commit_list *p; - struct commit *c = prio_queue_get(&queue); struct bitmap *active_c = active_paths_for(lm, c); if ((0 <= max_count && max_count < ++queue_popped) || @@ -416,9 +416,8 @@ static int last_modified_run(struct last_modified *lm) */ repo_parse_commit(lm->rev.repo, c); - while (not_queue.nr) { + while ((n = prio_queue_get(¬_queue))) { struct commit_list *np; - struct commit *n = prio_queue_get(¬_queue); repo_parse_commit(lm->rev.repo, n); diff --git a/builtin/log.c b/builtin/log.c index d027ce1e0bc833..350b35c556362d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1888,6 +1888,7 @@ static void prepare_bases(struct base_tree_info *bases, bases->nr_patch_id++; } clear_commit_base(&commit_base); + release_revisions(&revs); } static void print_bases(struct base_tree_info *bases, FILE *file) diff --git a/builtin/push.c b/builtin/push.c index 6021b71d668455..1b2ad3b8df7c55 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -8,6 +8,7 @@ #include "advice.h" #include "branch.h" #include "config.h" +#include "dir.h" #include "environment.h" #include "gettext.h" #include "hex.h" @@ -662,6 +663,29 @@ static int push_multiple(struct string_list *list, return result; } +static void die_if_repo_looks_like_ref(const char *repo) +{ + const char *slash = strchr(repo, '/'); + struct strbuf name = STRBUF_INIT; + int code; + + if (!slash || !slash[1] || file_exists(repo)) + return; + + strbuf_add(&name, repo, slash - repo); + if (!remote_is_configured(remote_get(name.buf), 0)) { + strbuf_release(&name); + return; + } + + code = die_message(_("'%s' is not a valid push target"), repo); + advise_if_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF, + _("Did you mean to use: git push %s %s?"), + name.buf, slash + 1); + strbuf_release(&name); + exit(code); +} + int cmd_push(int argc, const char **argv, const char *prefix, @@ -744,6 +768,17 @@ int cmd_push(int argc, if (repo) { if (!add_remote_or_group(repo, &remote_group)) { + struct remote *r; + + /* + * Check the advice up front to avoid the remote + * lookup when the hint is off. The helper still + * calls advise_if_enabled() so the hint carries the + * standard "disable this message" instructions. + */ + if (advice_enabled(ADVICE_PUSH_REPO_LOOKS_LIKE_REF)) + die_if_repo_looks_like_ref(repo); + /* * Not a configured remote name or group name. * Try treating it as a direct URL or path, e.g. @@ -753,7 +788,7 @@ int cmd_push(int argc, * from the URL so the loop below can handle it * identically to a named remote. */ - struct remote *r = pushremote_get(repo); + r = pushremote_get(repo); if (!r) die(_("bad repository '%s'"), repo); string_list_append(&remote_group, r->name); diff --git a/builtin/show-branch.c b/builtin/show-branch.c index f02831b08500c4..2435e8aeda40ef 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -62,11 +62,10 @@ static const char *get_color_reset_code(void) static struct commit *interesting(struct prio_queue *queue) { - for (size_t i = 0; i < queue->nr; i++) { - struct commit *commit = queue->array[i].data; - if (commit->object.flags & UNINTERESTING) - continue; - return commit; + struct commit *commit; + prio_queue_for_each(queue, commit) { + if (!(commit->object.flags & UNINTERESTING)) + return commit; } return NULL; } @@ -228,17 +227,18 @@ static void join_revs(struct prio_queue *queue, { int all_mask = ((1u << (REV_SHIFT + num_rev)) - 1); int all_revs = all_mask & ~((1u << REV_SHIFT) - 1); + struct commit *commit; - while (queue->nr) { + while ((commit = prio_queue_peek(queue))) { struct commit_list *parents; int still_interesting = !!interesting(queue); - struct commit *commit = prio_queue_peek(queue); - bool get_pending = true; int flags = commit->object.flags & all_mask; if (!still_interesting && extra <= 0) break; + prio_queue_get(queue); + mark_seen(commit, seen_p); if ((flags & all_revs) == all_revs) flags |= UNINTERESTING; @@ -254,14 +254,8 @@ static void join_revs(struct prio_queue *queue, if (mark_seen(p, seen_p) && !still_interesting) extra--; p->object.flags |= flags; - if (get_pending) - prio_queue_replace(queue, p); - else - prio_queue_put(queue, p); - get_pending = false; + prio_queue_put(queue, p); } - if (get_pending) - prio_queue_get(queue); } /* diff --git a/commit-reach.c b/commit-reach.c index 5df471a313cf6b..3898d09dec4e85 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -1121,6 +1121,7 @@ void ahead_behind(struct repository *r, struct nonstale_queue queue = { { .compare = compare_commits_by_gen_then_commit_date } }; + void *entry; size_t width = DIV_ROUND_UP(commits_nr, BITS_IN_EWORD); if (!commits_nr || !counts_nr) @@ -1186,8 +1187,8 @@ void ahead_behind(struct repository *r, /* STALE is used here, PARENT2 is used by insert_no_dup(). */ repo_clear_commit_marks(r, PARENT2 | STALE); - for (size_t i = 0; i < queue.pq.nr; i++) - free_bit_array(queue.pq.array[i].data); + prio_queue_for_each(&queue.pq, entry) + free_bit_array(entry); clear_bit_arrays(&bit_arrays); clear_nonstale_queue(&queue); } @@ -1320,7 +1321,7 @@ int get_branch_base_for_tip(struct repository *r, size_t bases_nr) { int best_index = -1; - struct commit *branch_point = NULL; + struct commit *c, *branch_point = NULL; struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; int found_missing_gen = 0; @@ -1373,8 +1374,7 @@ int get_branch_base_for_tip(struct repository *r, prio_queue_put(&queue, c); } - while (queue.nr) { - struct commit *c = prio_queue_get(&queue); + while ((c = prio_queue_get(&queue))) { int best_for_c = get_best(c); int best_for_p, positive; struct commit *parent; diff --git a/commit.c b/commit.c index 5c4a4319b57a33..ad26f0b40a9c64 100644 --- a/commit.c +++ b/commit.c @@ -782,24 +782,17 @@ void commit_list_sort_by_date(struct commit_list **list) struct commit *pop_most_recent_commit(struct prio_queue *queue, unsigned int mark) { - struct commit *ret = prio_queue_peek(queue); - int get_pending = 1; + struct commit *ret = prio_queue_get(queue); struct commit_list *parents = ret->parents; while (parents) { struct commit *commit = parents->item; if (!repo_parse_commit(the_repository, commit) && !(commit->object.flags & mark)) { commit->object.flags |= mark; - if (get_pending) - prio_queue_replace(queue, commit); - else - prio_queue_put(queue, commit); - get_pending = 0; + prio_queue_put(queue, commit); } parents = parents->next; } - if (get_pending) - prio_queue_get(queue); return ret; } diff --git a/fetch-pack.c b/fetch-pack.c index 120e01f3cf2674..29c41132ee0495 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -662,8 +662,8 @@ static int mark_complete_oid(const struct reference *ref, void *cb_data UNUSED) static void mark_recent_complete_commits(struct fetch_pack_args *args, timestamp_t cutoff) { - while (complete.nr) { - struct commit *item = prio_queue_peek(&complete); + struct commit *item; + while ((item = prio_queue_peek(&complete))) { if (item->date < cutoff) break; print_verbose(args, _("Marking %s as complete"), diff --git a/gpg-interface.c b/gpg-interface.c index dafd5371fa806d..95abf1ef4e1a0c 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -990,21 +990,18 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, return ret; } -/* - * Strip CR from the line endings, in case we are on Windows. - * NEEDSWORK: make it trim only CRs before LFs and rename - */ -static void remove_cr_after(struct strbuf *buffer, size_t offset) +/* Strip CR before LF from the line endings, in case we are on Windows. */ +static void strip_cr_before_lf(struct strbuf *buffer, size_t offset) { size_t i, j; for (i = j = offset; i < buffer->len; i++) { - if (buffer->buf[i] != '\r') { - if (i != j) - buffer->buf[j] = buffer->buf[i]; - j++; - } + if (buffer->buf[i] == '\r' && + i + 1 < buffer->len && buffer->buf[i + 1] == '\n') + continue; + buffer->buf[j++] = buffer->buf[i]; } + strbuf_setlen(buffer, j); } @@ -1049,8 +1046,8 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature, } strbuf_release(&gpg_status); - /* Strip CR from the line endings, in case we are on Windows. */ - remove_cr_after(signature, bottom); + /* Strip CR before LF from the line endings, in case we are on Windows. */ + strip_cr_before_lf(signature, bottom); return 0; } @@ -1136,8 +1133,8 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature, ssh_signature_filename.buf); goto out; } - /* Strip CR from the line endings, in case we are on Windows. */ - remove_cr_after(signature, bottom); + /* Strip CR before LF from the line endings, in case we are on Windows. */ + strip_cr_before_lf(signature, bottom); out: if (key_file) diff --git a/midx.c b/midx.c index cc6b94f9dd4fba..76c3f92cc374b8 100644 --- a/midx.c +++ b/midx.c @@ -101,7 +101,7 @@ static int midx_read_object_offsets(const unsigned char *chunk_start, struct multi_pack_index *get_multi_pack_index(struct odb_source_packed *source) { - odb_source_packed_prepare(source); + odb_source_prepare(&source->base, 0); return source->midx; } diff --git a/negotiator/default.c b/negotiator/default.c index 78d58d57cebbfb..19cdf3808cf266 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -113,10 +113,12 @@ static const struct object_id *get_rev(struct negotiation_state *ns) unsigned int mark; struct commit_list *parents; - if (ns->rev_list.nr == 0 || ns->non_common_revs == 0) + if (ns->non_common_revs == 0) return NULL; commit = prio_queue_get(&ns->rev_list); + if (!commit) + return NULL; repo_parse_commit(the_repository, commit); parents = commit->parents; diff --git a/negotiator/skipping.c b/negotiator/skipping.c index 68c9b3b997dc80..db90fa77b5325b 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -143,8 +143,7 @@ static int push_parent(struct data *data, struct entry *entry, /* * Find the existing entry and use it. */ - for (size_t i = 0; i < data->rev_list.nr; i++) { - parent_entry = data->rev_list.array[i].data; + prio_queue_for_each(&data->rev_list, parent_entry) { if (parent_entry->commit == to_push) goto parent_found; } @@ -181,10 +180,12 @@ static const struct object_id *get_rev(struct data *data) struct commit_list *p; int parent_pushed = 0; - if (data->rev_list.nr == 0 || data->non_common_revs == 0) + if (data->non_common_revs == 0) return NULL; entry = prio_queue_get(&data->rev_list); + if (!entry) + return NULL; commit = entry->commit; commit->object.flags |= POPPED; if (!(commit->object.flags & COMMON)) @@ -253,8 +254,9 @@ static void have_sent(struct fetch_negotiator *n, struct commit *c) static void release(struct fetch_negotiator *n) { struct data *data = n->data; - for (size_t i = 0; i < data->rev_list.nr; i++) - free(data->rev_list.array[i].data); + void *entry; + prio_queue_for_each(&data->rev_list, entry) + free(entry); clear_prio_queue(&data->rev_list); FREE_AND_NULL(data); } diff --git a/object-name.c b/object-name.c index 46159466ac543a..49e8aa466e6e43 100644 --- a/object-name.c +++ b/object-name.c @@ -1209,7 +1209,7 @@ static int get_oid_oneline(struct repository *r, l->item->object.flags |= ONELINE_SEEN; prio_queue_put(©, l->item); } - while (copy.nr) { + while (prio_queue_size(©)) { const char *p, *buf; struct commit *commit; int matches; diff --git a/odb.c b/odb.c index 7d555be09feaea..68dca6357f7548 100644 --- a/odb.c +++ b/odb.c @@ -1070,7 +1070,7 @@ void odb_free(struct object_database *o) free(o); } -void odb_reprepare(struct object_database *o) +void odb_prepare(struct object_database *o, enum odb_prepare_flags flags) { struct odb_source *source; @@ -1082,13 +1082,19 @@ void odb_reprepare(struct object_database *o) * the linked list, so existing odbs will continue to exist for * the lifetime of the process. */ - o->loaded_alternates = 0; - odb_prepare_alternates(o); + if (flags & ODB_PREPARE_FLUSH_CACHES) { + o->loaded_alternates = 0; + o->object_count_valid = 0; + } + odb_prepare_alternates(o); for (source = o->sources; source; source = source->next) - odb_source_reprepare(source); - - o->object_count_valid = 0; + odb_source_prepare(source, flags); obj_read_unlock(); } + +void odb_reprepare(struct object_database *o) +{ + odb_prepare(o, ODB_PREPARE_FLUSH_CACHES); +} diff --git a/odb.h b/odb.h index 3834a0dcbf033b..a1948650526cca 100644 --- a/odb.h +++ b/odb.h @@ -124,10 +124,22 @@ void odb_free(struct object_database *o); */ void odb_close(struct object_database *o); +enum odb_prepare_flags { + /* + * Flush caches, reload alternates and then re-prepare each object + * source so that new objects may become accessible. + */ + ODB_PREPARE_FLUSH_CACHES = (1 << 0), +}; + /* - * Clear caches, reload alternates and then reload object sources so that new - * objects may become accessible. + * Prepare the object database for use. Calling this function is generally not + * needed, but can be useful in case the caller wants to pre-open individual + * sources. */ +void odb_prepare(struct object_database *o, enum odb_prepare_flags flags); + +/* Equivalent to `odb_prepare(o, ODB_PREPARE_FLUSH_CACHES)`. */ void odb_reprepare(struct object_database *o); /* diff --git a/odb/source-files.c b/odb/source-files.c index bbd1784b337c6d..6c8e935c753983 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -41,11 +41,12 @@ static void odb_source_files_close(struct odb_source *source) odb_source_close(&files->packed->base); } -static void odb_source_files_reprepare(struct odb_source *source) +static void odb_source_files_prepare(struct odb_source *source, + enum odb_prepare_flags flags) { struct odb_source_files *files = odb_source_files_downcast(source); - odb_source_reprepare(&files->loose->base); - odb_source_reprepare(&files->packed->base); + odb_source_prepare(&files->loose->base, flags); + odb_source_prepare(&files->packed->base, flags); } static int odb_source_files_read_object_info(struct odb_source *source, @@ -273,7 +274,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, files->base.free = odb_source_files_free; files->base.close = odb_source_files_close; - files->base.reprepare = odb_source_files_reprepare; + files->base.prepare = odb_source_files_prepare; files->base.read_object_info = odb_source_files_read_object_info; files->base.read_object_stream = odb_source_files_read_object_stream; files->base.for_each_object = odb_source_files_for_each_object; diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c index 7f1b6f46363f2e..0b51c582384ee9 100644 --- a/odb/source-inmemory.c +++ b/odb/source-inmemory.c @@ -325,7 +325,8 @@ static void odb_source_inmemory_close(struct odb_source *source UNUSED) { } -static void odb_source_inmemory_reprepare(struct odb_source *source UNUSED) +static void odb_source_inmemory_prepare(struct odb_source *source UNUSED, + enum odb_prepare_flags flags UNUSED) { } @@ -365,7 +366,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb) source->base.free = odb_source_inmemory_free; source->base.close = odb_source_inmemory_close; - source->base.reprepare = odb_source_inmemory_reprepare; + source->base.prepare = odb_source_inmemory_prepare; source->base.read_object_info = odb_source_inmemory_read_object_info; source->base.read_object_stream = odb_source_inmemory_read_object_stream; source->base.for_each_object = odb_source_inmemory_for_each_object; diff --git a/odb/source-loose.c b/odb/source-loose.c index 6211348a4d3561..a404046d503a4b 100644 --- a/odb/source-loose.c +++ b/odb/source-loose.c @@ -664,10 +664,12 @@ static void odb_source_loose_clear_cache(struct odb_source_loose *loose) sizeof(loose->subdir_seen)); } -static void odb_source_loose_reprepare(struct odb_source *source) +static void odb_source_loose_prepare(struct odb_source *source, + enum odb_prepare_flags flags) { struct odb_source_loose *loose = odb_source_loose_downcast(source); - odb_source_loose_clear_cache(loose); + if (flags & ODB_PREPARE_FLUSH_CACHES) + odb_source_loose_clear_cache(loose); } static void odb_source_loose_close(struct odb_source *source UNUSED) @@ -708,7 +710,7 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb, loose->base.free = odb_source_loose_free; loose->base.close = odb_source_loose_close; - loose->base.reprepare = odb_source_loose_reprepare; + loose->base.prepare = odb_source_loose_prepare; loose->base.read_object_info = odb_source_loose_read_object_info; loose->base.read_object_stream = odb_source_loose_read_object_stream; loose->base.for_each_object = odb_source_loose_for_each_object; diff --git a/odb/source-packed.c b/odb/source-packed.c index 06b31dd7435d70..a0259b95bfb5f2 100644 --- a/odb/source-packed.c +++ b/odb/source-packed.c @@ -15,7 +15,7 @@ static int find_pack_entry(struct odb_source_packed *store, { struct packfile_list_entry *l; - odb_source_packed_prepare(store); + odb_source_prepare(&store->base, 0); if (store->midx && fill_midx_entry(store->midx, oid, e)) return 1; @@ -47,7 +47,7 @@ static int odb_source_packed_read_object_info(struct odb_source *source, * been added since the last time we have prepared the packfile store. */ if (flags & OBJECT_INFO_SECOND_READ) - odb_source_reprepare(source); + odb_source_prepare(source, ODB_PREPARE_FLUSH_CACHES); if (!find_pack_entry(packed, oid, &e)) return 1; @@ -692,27 +692,25 @@ static int sort_pack(const struct packfile_list_entry *a, return -1; } -void odb_source_packed_prepare(struct odb_source_packed *source) +static void odb_source_packed_prepare(struct odb_source *source, + enum odb_prepare_flags flags) { - if (source->initialized) + struct odb_source_packed *packed = odb_source_packed_downcast(source); + + if (flags & ODB_PREPARE_FLUSH_CACHES) + packed->initialized = false; + if (packed->initialized) return; - prepare_multi_pack_index_one(source); - prepare_packed_git_one(source); + prepare_multi_pack_index_one(packed); + prepare_packed_git_one(packed); - sort_packs(&source->packs.head, sort_pack); - for (struct packfile_list_entry *e = source->packs.head; e; e = e->next) + sort_packs(&packed->packs.head, sort_pack); + for (struct packfile_list_entry *e = packed->packs.head; e; e = e->next) if (!e->next) - source->packs.tail = e; + packed->packs.tail = e; - source->initialized = true; -} - -static void odb_source_packed_reprepare(struct odb_source *source) -{ - struct odb_source_packed *packed = odb_source_packed_downcast(source); - packed->initialized = false; - odb_source_packed_prepare(packed); + packed->initialized = true; } static void odb_source_packed_reparent(const char *name UNUSED, @@ -768,7 +766,7 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb, packed->base.free = odb_source_packed_free; packed->base.close = odb_source_packed_close; - packed->base.reprepare = odb_source_packed_reprepare; + packed->base.prepare = odb_source_packed_prepare; packed->base.read_object_info = odb_source_packed_read_object_info; packed->base.read_object_stream = odb_source_packed_read_object_stream; packed->base.for_each_object = odb_source_packed_for_each_object; diff --git a/odb/source-packed.h b/odb/source-packed.h index f0724b204c9223..77309ddd0932b6 100644 --- a/odb/source-packed.h +++ b/odb/source-packed.h @@ -82,13 +82,4 @@ static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_so return container_of(source, struct odb_source_packed, base); } -/* - * Prepare the source by loading packfiles and multi-pack indices for - * all alternates. This becomes a no-op if the source is already prepared. - * - * It shouldn't typically be necessary to call this function directly, as - * functions that access the source know to prepare it. - */ -void odb_source_packed_prepare(struct odb_source_packed *source); - #endif diff --git a/odb/source.h b/odb/source.h index 8767708c9c769c..efeff7ed12adbb 100644 --- a/odb/source.h +++ b/odb/source.h @@ -83,11 +83,12 @@ struct odb_source { void (*close)(struct odb_source *source); /* - * This callback is expected to clear underlying caches of the object - * database source. The function is called when the repository has for - * example just been repacked so that new objects will become visible. + * This callback is expected to prepare the source so that it becomes + * ready for use. It optionally clears underlying caches of the object + * database source. */ - void (*reprepare)(struct odb_source *source); + void (*prepare)(struct odb_source *source, + enum odb_prepare_flags flags); /* * This callback is expected to read object information from the object @@ -308,13 +309,14 @@ static inline void odb_source_close(struct odb_source *source) } /* - * Reprepare the object database source and clear any caches. Depending on the + * Prepare the object database source and clear any caches. Depending on the * backend used this may have the effect that concurrently-written objects * become visible. */ -static inline void odb_source_reprepare(struct odb_source *source) +static inline void odb_source_prepare(struct odb_source *source, + enum odb_prepare_flags flags) { - source->reprepare(source); + source->prepare(source, flags); } /* diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 1bcb3f98a42518..acbea890313b21 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -636,6 +636,8 @@ static int fill_bitmap_commit(struct bitmap_writer *writer, struct bitmap_index *old_bitmap, const uint32_t *mapping) { + struct commit *c; + struct tree *t; int found; int from_pseudo_merge = commit->object.flags & BITMAP_PSEUDO_MERGE; uint32_t pos; @@ -650,9 +652,8 @@ static int fill_bitmap_commit(struct bitmap_writer *writer, prio_queue_put(queue, commit); - while (queue->nr) { + while ((c = prio_queue_get(queue))) { struct commit_list *p; - struct commit *c = prio_queue_get(queue); if (old_bitmap && mapping) { struct ewah_bitmap *old; @@ -740,8 +741,7 @@ static int fill_bitmap_commit(struct bitmap_writer *writer, } } - while (tree_queue->nr) { - struct tree *t = prio_queue_get(tree_queue); + while ((t = prio_queue_get(tree_queue))) { int found; pos = find_object_pos(writer, &t->object.oid, &found); diff --git a/packfile.c b/packfile.c index 1d1b23b6cc782f..60dd0f286abb07 100644 --- a/packfile.c +++ b/packfile.c @@ -855,7 +855,7 @@ void for_each_file_in_pack_dir(const char *objdir, struct packfile_list_entry *packfile_store_get_packs(struct odb_source_packed *store) { - odb_source_packed_prepare(store); + odb_source_prepare(&store->base, 0); if (store->midx) { struct multi_pack_index *m = store->midx; diff --git a/path-walk.c b/path-walk.c index edc8e736d7435a..9ca3248ea8f53d 100644 --- a/path-walk.c +++ b/path-walk.c @@ -699,6 +699,7 @@ int walk_objects_by_path(struct path_walk_info *info) int ret; size_t commits_nr = 0, paths_nr = 0; struct commit *c; + char *path; struct type_and_oid_list *root_tree_list; struct type_and_oid_list *commit_list; struct path_walk_context ctx = { @@ -808,8 +809,7 @@ int walk_objects_by_path(struct path_walk_info *info) free(commit_list); trace2_region_enter("path-walk", "path-walk", info->revs->repo); - while (!ret && ctx.path_stack.nr) { - char *path = prio_queue_get(&ctx.path_stack); + while (!ret && (path = prio_queue_get(&ctx.path_stack))) { paths_nr++; ret = walk_path(&ctx, path); @@ -821,12 +821,12 @@ int walk_objects_by_path(struct path_walk_info *info) if (!strmap_empty(&ctx.paths_to_lists)) { struct hashmap_iter iter; struct strmap_entry *entry; + char *path; strmap_for_each_entry(&ctx.paths_to_lists, &iter, entry) push_to_stack(&ctx, entry->key); - while (!ret && ctx.path_stack.nr) { - char *path = prio_queue_get(&ctx.path_stack); + while (!ret && (path = prio_queue_get(&ctx.path_stack))) { paths_nr++; ret = walk_path(&ctx, path); diff --git a/prio-queue.c b/prio-queue.c index 9748528ce6ecd6..199775d5afd22a 100644 --- a/prio-queue.c +++ b/prio-queue.c @@ -22,40 +22,19 @@ void prio_queue_reverse(struct prio_queue *queue) if (queue->compare) BUG("prio_queue_reverse() on non-LIFO queue"); - if (!queue->nr) + if (!queue->nr_) return; - for (i = 0; i < (j = (queue->nr - 1) - i); i++) + for (i = 0; i < (j = (queue->nr_ - 1) - i); i++) swap(queue, i, j); } void clear_prio_queue(struct prio_queue *queue) { FREE_AND_NULL(queue->array); - queue->nr = 0; + queue->nr_ = 0; queue->alloc = 0; queue->insertion_ctr = 0; -} - -void prio_queue_put(struct prio_queue *queue, void *thing) -{ - size_t ix, parent; - - /* Append at the end */ - ALLOC_GROW(queue->array, queue->nr + 1, queue->alloc); - queue->array[queue->nr].ctr = queue->insertion_ctr++; - queue->array[queue->nr].data = thing; - queue->nr++; - if (!queue->compare) - return; /* LIFO */ - - /* Bubble up the new one */ - for (ix = queue->nr - 1; ix; ix = parent) { - parent = (ix - 1) / 2; - if (compare(queue, parent, ix) <= 0) - break; - - swap(queue, parent, ix); - } + queue->get_pending = 0; } static void sift_down_root(struct prio_queue *queue) @@ -63,9 +42,9 @@ static void sift_down_root(struct prio_queue *queue) size_t ix, child; /* Push down the one at the root */ - for (ix = 0; ix * 2 + 1 < queue->nr; ix = child) { + for (ix = 0; ix * 2 + 1 < queue->nr_; ix = child) { child = ix * 2 + 1; /* left */ - if (child + 1 < queue->nr && + if (child + 1 < queue->nr_ && compare(queue, child, child + 1) >= 0) child++; /* use right child */ @@ -76,43 +55,72 @@ static void sift_down_root(struct prio_queue *queue) } } -void *prio_queue_get(struct prio_queue *queue) +static inline void flush_get(struct prio_queue *queue) +{ + if (!queue->get_pending) + return; + queue->get_pending = 0; + queue->array[0] = queue->array[--queue->nr_]; + sift_down_root(queue); +} + +void prio_queue_put(struct prio_queue *queue, void *thing) { - void *result; + size_t ix, parent; - if (!queue->nr) - return NULL; + if (queue->get_pending) { + queue->get_pending = 0; + queue->array[0].ctr = queue->insertion_ctr++; + queue->array[0].data = thing; + sift_down_root(queue); + return; + } + + /* Append at the end */ + ALLOC_GROW(queue->array, queue->nr_ + 1, queue->alloc); + queue->array[queue->nr_].ctr = queue->insertion_ctr++; + queue->array[queue->nr_].data = thing; + queue->nr_++; if (!queue->compare) - return queue->array[--queue->nr].data; /* LIFO */ + return; /* LIFO */ - result = queue->array[0].data; - if (!--queue->nr) - return result; + /* Bubble up the new one */ + for (ix = queue->nr_ - 1; ix; ix = parent) { + parent = (ix - 1) / 2; + if (compare(queue, parent, ix) <= 0) + break; - queue->array[0] = queue->array[queue->nr]; - sift_down_root(queue); - return result; + swap(queue, parent, ix); + } } -void *prio_queue_peek(struct prio_queue *queue) +void *prio_queue_get(struct prio_queue *queue) { - if (!queue->nr) + if (queue->nr_ <= queue->get_pending) { + queue->nr_ = 0; + queue->get_pending = 0; return NULL; + } if (!queue->compare) - return queue->array[queue->nr - 1].data; + return queue->array[--queue->nr_].data; /* LIFO */ + + flush_get(queue); + + queue->get_pending = 1; return queue->array[0].data; } -void prio_queue_replace(struct prio_queue *queue, void *thing) +void *prio_queue_peek(struct prio_queue *queue) { - if (!queue->nr) { - prio_queue_put(queue, thing); - } else if (!queue->compare) { - queue->array[queue->nr - 1].ctr = queue->insertion_ctr++; - queue->array[queue->nr - 1].data = thing; - } else { - queue->array[0].ctr = queue->insertion_ctr++; - queue->array[0].data = thing; - sift_down_root(queue); + if (queue->nr_ <= queue->get_pending) { + queue->nr_ = 0; + queue->get_pending = 0; + return NULL; } + if (!queue->compare) + return queue->array[queue->nr_ - 1].data; + + flush_get(queue); + + return queue->array[0].data; } diff --git a/prio-queue.h b/prio-queue.h index da7fad2f1f408f..570b48e6485b19 100644 --- a/prio-queue.h +++ b/prio-queue.h @@ -30,8 +30,9 @@ struct prio_queue { prio_queue_compare_fn compare; size_t insertion_ctr; void *cb_data; - size_t alloc, nr; + size_t alloc, nr_; /* use prio_queue_size() for logical count */ struct prio_queue_entry *array; + unsigned get_pending; }; /* @@ -52,13 +53,15 @@ void *prio_queue_get(struct prio_queue *); */ void *prio_queue_peek(struct prio_queue *); -/* - * Replace the "thing" that compares the smallest with a new "thing", - * like prio_queue_get()+prio_queue_put() would do, but in a more - * efficient way. Does the same as prio_queue_put() if the queue is - * empty. - */ -void prio_queue_replace(struct prio_queue *queue, void *thing); +static inline size_t prio_queue_size(const struct prio_queue *queue) +{ + return queue->nr_ - queue->get_pending; +} + +#define prio_queue_for_each(queue, it) \ + for (size_t pq_ix_ = (queue)->get_pending; \ + pq_ix_ < (queue)->nr_ && ((it) = (queue)->array[pq_ix_].data, 1); \ + pq_ix_++) void clear_prio_queue(struct prio_queue *); diff --git a/reftable/writer.c b/reftable/writer.c index f850e9d599e387..d969a6a0210e8b 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -151,10 +151,6 @@ int reftable_writer_new(struct reftable_writer **out, struct reftable_write_options opts = {0}; struct reftable_writer *wp; - wp = reftable_calloc(1, sizeof(*wp)); - if (!wp) - return REFTABLE_OUT_OF_MEMORY_ERROR; - if (_opts) opts = *_opts; options_set_defaults(&opts); @@ -164,6 +160,10 @@ int reftable_writer_new(struct reftable_writer **out, if (!hash_id) hash_id = REFTABLE_HASH_SHA1; + wp = reftable_calloc(1, sizeof(*wp)); + if (!wp) + return REFTABLE_OUT_OF_MEMORY_ERROR; + reftable_buf_init(&wp->block_writer_data.last_key); reftable_buf_init(&wp->last_key); reftable_buf_init(&wp->scratch); diff --git a/revision.c b/revision.c index 0c95edef5947fa..137a86d33bbbe1 100644 --- a/revision.c +++ b/revision.c @@ -477,16 +477,15 @@ static struct commit *handle_commit(struct rev_info *revs, static int everybody_uninteresting(struct prio_queue *orig, struct commit **interesting_cache) { - size_t i; + struct commit *commit; if (*interesting_cache) { - struct commit *commit = *interesting_cache; + commit = *interesting_cache; if (!(commit->object.flags & UNINTERESTING)) return 0; } - for (i = 0; i < orig->nr; i++) { - struct commit *commit = orig->array[i].data; + prio_queue_for_each(orig, commit) { if (commit->object.flags & UNINTERESTING) continue; @@ -1443,7 +1442,7 @@ static int limit_list(struct rev_info *revs) struct commit_list *original_list = revs->commits; struct commit_list *newlist = NULL; struct commit_list **p = &newlist; - struct commit *interesting_cache = NULL; + struct commit *commit, *interesting_cache = NULL; struct prio_queue queue = { .compare = compare_commits_by_commit_date }; if (revs->ancestry_path_implicit_bottoms) { @@ -1458,8 +1457,7 @@ static int limit_list(struct rev_info *revs) prio_queue_put(&queue, commit); } - while (queue.nr) { - struct commit *commit = prio_queue_get(&queue); + while ((commit = prio_queue_get(&queue))) { struct object *obj = &commit->object; if (commit == interesting_cache) @@ -4058,8 +4056,9 @@ static enum rewrite_result rewrite_one_1(struct rev_info *revs, static void merge_queue_into_prio_queue(struct prio_queue *from, struct prio_queue *to) { - while (from->nr) - prio_queue_put(to, prio_queue_get(from)); + struct commit *item; + while ((item = prio_queue_get(from))) + prio_queue_put(to, item); } static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index e7829c2c4bfdc3..e2682a83a0c8d1 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -1022,6 +1022,44 @@ test_expect_success '--set-upstream-to fails on a missing dst branch' ' test_cmp expect err ' +test_expect_success '--set-upstream-to suggests / on slip' ' + test_when_finished "git remote remove slip-remote" && + git remote add slip-remote . && + git update-ref refs/remotes/slip-remote/slip-feature HEAD && + test_must_fail git branch --set-upstream-to slip-remote slip-feature 2>err && + test_grep "takes a single / argument" err && + test_grep "hint: Did you mean to use: git branch --set-upstream-to=slip-remote/slip-feature?" err && + test_must_fail git -c advice.setUpstreamFailure=false \ + branch --set-upstream-to slip-remote slip-feature 2>err && + test_grep ! "Did you mean" err +' + +test_expect_success '--set-upstream-to does not suggest when no matching remote ref' ' + test_when_finished "git remote remove slip-remote" && + git remote add slip-remote . && + test_must_fail git branch --set-upstream-to slip-remote no-such-branch 2>err && + test_grep "branch ${SQ}no-such-branch${SQ} does not exist" err && + test_grep ! "Did you mean" err +' + +test_expect_success '--set-upstream-to to a local branch is not mistaken for a slip' ' + git branch slip-local-upstream && + git branch slip-local-target && + git branch --set-upstream-to=slip-local-upstream slip-local-target 2>err && + test_grep ! "Did you mean" err && + echo refs/heads/slip-local-upstream >expect && + git config branch.slip-local-target.merge >actual && + test_cmp expect actual +' + +test_expect_success '--set-upstream-to slip suggestion keeps a slashed branch name' ' + test_when_finished "git remote remove slip-remote" && + git remote add slip-remote . && + git update-ref refs/remotes/slip-remote/slip/feature HEAD && + test_must_fail git branch --set-upstream-to slip-remote slip/feature 2>err && + test_grep "hint: Did you mean to use: git branch --set-upstream-to=slip-remote/slip/feature?" err +' + test_expect_success '--set-upstream-to fails on a missing src branch' ' test_must_fail git branch --set-upstream-to does-not-exist main 2>err && test_grep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh index 80b06a0cd2886d..2294645902c90e 100755 --- a/t/t5529-push-errors.sh +++ b/t/t5529-push-errors.sh @@ -54,6 +54,37 @@ test_expect_success 'detect empty remote with targeted refspec' ' grep "fatal: bad repository ${SQ}${SQ}" stderr ' +test_expect_success 'suggest for a / slip' ' + test_must_fail git push origin/main 2>stderr && + test_grep "${SQ}origin/main${SQ} is not a valid push target" stderr && + test_grep "hint: Did you mean to use: git push origin main?" stderr && + test_must_fail git -c advice.pushRepoLooksLikeRef=false push origin/main 2>stderr && + test_grep ! "Did you mean" stderr +' + +test_expect_success 'suggest when the branch has slashes' ' + test_must_fail git push origin/feature/x 2>stderr && + test_grep "hint: Did you mean to use: git push origin feature/x?" stderr +' + +test_expect_success 'no suggestion when prefix is not a configured remote' ' + test_must_fail git push not-a-remote/main 2>stderr && + test_grep ! "Did you mean" stderr +' + +test_expect_success 'no suggestion for a trailing slash with no branch' ' + test_must_fail git push origin/ 2>stderr && + test_grep ! "Did you mean" stderr +' + +test_expect_success 'no suggestion when the argument is an existing path' ' + test_when_finished "rm -rf origin" && + git init --bare origin/main && + git push origin/main HEAD:refs/heads/pushed 2>stderr && + test_grep ! "Did you mean" stderr && + git -C origin/main rev-parse --verify refs/heads/pushed +' + test_expect_success 'detect ambiguous refs early' ' git branch foo && git tag foo && diff --git a/t/test-lib.sh b/t/test-lib.sh index ceefb99bff60e0..d390c53ec1cfb9 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1217,14 +1217,14 @@ check_test_results_san_file_ () { then return fi && - say_color error "$(cat "$TEST_RESULTS_SAN_FILE".*)" && + say_color >&4 error "$(cat "$TEST_RESULTS_SAN_FILE".*)" && if test "$test_failure" = 0 then - say "Our logs revealed a memory leak, exit non-zero!" && + say >&4 "Our logs revealed a memory leak, exit non-zero!" && invert_exit_code=t else - say "Our logs revealed a memory leak..." + say >&4 "Our logs revealed a memory leak..." fi } diff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c index 63e58114ae7dd5..af3e0b85988832 100644 --- a/t/unit-tests/u-prio-queue.c +++ b/t/unit-tests/u-prio-queue.c @@ -53,13 +53,13 @@ static void test_prio_queue(int *input, size_t input_size, prio_queue_reverse(&pq); break; case REPLACE: - peek = prio_queue_peek(&pq); + get = prio_queue_get(&pq); cl_assert(i + 1 < input_size); cl_assert(input[i + 1] >= 0); cl_assert(j < result_size); - cl_assert_equal_i(result[j], show(peek)); + cl_assert_equal_i(result[j], show(get)); j++; - prio_queue_replace(&pq, &input[++i]); + prio_queue_put(&pq, &input[++i]); break; default: prio_queue_put(&pq, &input[i]); diff --git a/walker.c b/walker.c index e98eb6da53692e..e3de77f0925082 100644 --- a/walker.c +++ b/walker.c @@ -84,12 +84,12 @@ static struct prio_queue complete = { compare_commits_by_commit_date }; static int process_commit(struct walker *walker, struct commit *commit) { struct commit_list *parents; + struct commit *item; if (repo_parse_commit(the_repository, commit)) return -1; - while (complete.nr) { - struct commit *item = prio_queue_peek(&complete); + while ((item = prio_queue_peek(&complete))) { if (item->date < commit->date) break; pop_most_recent_commit(&complete, COMPLETE);