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

Re: [PATCH] refs: allow @{n} to work with n-sized reflog

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 6, 2021, 21:02 UTC
Message-ID
<xmqqft3drd82.fsf@gitster.c.googlers.com>
In-Reply-To
<X/V0DU+CD6mS36dK@generichostname>
Denton Liu <liu.denton@gmail.com> writes:
Show 14 quoted lines
>> > -	if (timestamp <= cb->at_time || cb->cnt == 0) {
>> > +	if (cb->cnt > 0)
>> > +		cb->cnt--;
>> > +	at_indexed_ent = cb->cnt == 0 && !is_null_oid(ooid);
>> 
>> The code treats two cases identically (i.e. the case where cb->cnt
>> was originally zero, and one).  Is that intended?
>
> It shouldn't be possible for cb->cnt == 0 on the first iteration
> because there's a special-case check at [0]. As a result, it can only be
> -1 or >= 1 on the first iteration.
>
> The -1 case happens when we're doing date-based lookup and that's what
> this if is intended to handle.

I knew about -1; it wasn't apparent that the caller won't call us with cnt==0. Perhaps it deserves a mention in an in-code comment.

> "at_indexed_ent" is meant to signal when we are indexing the reflog
> numerically (as opposed to by date), we have arrived at the correct
> entry. If you have a more fitting name, I'm open to suggestions.

When querying for <ref>@{24}, all the entries are indexed numerically (counted), not just the 24th one, and that contributed to my puzzlement.

I offhand do not think of a "name", but "at target", "found", "reached count", are phrases that come to my mind as starting points.

Thanks.
Previous: Denton LiuNext: Denton Liu
Message 7 of 21 in “refs: allow @{n} to work with n-sized reflog”
  1. refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 2, 2021
  2. Martin ÅgrenJan 2, 2021
  3. Denton LiuJan 3, 2021
  4. SZEDER GáborJan 5, 2021
  5. Junio C HamanoJan 6, 2021
  6. Denton LiuJan 6, 2021
  7. Junio C HamanoJan 6, 2021
  8. 0/2 refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 6, 2021
  9. 1/2 refs: factor out set_read_ref_cutoffs()Denton Liu, Jan 6, 2021
  10. 2/2 refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 6, 2021
  11. SZEDER GáborJan 6, 2021
  12. 0/2 refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 7, 2021
  13. 1/2 refs: factor out set_read_ref_cutoffs()Denton Liu, Jan 7, 2021
  14. 2/2 refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 7, 2021
  15. Simon RuderichJan 10, 2021
  16. fixup! refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 12, 2021
  17. Denton LiuJan 12, 2021
  18. Junio C HamanoJan 12, 2021
  19. SZEDER GáborJan 10, 2021
  20. Junio C HamanoJan 10, 2021
  21. 3/2 fixup! refs: allow @{n} to work with n-sized reflogDenton Liu, Jan 7, 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.