git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] remote: initialize values that might not be set

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 11, 2021, 01:41 UTC
Message-ID
<xmqqeed95gaw.fsf@gitster.g>
In-Reply-To
<nycvar.QRO.7.76.6.2106101046470.57@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> You will notice that there are two Trace2 calls in that conditional `abf
> == AHEAD_BEHIND_FULL` block.

Yes, the calls use ours/theirs uninitialized. Is it sensible to show 0 there, or "(unset)" or its moral equivalent (e.g. "-1")? Not showing them indeed is an option, which is what you did below, and that I find sensible, too.

Show 24 quoted lines
> Now, what I failed to realize when reviewing this code (and I _bet_ Stolee
> was in the same boat when they contributed the patch) is that this version
> of `format_tracking_info()` is different from what is in v2.32.0. It is
> the version we have in the `microsoft/git` fork, and it has not yet made
> it upstream. To be precise, it is this commit:
> https://github.com/microsoft/git/commit/91209e591b0398c8334a78001a245807f7eb348a
>
> In light of this, it might make more sense for us to fixup! this commit
> thusly:
>
> -- snip --
> diff --git a/remote.c b/remote.c
> index caed9cbc31b1..cfb7b6bd8d30 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -2110,7 +2110,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
>  	sti = stat_tracking_info(branch, &ours, &theirs, &full_base, 0, abf);
>  	trace2_data_intmax("tracking", NULL, "stat_tracking_info/ab_flags", abf);
>  	trace2_data_intmax("tracking", NULL, "stat_tracking_info/ab_result", sti);
> -	if (abf == AHEAD_BEHIND_FULL) {
> +	if (sti >= 0 && abf == AHEAD_BEHIND_FULL) {
>  	    trace2_data_intmax("tracking", NULL, "stat_tracking_info/ab_ahead", ours);
>  	    trace2_data_intmax("tracking", NULL, "stat_tracking_info/ab_behind", theirs);
>  	}
Previous: Johannes SchindelinNext: Derrick Stolee
Message 5 of 6 in “remote: initialize values that might not be set”
  1. remote: initialize values that might not be setDerrick Stolee via GitGitGadget, Jun 7, 2021
  2. Johannes SchindelinJun 7, 2021
  3. Junio C HamanoJun 7, 2021
  4. Johannes SchindelinJun 10, 2021
  5. Junio C HamanoJun 11, 2021
  6. Derrick StoleeJun 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.