diff options
author | Jeff King <peff@peff.net> | 2011-08-05 16:36:22 -0600 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-05 15:56:54 -0700 |
commit | 6280dfdc3b22aa821521182781e5a247b19fb515 (patch) | |
tree | 558e2c5187a36ad5710eae064d3b6acd99ada98b /t | |
parent | da656f17d37fe96454645c08f21a24134f5aa900 (diff) | |
download | git-6280dfdc3b22aa821521182781e5a247b19fb515.tar.gz git-6280dfdc3b22aa821521182781e5a247b19fb515.tar.xz |
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t9350-fast-export.sh | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 8c8e67946..d90a4136c 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -228,7 +228,7 @@ test_expect_success 'fast-export -C -C | fast-import' ' mkdir new && git --git-dir=new/.git init && git fast-export -C -C --signed-tags=strip --all > output && - grep "^C \"file6\" \"file7\"\$" output && + grep "^C file6 file7\$" output && cat output | (cd new && git fast-import && @@ -414,4 +414,30 @@ test_expect_success SYMLINKS 'directory becomes symlink' ' (cd result && git show master:foo) ' +test_expect_success 'fast-export quotes pathnames' ' + git init crazy-paths && + (cd crazy-paths && + blob=`echo foo | git hash-object -w --stdin` && + git update-index --add \ + --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \ + --cacheinfo 100644 $blob "path with \"quote\"" \ + --cacheinfo 100644 $blob "path with \\backslash" \ + --cacheinfo 100644 $blob "path with space" && + git commit -m addition && + git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index && + git read-tree --empty && + git update-index -z --index-info <index && + git commit -m rename && + git read-tree --empty && + git commit -m deletion && + git fast-export HEAD >export.out && + git rev-list HEAD >expect && + git init result && + cd result && + git fast-import <../export.out && + git rev-list HEAD >actual && + test_cmp ../expect actual + ) +' + test_done |