two fixes for fast-import's "ls" command

Andrew Sayers noticed that the svn-fe | git fast-import pipeline
 mishandles a subversion history that copies the root directory to a
 sub-directory (e.g. doing `svn cp . trunk` to standardise your
 layout).  As David Barr explained, the bug arises when the following
 command is sent to git fast-import:
 
   'ls' SP ':1' SP LF
 
 Instead of reading back what is at the root of r1, it unconditionally
 reports the path as missing.
 
 After sleeping on it, here are two patches for 'maint'.  One plugs a
 memory leak.  The other ensures that trying to pass an empty path to
 the 'ls' command results in an error message that can help the
 frontend author instead of the silently broken conversion Andrew
 found.
 
 Then we can carefully add 'ls ""' support in 1.7.11.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIbBAABCAAGBQJPWtgPAAoJEN/Gce6zM/olpU4P92DnurNCuUOsCIOVvEHT7YC+
 JdBou7wDKug2U0XH4yvTCglJZQ+zWpoobPoJlGu4c+RPWYGoUnOvc2jUmhFGD2r4
 jLlNhq3Uob4CSdEA8JLz8IOvgW41kc2LuUsZrr19dC3eS/19U72NQpD5nA958wZw
 xmvcu1DjhrsYHSdh4azg0Ccsp3PzesssCGJSckKoYpOZSlbznK3Dyn2KnLPZvAmx
 fF6uyPAZXKsKDOyVUPczIQ+mitb5YhOa3eFDcZk/EBM1LUCqbE0qmFyPhFqtE2pP
 f0BcG2MwXc6S8FIRTSkzxV3WP8Cl5+3Y3LX+aB9Y5Zl7Vx1LBdDEhEZS0DkJFW1u
 c/64Ge89FD/mSKpJfu8iZdga+qalyF1u5fPPFvOKV3p6UO1ou1RuIVEDMUhMzPhi
 244i7VnaPq232aMr8Jn4eAnpg+mZpOdDuqsJn4Q/BOpJ2D5UmKzja4LUZk2tkmgh
 EzGYLbs//TZXKjeNGH1rBdbW9lO0fU8oGRaTKiRwWTQVAJ48hUlOYfMBsWvUnvI6
 A5ar/iT8UthEc54OZIkBefjpFrwIXl3wG1iafDY8Z1rcnGsbH9MpNFLFxcoGQTBJ
 9A6ZyqL7dEKg2SWfESXf93xkF/fFZYl+0jFm+VNuJUzkrsvoi4tkxs/3qxaE74Kb
 zQtYbp/z+KWFh4eg830=
 =wrup
 -----END PGP SIGNATURE-----

Merge "two fixes for fast-import's 'ls' command" from Jonathan

Andrew Sayers noticed that the svn-fe | git fast-import pipeline
mishandles a subversion history that copies the root directory to a
sub-directory (e.g. doing `svn cp . trunk` to standardise your
layout).  As David Barr explained, the bug arises when the following
command is sent to git fast-import:

  'ls' SP ':1' SP LF

Instead of reading back what is at the root of r1, it unconditionally
reports the path as missing.

After sleeping on it, here are two patches for 'maint'.  One plugs a
memory leak.  The other ensures that trying to pass an empty path to
the 'ls' command results in an error message that can help the
frontend author instead of the silently broken conversion Andrew
found.

Then we can carefully add 'ls ""' support in 1.7.11.

* commit 'refs/pull-request-tags/jn/maint-fast-import-empty-ls':
  fast-import: don't allow 'ls' of path with empty components
  fast-import: leakfix for 'ls' of dirty trees
This commit is contained in:
Junio C Hamano 2012-03-16 08:19:18 -07:00
commit 5087aace2d
2 changed files with 43 additions and 0 deletions

View file

@ -1641,6 +1641,8 @@ static int tree_content_get(
n = slash1 - p;
else
n = strlen(p);
if (!n)
die("Empty path component found in input");
if (!root->tree)
load_tree(root);
@ -3028,6 +3030,8 @@ static void parse_ls(struct branch *b)
store_tree(&leaf);
print_ls(leaf.versions[1].mode, leaf.versions[1].sha1, p);
if (leaf.tree)
release_tree_content_recursive(leaf.tree);
if (!b || root != &b->branch_tree)
release_tree_entry(root);
}

View file

@ -1306,6 +1306,45 @@ test_expect_success \
M 040000 $subdir file3/
INPUT_END'
test_expect_success \
'N: reject foo/ syntax in copy source' \
'test_must_fail git fast-import <<-INPUT_END
commit refs/heads/N5C
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
data <<COMMIT
copy with invalid syntax
COMMIT
from refs/heads/branch^0
C file2/ file3
INPUT_END'
test_expect_success \
'N: reject foo/ syntax in rename source' \
'test_must_fail git fast-import <<-INPUT_END
commit refs/heads/N5D
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
data <<COMMIT
rename with invalid syntax
COMMIT
from refs/heads/branch^0
R file2/ file3
INPUT_END'
test_expect_success \
'N: reject foo/ syntax in ls argument' \
'test_must_fail git fast-import <<-INPUT_END
commit refs/heads/N5E
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
data <<COMMIT
copy with invalid syntax
COMMIT
from refs/heads/branch^0
ls "file2/"
INPUT_END'
test_expect_success \
'N: copy to root by id and modify' \
'echo "hello, world" >expect.foo &&