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

Re: [PATCH 2/2] fast-import: teach ls command to accept empty path

From
David Barr <davidbarr@google.com>
Date
Mar 9, 2012, 04:28 UTC
Message-ID
<CAFfmPPNnQ21qwKb_w1FCRL7Vx7CSQKYurM2zqziTw01kkRoMog@mail.gmail.com>
In-Reply-To
<20120308203330.GC8992@burratino>
On Fri, Mar 9, 2012 at 7:33 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 37 quoted lines
> From: David Barr <davidbarr@google.com>
>
> There is a pathological Subversion operation that svn-fe handles
> incorrectly due to an unexpected response from fast-import:
>
>  svn cp $SVN_ROOT $SVN_ROOT/subdirectory
>
> When the following command is sent to fast-import:
>
>  'ls' SP ':1' SP LF
>
> The expected output is:
>
>  '040000' SP 'tree' SP <dataref> HT LF
>
> The actual output is:
>
>  'missing' SP LF
>
> This is because tree_content_get() is called but expects a non-empty
> path. Instead, copy the root entry.
>
> [jn: using a deep copy; w/ more tests]
> [jn: with a fix from Dmitry to fully initialize root->versions[0]
>  and versions[1] now that root can be passed to store_tree]
>
> Reported-by: Andrew Sayers <andrew-git@pileofstuff.org>
> Signed-off-by: David Barr <davidbarr@google.com>
> Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> +               /*
> +                * store_tree scribbles over version[0] in leaf.tree's
> +                * entries, so we need a deep copy.
> +                */
> +               if (root->tree && is_null_sha1(root->versions[1].sha1))
> +                       leaf.tree = dup_tree_content(root->tree);

Is it ok to call store_tree(root)? If so, could we not introduce a pointer rather than a deep copy?

diff --git a/fast-import.c b/fast-import.c
index 94d7037..eab24f3 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2993,7 +2993,8 @@ static void parse_ls(struct branch *b)
 {
 	const char *p;
 	struct tree_entry *root = NULL;
-	struct tree_entry leaf = {NULL};
+	struct tree_entry tmp_tree = {NULL};
+	struct tree_entry *leaf = &tmp_tree;

 	/* ls SP (<treeish> SP)? <path> */
 	p = command_buf.buf + strlen("ls ");
@@ -3022,27 +3023,18 @@ static void parse_ls(struct branch *b)
 			die("Garbage after path in: %s", command_buf.buf);
 		p = uq.buf;
 	}
-	if (*p) {
-		tree_content_get(root, p, &leaf);
-	} else {
-		memcpy(&leaf, root, sizeof(leaf));
-		/*
-		 * store_tree scribbles over version[0] in leaf.tree's
-		 * entries, so we need a deep copy.
-		 */
-		if (root->tree && is_null_sha1(root->versions[1].sha1))
-			leaf.tree = dup_tree_content(root->tree);
-		else
-			leaf.tree = NULL;
-	}
+	if (*p)
+		tree_content_get(root, p, leaf);
+	else
+		leaf = root;
 	/*
 	 * A directory in preparation would have a sha1 of zero
 	 * until it is saved.  Save, for simplicity.
 	 */
-	if (S_ISDIR(leaf.versions[1].mode))
-		store_tree(&leaf);
+	if (S_ISDIR(leaf->versions[1].mode))
+		store_tree(leaf);

-	print_ls(leaf.versions[1].mode, leaf.versions[1].sha1, p);
+	print_ls(leaf->versions[1].mode, leaf->versions[1].sha1, p);
 	if (!b || root != &b->branch_tree)
 		release_tree_entry(root);
 }

--
David Barr
Previous: Jonathan NiederNext: Jonathan Nieder
Message 19 of 23 in “[BUG] fast-import: ls command on commit root returns missing (was: Bug in svn-fe: copying the root directory acts as if it's an empty directory)”
  1. David BarrMar 8, 2012
  2. fast-import: fix ls command with empty pathDavid Barr, Mar 8, 2012
  3. Jonathan NiederMar 8, 2012
  4. Sverre RabbelierMar 8, 2012
  5. Junio C HamanoMar 8, 2012
  6. Dmitry IvankovMar 8, 2012
  7. Jonathan NiederMar 8, 2012
  8. Jonathan NiederMar 10, 2012
  9. Jonathan NiederMar 8, 2012
  10. Jonathan NiederMar 10, 2012
  11. fast-import: leakfix for 'ls' of dirty treesJonathan Nieder, Mar 10, 2012
  12. fast-import: don't allow 'ls' of path with empty componentsJonathan Nieder, Mar 10, 2012
  13. [PULL maint] two fast-import "ls" fixesJonathan Nieder, Mar 10, 2012
  14. vcs-svn: avoid 'ls' and filedelete with empty pathJonathan Nieder, Mar 10, 2012
  15. Dave AbrahamsJun 21, 2013
  16. 0/2 Re: fast-import: fix ls command with empty pathJonathan Nieder, Mar 8, 2012
  17. 1/2 fast-import: plug leak of dirty trees in 'ls' commandJonathan Nieder, Mar 8, 2012
  18. 2/2 fast-import: teach ls command to accept empty pathJonathan Nieder, Mar 8, 2012
  19. David BarrMar 9, 2012
  20. Jonathan NiederMar 9, 2012
  21. fast-import: allow 'ls' and filecopy to read the rootJonathan Nieder, Mar 10, 2012
  22. Jonathan NiederMar 10, 2012
  23. 2/1 fixup! fast-import: allow 'ls' and filecopy to read the rootJonathan Nieder, Mar 10, 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.