From: David Barr <davidbarr@google.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>,
Andrew Sayers <andrew-git@pileofstuff.org>,
Dmitry Ivankov <divanorama@gmail.com>,
Sverre Rabbelier <srabbelier@gmail.com>
Subject: Re: [PATCH 2/2] fast-import: teach ls command to accept empty path
Date: Fri, 9 Mar 2012 15:28:02 +1100 [thread overview]
Message-ID: <CAFfmPPNnQ21qwKb_w1FCRL7Vx7CSQKYurM2zqziTw01kkRoMog@mail.gmail.com> (raw)
In-Reply-To: <20120308203330.GC8992@burratino>
On Fri, Mar 9, 2012 at 7:33 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> 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
next prev parent reply other threads:[~2012-03-09 4:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 3:13 [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) David Barr
2012-03-08 5:30 ` [PATCH] fast-import: fix ls command with empty path David Barr
2012-03-08 7:09 ` Jonathan Nieder
2012-03-08 15:29 ` Sverre Rabbelier
2012-03-08 16:39 ` Junio C Hamano
2012-03-08 17:33 ` Dmitry Ivankov
2012-03-08 19:32 ` Jonathan Nieder
2012-03-10 9:48 ` Jonathan Nieder
2012-03-08 18:15 ` Jonathan Nieder
2012-03-10 3:12 ` Jonathan Nieder
2012-03-10 3:20 ` [PATCH maint-1.7.6] fast-import: leakfix for 'ls' of dirty trees Jonathan Nieder
2012-03-10 4:00 ` [PATCH maint-1.7.6] fast-import: don't allow 'ls' of path with empty components Jonathan Nieder
2012-03-10 4:30 ` [PULL maint] two fast-import "ls" fixes Jonathan Nieder
2012-03-10 7:00 ` [NON-PATCH] vcs-svn: avoid 'ls' and filedelete with empty path Jonathan Nieder
2013-06-21 16:33 ` [PATCH] fast-import: fix ls command " Dave Abrahams
2012-03-08 20:27 ` [PATCH v2 0/2] " Jonathan Nieder
2012-03-08 20:31 ` [PATCH 1/2] fast-import: plug leak of dirty trees in 'ls' command Jonathan Nieder
2012-03-08 20:33 ` [PATCH 2/2] fast-import: teach ls command to accept empty path Jonathan Nieder
2012-03-09 4:28 ` David Barr [this message]
2012-03-09 9:29 ` Jonathan Nieder
2012-03-10 8:53 ` [PATCH v3] fast-import: allow 'ls' and filecopy to read the root Jonathan Nieder
2012-03-10 9:01 ` Jonathan Nieder
2012-03-10 9:18 ` [PATCH 2/1] fixup! " Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFfmPPNnQ21qwKb_w1FCRL7Vx7CSQKYurM2zqziTw01kkRoMog@mail.gmail.com \
--to=davidbarr@google.com \
--cc=andrew-git@pileofstuff.org \
--cc=divanorama@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=srabbelier@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).