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

Re: [PATCH 1/3] diff_tree_sha1(): avoid rereading trees if possible

From
Junio C Hamano <junkio@cox.net>
Date
Dec 10, 2006, 01:47 UTC
Message-ID
<7vvekk5xpc.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0612100055160.28348@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> If the tree has already been read, no need to read it into memory
> again.
Hmm...
> This also helps when this function is called on temporary trees;
> these no longer have to be written to disk.

To generate tree-diff, probably yes, but I am not sure that allows you to use hash_sha1_file() everywhere in merge_recursive instead of write_sha1_file(), if that is what you are getting at.

Show 19 quoted lines
> +static int get_tree_desc_from_sha1(const unsigned char *sha1,
> +		struct tree_desc *t)
> +{
> +	struct object *o;
> +
> +	o = lookup_object(sha1);
> +	if (o && o->type == OBJ_TREE && o->parsed) {
> +		struct tree *tree = (struct tree *)o;
> +		t->size = tree->size;
> +		t->buf = xmalloc(t->size);
> +		memcpy(t->buf, tree->buffer, t->size);
> +	} else {
> +		t->buf = read_object_with_reference(sha1,
> +				tree_type, &t->size, NULL);
> +		if (!t->buf)
> +			die("unable to read source tree (%s)",
> +					sha1_to_hex(sha1));
> +	}
> +}

Are you absolutely sure that all users of "struct tree" retains the tree->buffer for a parsed tree? If nobody does "free(tree->buffer)" without "tree->buffer = NULL", then the situation is still salvageable (you need a bit more code above), though.

I think this is overkill that only helps a very narrow "empty tree" special case that [PATCH 2/3] addresses, and can be easily and incorrectly abused. We do not want people to expect that reading many trees from different revisions as "struct tree" objects and keeping all of them in memory would magically speed up diff-tree, for example.

I'd prefer write_sha1_file() approach in Shawn's patch for its simplicity at least for now.

I suspect gitlink/subproject people might want to modify in-core representation of a tree to graft in subproject directory somewhere in the superproject, just like the history traversal code modifies in-core representation of a commit to simplify parents. Your approach might turn out to be the right thing to for that application --- populate tree objects in the in-core obj_hash[], muck with its entries and then have everybody else go through get_tree_desc_from_sha1() interface to pretend as if the superproject has everything contained in the subproject tree. I dunno.

Previous: Johannes SchindelinNext: Johannes Schindelin
Message 3 of 37 in “Make sure the empty tree exists when needed in merge-recursive.”
  1. 1/1 Make sure the empty tree exists when needed in merge-recursive.Shawn O. Pearce, Dec 7, 2006
  2. 1/3 diff_tree_sha1(): avoid rereading trees if possibleJohannes Schindelin, Dec 9, 2006
  3. Junio C HamanoDec 10, 2006
  4. Johannes SchindelinDec 10, 2006
  5. 2/3 merge-recursive: make empty tree a known objectJohannes Schindelin, Dec 9, 2006
  6. Linus TorvaldsDec 10, 2006
  7. Junio C HamanoDec 10, 2006
  8. Linus TorvaldsDec 10, 2006
  9. Junio C HamanoDec 10, 2006
  10. Linus TorvaldsDec 10, 2006
  11. Junio C HamanoDec 10, 2006
  12. Johannes SchindelinDec 10, 2006
  13. 3/3 add test case for recursive mergeJohannes Schindelin, Dec 9, 2006
  14. Johannes SchindelinDec 10, 2006
  15. Junio C HamanoDec 10, 2006
  16. Johannes SchindelinDec 10, 2006
  17. t6024: fix timing problemJohannes Schindelin, Dec 12, 2006
  18. Junio C HamanoDec 12, 2006
  19. Johannes SchindelinDec 12, 2006
  20. merge-recursive: add/add really is modify/modify with an empty baseJohannes Schindelin, Dec 13, 2006
  21. Junio C HamanoDec 13, 2006
  22. StGit repo & gitweb, was Re: [PATCH] merge-recursive: add/add really is modify/modify with an empty baseJohannes Schindelin, Dec 13, 2006
  23. Jakub NarebskiDec 13, 2006
  24. Catalin MarinasDec 13, 2006
  25. Robin RosenbergDec 13, 2006
  26. Johannes SchindelinDec 13, 2006
  27. Jakub NarebskiDec 13, 2006
  28. Petr BaudisDec 19, 2006
  29. Jakub NarebskiDec 19, 2006
  30. Catalin MarinasDec 13, 2006
  31. Junio C HamanoDec 13, 2006
  32. Johannes SchindelinDec 13, 2006
  33. Catalin MarinasDec 14, 2006
  34. Shawn PearceDec 14, 2006
  35. Shawn PearceDec 14, 2006
  36. Johannes SchindelinDec 14, 2006
  37. Catalin MarinasDec 14, 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.