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

Re: [PATCH v2 3/4] status: show more info than "currently not on any branch"

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 8, 2013, 11:04 UTC
Message-ID
<CACsJy8CnDoMRzR5ifH3+0AKRLfzrNpkc3-NOxoA85SiRUb40ng@mail.gmail.com>
In-Reply-To
<7vzjygpcd5.fsf@alter.siamese.dyndns.org>
On Thu, Mar 7, 2013 at 2:16 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 29 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> +static void wt_status_get_detached_from(struct wt_status_state *state)
>> +{
>> +     struct grab_1st_switch_cbdata cb;
>> +     struct commit *commit;
>> +     unsigned char sha1[20];
>> +     char *ref = NULL;
>> +
>> +     strbuf_init(&cb.buf, 0);
>> +     if (for_each_recent_reflog_ent("HEAD", grab_1st_switch, 4096, &cb))
>> +             for_each_reflog_ent("HEAD", grab_1st_switch, &cb);
>> +     if (!cb.buf.len)
>> +             return;
>
> Is this correct?  What if the recent entries (i.e. the tail 4k) of
> the HEAD reflog did not have *any* checkout?  Your callback never
> returns non-zero, so as long as the HEAD reflog is sufficiently
> long, for_each_recent_reflog_ent() will return 0 to signal success,
> and you do not dig deeper by retrying the full reflog for HEAD,
> missing the checkout that exists before the final 4k, no?
>
> It should be more like this, I would think:
>
>         for_each_recent_reflog_ent();
>         if (!found)
>                 for_each_reflog_ent();
>         if (!found)
>                 return;
Yes. This "recent" optimization is tricky.
> Using cb.buf.len as the "found" marker may be correct, but I found
> it a bit subtle to my taste, without explanation.  Adding an
> explicit bit to "struct grab_1st_switch_cbdata" would be cleaner and
> more resistant to future changes, I think.
OK
Show 13 quoted lines
>
>> +
>> +     if (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 &&
>> +         (commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
>> +         !hashcmp(cb.nsha1, commit->object.sha1)) {
>
> That feels unnecessarily expensive.  Why not hashcmp before checking
> the type of the object to reject the case where the ref moved since
> the last checkout early?
>
> For that matter, does this even need to check the type of the object
> that currently sits at the ref?  Isn't it sufficient to reject this
> case by seeing if sha1 is the same as cb.nsha1?

nsha1 is always a commit sha-1, sha-1 could be a tag sha-1 that refers to the same commit. hashcmp before lookup is a good idea. Although I don't think it's expensive in the big picture. When HEAD is not detached, we show "<n> commits ahead of @{u}" which is way more expensive than this. As long as "git status" on detached HEAD does not use up all the time that "git status" on branches normally does, I think we're fine.

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 20 of 38 in “nd/branch-show-rebase-bisect-state updates”
  1. 0/5 nd/branch-show-rebase-bisect-state updatesNguyễn Thái Ngọc Duy, Mar 3, 2013
  2. 1/5 checkout: record full target ref in reflogNguyễn Thái Ngọc Duy, Mar 3, 2013
  3. 2/5 wt-status: split wt_status_state parsing function outNguyễn Thái Ngọc Duy, Mar 3, 2013
  4. 3/5 wt-status: move wt_status_get_state() out to wt_status_print()Nguyễn Thái Ngọc Duy, Mar 3, 2013
  5. 4/5 status: show the ref that is checked out, even if it's detachedNguyễn Thái Ngọc Duy, Mar 3, 2013
  6. Junio C HamanoMar 3, 2013
  7. Duy NguyenMar 4, 2013
  8. Junio C HamanoMar 4, 2013
  9. Duy NguyenMar 5, 2013
  10. Matthieu MoyMar 5, 2013
  11. 5/5 branch: show more information when HEAD is detachedNguyễn Thái Ngọc Duy, Mar 3, 2013
  12. Junio C HamanoMar 3, 2013
  13. 0/4 nd/branch-show-rebase-bisect-state updatesNguyễn Thái Ngọc Duy, Mar 6, 2013
  14. 1/4 wt-status: split wt_status_state parsing function outNguyễn Thái Ngọc Duy, Mar 6, 2013
  15. Junio C HamanoMar 6, 2013
  16. Junio C HamanoMar 6, 2013
  17. 2/4 wt-status: move wt_status_get_state() out to wt_status_print()Nguyễn Thái Ngọc Duy, Mar 6, 2013
  18. 3/4 status: show more info than "currently not on any branch"Nguyễn Thái Ngọc Duy, Mar 6, 2013
  19. Junio C HamanoMar 6, 2013
  20. Duy NguyenMar 8, 2013
  21. Junio C HamanoMar 8, 2013
  22. 4/4 branch: show more information when HEAD is detachedNguyễn Thái Ngọc Duy, Mar 6, 2013
  23. 0/4 nd/branch-show-rebase-bisect-state updatesNguyễn Thái Ngọc Duy, Mar 6, 2013
  24. 4/4 branch: show more information when HEAD is detachedNguyễn Thái Ngọc Duy, Mar 6, 2013
  25. 0/5 nd/branch-show-rebase-bisect-state updatesNguyễn Thái Ngọc Duy, Mar 13, 2013
  26. 1/5 wt-status: move strbuf into read_and_strip_branch()Nguyễn Thái Ngọc Duy, Mar 13, 2013
  27. Junio C HamanoMar 13, 2013
  28. 1/5 wt-status: move strbuf into read_and_strip_branch()Nguyễn Thái Ngọc Duy, Mar 16, 2013
  29. 2/5 wt-status: split wt_status_state parsing function outNguyễn Thái Ngọc Duy, Mar 13, 2013
  30. 3/5 wt-status: move wt_status_get_state() out to wt_status_print()Nguyễn Thái Ngọc Duy, Mar 13, 2013
  31. 4/5 status: show more info than "currently not on any branch"Nguyễn Thái Ngọc Duy, Mar 13, 2013
  32. Junio C HamanoMar 13, 2013
  33. 5/5 branch: show more information when HEAD is detachedNguyễn Thái Ngọc Duy, Mar 13, 2013
  34. Junio C HamanoMar 19, 2013
  35. Duy NguyenMar 20, 2013
  36. Junio C HamanoMar 20, 2013
  37. status, branch: fix the misleading "bisecting" messageNguyễn Thái Ngọc Duy, Mar 23, 2013
  38. Junio C HamanoMar 24, 2013

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.