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

Re: git status: small difference between stating whole repository and small subdirectory

From
Jeff King <peff@peff.net>
Date
Feb 20, 2012, 20:09 UTC
Message-ID
<20120220200902.GA5314@sigill.intra.peff.net>
In-Reply-To
<7vr4xpl1nm.fsf@alter.siamese.dyndns.org>
On Mon, Feb 20, 2012 at 11:56:13AM -0800, Junio C Hamano wrote:
Show 5 quoted lines
> These days, we have src_index and dst_index, and dst_index IIRC can start
> as empty in which case "start from kept information and selectively
> invalidate" would not work at all.  When src_index and dst_index are the
> same, however, you should be able to keep the cached tree valid, at least
> in theory.

Yeah, I was worried that the cache invalidations sprinkled throughout unpack-trees.c would not be sufficient (and because we are invalidating, a missing invalidation would give us bogus cache info, which is Very Bad).

So I think the one-liner I posted before is not sufficient in the general case, because it definitely doesn't consider where the destination is starting from. It should at least be more like:

  if (src_index == dst_index) {
          /* We would ordinarily want to do a deep copy here, but since
           * we know that we will be overwriting src_index in the long
           * run, it's OK to just take ownership of its cache_tree. */
          o->result.cache_tree = o->src_index->cache_tree;
          o->src_index->cache_tree = NULL;
  }
  [... do the usual tree traversal here, except invalidate entries in
       o->result.call_tree instead of o->src_index. That makes it a
       no-op when src_index != dst_index (because we have no cache tree
       defined in result, then), and otherwise we are invalidating what
       will go into the result...]
  [then as before, we copy the result to dst_index; except now the
   result may have src_index's cache_tree plus any invalidations]
  o->result = *o->dst_index;

And fortunately that does exactly what we want in all cases, because we always either read from and write to the_index, or we write to NULL (in which case we will not bother with a cache_tree for the result, and it is fixing a minor bug that we might be invalidating src_index's tree in the first place).

I'm still slightly worried that we are missing some invalidation somewhere deep in unpack_tree's callbacks (especially because they _are_ callbacks, and invalidating the cache_tree properly is now a promise that the callbacks have to make).

-Peff
Previous: Junio C Hamano
Message 52 of 52 in “git status: small difference between stating whole repository and small subdirectory”
  1. Piotr KrukowieckiFeb 10, 2012
  2. Nguyen Thai Ngoc DuyFeb 10, 2012
  3. Piotr KrukowieckiFeb 10, 2012
  4. Nguyen Thai Ngoc DuyFeb 10, 2012
  5. Piotr KrukowieckiFeb 13, 2012
  6. Piotr KrukowieckiFeb 10, 2012
  7. Thomas RastFeb 14, 2012
  8. Piotr KrukowieckiFeb 15, 2012
  9. Nguyen Thai Ngoc DuyFeb 15, 2012
  10. Piotr KrukowieckiFeb 15, 2012
  11. Piotr KrukowieckiFeb 16, 2012
  12. Jeff KingFeb 15, 2012
  13. Piotr KrukowieckiFeb 16, 2012
  14. Thomas RastFeb 16, 2012
  15. Junio C HamanoFeb 16, 2012
  16. Piotr KrukowieckiFeb 17, 2012
  17. Jeff KingFeb 16, 2012
  18. Piotr KrukowieckiFeb 17, 2012
  19. Jeff KingFeb 17, 2012
  20. Junio C HamanoFeb 17, 2012
  21. Jeff KingFeb 17, 2012
  22. Piotr KrukowieckiFeb 20, 2012
  23. Jeff KingFeb 20, 2012
  24. Thomas RastFeb 20, 2012
  25. Nguyen Thai Ngoc DuyFeb 20, 2012
  26. Jeff KingFeb 20, 2012
  27. Jeff KingFeb 20, 2012
  28. Thomas RastFeb 20, 2012
  29. Jeff KingFeb 20, 2012
  30. Junio C HamanoFeb 20, 2012
  31. Jeff KingFeb 20, 2012
  32. Junio C HamanoFeb 20, 2012
  33. Piotr KrukowieckiFeb 21, 2012
  34. Junio C HamanoFeb 20, 2012
  35. Jeff KingFeb 20, 2012
  36. Nguyen Thai Ngoc DuyFeb 21, 2012
  37. Junio C HamanoFeb 21, 2012
  38. Nguyen Thai Ngoc DuyFeb 22, 2012
  39. Junio C HamanoFeb 22, 2012
  40. Nguyen Thai Ngoc DuyFeb 22, 2012
  41. Thomas RastFeb 22, 2012
  42. Nguyen Thai Ngoc DuyFeb 22, 2012
  43. Junio C HamanoFeb 22, 2012
  44. Piotr KrukowieckiApr 10, 2012
  45. Junio C HamanoApr 10, 2012
  46. Jeff KingApr 10, 2012
  47. Junio C HamanoFeb 20, 2012
  48. Thomas RastFeb 20, 2012
  49. Nguyen Thai Ngoc DuyFeb 20, 2012
  50. Jeff KingFeb 20, 2012
  51. Junio C HamanoFeb 20, 2012
  52. Jeff KingFeb 20, 2012

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.