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

Re: Adding a new file as if it had existed

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 13, 2006, 15:46 UTC
Message-ID
<Pine.LNX.4.63.0612131611050.3635@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<457FCA8C.6000300@op5.se>
Hi,
On Wed, 13 Dec 2006, Andreas Ericsson wrote:
Show 22 quoted lines
> Junio C Hamano wrote:
> > "Bahadir Balban" <bahadir.balban@gmail.com> writes:
> > 
> > There is one thing we could further optimize, though.
> > 
> > Switching branches with 100k blobs in a commit even when there
> > are a handful paths different between the branches would still
> > need to populate the index by reading two trees and collapsing
> > them into a single stage.  In theory, we should be able to do a
> > lot better if two-tree case of read-tree took advanrage of
> > cache-tree information.  If ce_match_stat() says Ok for all
> > paths in a subdirectory and the cached tree object name for that
> > subdirectory in the index match what we are reading from the new
> > tree, we should be able to skip reading that subdirectory (and
> > its subdirectories) from the new tree object at all.
> > 
> > Anybody interested to give it a try?
> > 
> 
> I'm not vell-versed enough in git internals to have my hopes high of 
> making something useful of it, but if you give me a pointer of where to 
> start I'd be happy to try, and perhaps learn something in the process.
Okay, I'll have a stab at explaining it.

For huge working directories, you usually have a huge number of trees. The idea of cache_tree is to remember not only the stat information of the blobs in the index, but to cache the hashes of the trees also (until they are invalidated, e.g. by an update-index). This avoids recalculation of the hashes when committing.

This cache is accessible by the global variable active_cache_tree. It is best accessed by the function cache_tree_find(), which you call like that:

	struct cache_tree *ct = cache_tree_find(active_cache_tree, path);

where the variable "path" may contain slashes. The SHA1 of the corresponding tree is in ct->sha1, and you can check if the hash is still valid by asking

	if (cache_tree_fully_valid(ct))
		/* still valid */

AFAIU Junio would like to take the shortcut of doing nothing at all when (twoway) reading a tree whose hash is identical to the hash stored in the corresponding cache_tree _and_ when the cache is still fully valid.

Ciao, Dscho

Previous: Andreas EricssonNext: Andreas Ericsson
Message 9 of 11 in “Adding a new file as if it had existed”
  1. Bahadir BalbanDec 12, 2006
  2. Junio C HamanoDec 12, 2006
  3. Bahadir BalbanDec 12, 2006
  4. Johannes SchindelinDec 12, 2006
  5. Andy ParkinsDec 12, 2006
  6. Andreas EricssonDec 12, 2006
  7. Junio C HamanoDec 12, 2006
  8. Andreas EricssonDec 13, 2006
  9. Johannes SchindelinDec 13, 2006
  10. Andreas EricssonDec 13, 2006
  11. Jakub NarebskiDec 12, 2006

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.