Skip to content

Commit 5087aac

Browse files
committed
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
2 parents a99c5e5 + 178e1de commit 5087aac

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

fast-import.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,8 @@ static int tree_content_get(
16411641
n = slash1 - p;
16421642
else
16431643
n = strlen(p);
1644+
if (!n)
1645+
die("Empty path component found in input");
16441646

16451647
if (!root->tree)
16461648
load_tree(root);
@@ -3028,6 +3030,8 @@ static void parse_ls(struct branch *b)
30283030
store_tree(&leaf);
30293031

30303032
print_ls(leaf.versions[1].mode, leaf.versions[1].sha1, p);
3033+
if (leaf.tree)
3034+
release_tree_content_recursive(leaf.tree);
30313035
if (!b || root != &b->branch_tree)
30323036
release_tree_entry(root);
30333037
}

t/t9300-fast-import.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,45 @@ test_expect_success \
13061306
M 040000 $subdir file3/
13071307
INPUT_END'
13081308

1309+
test_expect_success \
1310+
'N: reject foo/ syntax in copy source' \
1311+
'test_must_fail git fast-import <<-INPUT_END
1312+
commit refs/heads/N5C
1313+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1314+
data <<COMMIT
1315+
copy with invalid syntax
1316+
COMMIT
1317+
1318+
from refs/heads/branch^0
1319+
C file2/ file3
1320+
INPUT_END'
1321+
1322+
test_expect_success \
1323+
'N: reject foo/ syntax in rename source' \
1324+
'test_must_fail git fast-import <<-INPUT_END
1325+
commit refs/heads/N5D
1326+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1327+
data <<COMMIT
1328+
rename with invalid syntax
1329+
COMMIT
1330+
1331+
from refs/heads/branch^0
1332+
R file2/ file3
1333+
INPUT_END'
1334+
1335+
test_expect_success \
1336+
'N: reject foo/ syntax in ls argument' \
1337+
'test_must_fail git fast-import <<-INPUT_END
1338+
commit refs/heads/N5E
1339+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1340+
data <<COMMIT
1341+
copy with invalid syntax
1342+
COMMIT
1343+
1344+
from refs/heads/branch^0
1345+
ls "file2/"
1346+
INPUT_END'
1347+
13091348
test_expect_success \
13101349
'N: copy to root by id and modify' \
13111350
'echo "hello, world" >expect.foo &&

0 commit comments

Comments
 (0)