Re: [PATCH v19 1/2] refactor format_branch_comparison in preparation
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 10, 2026, 02:02 UTC
- Message-ID
- <xmqqjyxqtebq.fsf@gitster.g>
- In-Reply-To
- <451d7a498617fbcbeb08ee644cb621cbf6af0bd5.1767984037.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 20 quoted lines
> +static void format_branch_comparison(struct strbuf *sb,
> + bool up_to_date,
> + int ours, int theirs,
> + const char *branch_name,
> + enum ahead_behind_flags abf,
> + bool show_divergence_advice)
> +{
> + if (up_to_date) {
> strbuf_addf(sb,
> _("Your branch is up to date with '%s'.\n"),
> - base);
> + branch_name);
> } else if (abf == AHEAD_BEHIND_QUICK) {
> strbuf_addf(sb,
> _("Your branch and '%s' refer to different commits.\n"),
> - base);
> + branch_name);
> if (advice_enabled(ADVICE_STATUS_HINTS))
> strbuf_addf(sb, _(" (use \"%s\" for details)\n"),
> "git status --ahead-behind");OK. We _could_, just like we moved the "upstream_gone" case to the caller, move the "up to date" case to the caller as well, but this reads well now. And we do not need the (!ours && !theirs) case in this if/else if/... cascade. Very good.
Show 36 quoted lines
> +/*
> + * Return true when there is anything to report, otherwise false.
> + */
> +int format_tracking_info(struct branch *branch, struct strbuf *sb,
> + enum ahead_behind_flags abf,
> + int show_divergence_advice)
> +{
> + int ours, theirs, sti;
> + const char *full_base;
> + char *base;
> + int upstream_is_gone = 0;
> +
> + sti = stat_tracking_info(branch, &ours, &theirs, &full_base, 0, abf);
> + if (sti < 0) {
> + if (!full_base)
> + return 0;
> + upstream_is_gone = 1;
> + }
> +
> + base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
> + full_base, 0);
> +
> + if (upstream_is_gone) {
> + strbuf_addf(sb,
> + _("Your branch is based on '%s', but the upstream is gone.\n"),
> + base);
> + if (advice_enabled(ADVICE_STATUS_HINTS))
> + strbuf_addstr(sb,
> + _(" (use \"git branch --unset-upstream\" to fixup)\n"));
> + } else {
> + format_branch_comparison(sb, !sti, ours, theirs, base, abf, show_divergence_advice);
> + }
> +
> free(base);
> return 1;
> }