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

Re: [PATCH v3 1/5] stat_tracking_info: return +1 when branches not equal

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2018, 21:41 UTC
Message-ID
<xmqqr2r5e1yh.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20180103214733.797-2-git@jeffhostetler.com>
Jeff Hostetler <git@jeffhostetler.com> writes:
Show 9 quoted lines
> -		if (stat_tracking_info(branch, &num_ours,
> -				       &num_theirs, NULL)) {
> +		if (stat_tracking_info(branch, &num_ours, &num_theirs,
> +				       NULL, AHEAD_BEHIND_FULL) < 0) {
> ...
> -		if (stat_tracking_info(branch, &num_ours,
> -				       &num_theirs, NULL))
> +		if (stat_tracking_info(branch, &num_ours, &num_theirs,
> +				       NULL, AHEAD_BEHIND_FULL) < 0)

Mental note: any code that reacted to stat_tracking_info() returning non-zero was reacting to "no useful info in num_{ours,theirs}". They now have to compare the returned value with "< 0" for the same purpose.

Show 23 quoted lines
> ...
>   * Returns -1 if num_ours and num_theirs could not be filled in (e.g., no
> - * upstream defined, or ref does not exist), 0 otherwise.
> + * upstream defined, or ref does not exist).  Returns 0 if the commits are
> + * identical.  Returns 1 if commits are different.
>   */
>  int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
> -		       const char **upstream_name)
> +		       const char **upstream_name, enum ahead_behind_flags abf)
>  {
>  	struct object_id oid;
>  	struct commit *ours, *theirs;
> @@ -2019,6 +2026,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
>  		*num_theirs = *num_ours = 0;
>  		return 0;
>  	}
> +	if (abf == AHEAD_BEHIND_QUICK)
> +		return 1;
> ...
>  	argv_array_clear(&argv);
> -	return 0;
> +	return 1;
>  }

When a caller gets +1 from the function, it is not safe to peek into *num_{ours,theirs} if it passed _QUICK.

> @@ -2064,7 +2073,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
> -	if (stat_tracking_info(branch, &ours, &theirs, &full_base) < 0) {
> +	if (stat_tracking_info(branch, &ours, &theirs, &full_base,
> +			       AHEAD_BEHIND_FULL) < 0) {
Sane conversion to the new return value convention.
Show 11 quoted lines
> diff --git a/wt-status.c b/wt-status.c
> index 94e5eba..8f7fdc6 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1791,7 +1791,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>  
>  	color_fprintf(s->fp, branch_color_local, "%s", branch_name);
>  
> -	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) {
> +	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
> +			       AHEAD_BEHIND_FULL) < 0) {
Ditto.
Show 7 quoted lines
> @@ -1928,7 +1929,8 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
>  		/* Lookup stats on the upstream tracking branch, if set. */
>  		branch = branch_get(branch_name);
>  		base = NULL;
> -		ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind, &base) == 0);
> +		ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind,
> +					      &base, AHEAD_BEHIND_FULL) >= 0);

If a later step plans to (conditionally) allow _QUICK to be passed here, this conversion is questionable, because ab_info being true no longer is a sign that nr_{ahead,behind} are valid.

I suspect that moving the "s/ab_info/sti/" bits around here from step [2/5] to this commit may make the result after this patch more consistent, but it is not a big deal either way.

>  		if (base) {
>  			base = shorten_unambiguous_ref(base, 0);
>  			fprintf(s->fp, "# branch.upstream %s%c", base, eol);
Previous: Jeff HostetlerNext: Jeff Hostetler
Message 4 of 14 in “Add --no-ahead-behind to status”
  1. 0/5 Add --no-ahead-behind to statusJeff Hostetler, Jan 3, 2018
  2. 3/5 status: update short status to respect --no-ahead-behindJeff Hostetler, Jan 3, 2018
  3. 1/5 stat_tracking_info: return +1 when branches not equalJeff Hostetler, Jan 3, 2018
  4. Junio C HamanoJan 4, 2018
  5. 5/5 status: add status.aheadBehind value for porcelain outputJeff Hostetler, Jan 3, 2018
  6. 2/5 status: add --[no-]ahead-behind to status and commit for V2 format.Jeff Hostetler, Jan 3, 2018
  7. Junio C HamanoJan 4, 2018
  8. Jeff HostetlerJan 5, 2018
  9. 4/5 status: support --no-ahead-behind in long formatJeff Hostetler, Jan 3, 2018
  10. Jeff KingJan 4, 2018
  11. Jeff HostetlerJan 5, 2018
  12. Junio C HamanoJan 5, 2018
  13. Jeff KingJan 8, 2018
  14. Jeff HostetlerJan 8, 2018

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.