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

Re: [PATCH v3 2/5] status: add --[no-]ahead-behind to status and commit for V2 format.

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Jan 5, 2018, 16:31 UTC
Message-ID
<6fe41395-6cb5-cbfe-88cd-5b0b21fad7b8@jeffhostetler.com>
In-Reply-To
<xmqqlghde0uy.fsf@gitster.mtv.corp.google.com>
On 1/4/2018 5:05 PM, Junio C Hamano wrote:
Show 70 quoted lines
> Jeff Hostetler <git@jeffhostetler.com> writes:
> 
>> +		sti = stat_tracking_info(branch, &nr_ahead, &nr_behind,
>> +					 &base, s->ahead_behind_flags);
>>   		if (base) {
>>   			base = shorten_unambiguous_ref(base, 0);
>>   			fprintf(s->fp, "# branch.upstream %s%c", base, eol);
>>   			free((char *)base);
>>   
>> -			if (ab_info)
>> -				fprintf(s->fp, "# branch.ab +%d -%d%c", nr_ahead, nr_behind, eol);
>> +			if (sti >= 0) {
>> +				if (s->ahead_behind_flags == AHEAD_BEHIND_FULL)
>> +					fprintf(s->fp, "# branch.ab +%d -%d%c",
>> +						nr_ahead, nr_behind, eol);
>> +				else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK)
>> +					fprintf(s->fp, "# branch.equal %s%c",
>> +						sti ? "neq" : "eq", eol);
> 
> This is related to what I said in the review of [1/5], but this
> arrangement to require the caller to know that _QUICK request
> results in incomplete information smells like a bit of maintenance
> hassle.
> 
> We'd rather allow the caller to tell if it was given incomplete
> information from the values returned by stat_tracking_info()
> function (notice the plural "values" here; what is returned in
> nr_{ahead,behind} also counts).  For example, we can keep the (-1 =>
> "no relation", 0 => "identical", 1 => "different") as return values
> of the function, but have it clear nr_{ahead,behind} when it only
> knows the two are different but not by how many commits.  That way,
> this step can instead do:
> 
> 	ab_info = stat_tracking_info(...);
> 	if (base) {
> 		... do the base thing ...
> 		if (ab_info > 0) {
> 			/* different */
> 			if (nr_ahead || nr_behind)
> 				fprintf(... +%d -%d ... nr_ahead, nr_behind, ...);
> 			else
> 				fprintf(... "neq" ...);
> 		} else if (!ab_info) {
> 			/* same */
> 			fprintf(... +%d -%d ... nr_ahead, nr_behind, ...);
> 		}
> 		...
> 
> That would allow us to later add different kinds of _QUICK that do
> not give full information without having to update this consumer
> with something like
> 
> -	else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK)
> +	else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK ||
> +		 s->ahead_behind_flags == AHEAD_BEHIND_QUICK_DIFFERENTLY)
> 
> when it happens.
> 
> Two related tangents.
> 
>   - I do not see why "eq" need to exist at all.  Even in _QUICK mode,
>     when you determine that two are identical, you know your branch
>     is ahead and behind by 0 commit each.
> 
>   - A short-format that is easy to parse by machines does not have to
>     be cryptic to humans.  s/neq/not-equal/ or something may be an
>     improvement.
> 
> Thanks.
> 

Thanks for the review. Let me update it along the lines suggested here. It felt odd to define the nr_{ahead,behind} as undefined, but short of making them negative or something I wasn't sure what was best.

Thanks, Jeff

Previous: Junio C HamanoNext: Jeff Hostetler
Message 8 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.