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

[PATCH 1/2] fast-import: be saner with temporary trees

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Aug 16, 2011, 10:08 UTC
Message-ID
<1313489337-2523-2-git-send-email-divanorama@gmail.com>
In-Reply-To
<1313489337-2523-1-git-send-email-divanorama@gmail.com>

new_tree_entry/release_tree_entry manage a stack of tree_entry structs to use as temporaries. Initializing them is the responsibility of the caller, both after allocation with xmalloc() when existing temporaries are exhausted and after used entries are pushed with release_tree_entry.

parse_ls doesn't set root->versions[0] fields, making root an invalid entry. The problem could arise if store_tree(root) is called. parse_ls calls store_tree on the node corresponding to the path it is called on.

Do initialize entry->versions[0]. As of now, ls command can not list the topmost tree so this change is just to avoid surprises in case things will change around ls or tree_content_get.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
Acked-by: Jonathan Nieder <jrnieder@gmail.com>
---
 fast-import.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 7cc2262..3a0aaad 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2951,6 +2951,9 @@ static void parse_ls(struct branch *b)
 	} else {
 		struct object_entry *e = parse_treeish_dataref(&p);
 		root = new_tree_entry();
+		hashclr(root->versions[0].sha1);
+		root->versions[0].mode = 0;
+		root->versions[1].mode = S_IFDIR;
 		hashcpy(root->versions[1].sha1, e->idx.sha1);
 		load_tree(root);
 		if (*p++ != ' ')
-- 
1.7.3.4
Previous: Dmitry IvankovNext: Jonathan Nieder
Message 2 of 4 in “fast-import: allow more operations on root directory”
  1. 0/2 fast-import: allow more operations on root directoryDmitry Ivankov, Aug 16, 2011
  2. 1/2 fast-import: be saner with temporary treesDmitry Ivankov, Aug 16, 2011
  3. Jonathan NiederMar 8, 2012
  4. 2/2 fast-import: allow top directory as an argument for some commandsDmitry Ivankov, Aug 16, 2011

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.