vcs-svn: handle log message with embedded NUL

Pass the log message by strbuf instead of as a C-style string and use
fwrite instead of printf to write it to fast-import so embedded '\0'
bytes can be preserved.

Currently "git log" doesn't show the embedded NULs but "git cat-file
commit" can.

While at it, stop including system headers from repo_tree.h.  git
source files need to include git-compat-util.h (or cache.h or
builtin.h) sooner to ensure the appropriate feature test macros are
defined.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
This commit is contained in:
Jonathan Nieder
2011-03-26 00:49:37 -05:00
parent 4c3169b03e
commit 195b7ca6f2
6 changed files with 94 additions and 13 deletions

View File

@ -397,6 +397,83 @@ test_expect_success 'NUL in property value' '
test_cmp expect.message actual.message
'
test_expect_success 'NUL in log message, file content, and property name' '
# Caveat: svnadmin 1.6.16 (r1073529) truncates at \0 in the
# svn:specialQnotreally example.
reinit_git &&
cat >expect <<-\EOF &&
OBJID
:100644 100644 OBJID OBJID M greeting
OBJID
:000000 100644 OBJID OBJID A greeting
EOF
printf "\n%s" "something with an ASCII NUL (Q)" >expect.message &&
printf "%s\n" "helQo" >expect.hello1 &&
printf "%s\n" "link hello" >expect.hello2 &&
{
properties svn:log "something with an ASCII NUL (Q)" &&
echo PROPS-END
} |
q_to_nul >props &&
{
q_to_nul <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: add
Prop-content-length: 10
Text-content-length: 6
Content-length: 16
PROPS-END
helQo
Revision-number: 2
EOF
echo Prop-content-length: $(wc -c <props) &&
echo Content-length: $(wc -c <props) &&
echo &&
cat props &&
q_to_nul <<-\EOF
Node-path: greeting
Node-kind: file
Node-action: change
Prop-content-length: 43
Text-content-length: 11
Content-length: 54
K 21
svn:specialQnotreally
V 1
*
PROPS-END
link hello
EOF
} >8bitclean.dump &&
test-svn-fe 8bitclean.dump >stream &&
git fast-import <stream &&
{
git rev-list HEAD |
git diff-tree --root --stdin |
sed "s/$_x40/OBJID/g"
} >actual &&
git cat-file commit HEAD | nul_to_q | sed -ne "/^\$/,\$ p" >actual.message &&
git cat-file blob HEAD^:greeting | nul_to_q >actual.hello1 &&
git cat-file blob HEAD:greeting | nul_to_q >actual.hello2 &&
test_cmp expect actual &&
test_cmp expect.message actual.message &&
test_cmp expect.hello1 actual.hello1 &&
test_cmp expect.hello2 actual.hello2
'
test_expect_success 'change file mode and reiterate content' '
reinit_git &&
cat >expect <<-\EOF &&