vcs-svn: quote paths correctly for ls command
authorDavid Barr <david.barr@cordelta.com>
Sat, 11 Dec 2010 16:59:31 +0000 (03:59 +1100)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 7 Mar 2011 07:43:58 +0000 (01:43 -0600)
This bug was found while importing rev 601865 of ASF.

[jn: with test]

Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
t/t9010-svn-fe.sh
vcs-svn/fast_export.c
vcs-svn/string_pool.c
vcs-svn/string_pool.h

index 2ae5374de38a2a618713f93fd290f74bf1dff67f..720fd6b5a32e88f0b58614e0bea4cc3e7a1e0e07 100755 (executable)
@@ -270,6 +270,105 @@ test_expect_success PIPE 'directory with files' '
        test_cmp hi directory/file2
 '
 
+test_expect_success PIPE 'branch name with backslash' '
+       reinit_git &&
+       sort <<-\EOF >expect.branch-files &&
+       trunk/file1
+       trunk/file2
+       "branches/UpdateFOPto094\\/file1"
+       "branches/UpdateFOPto094\\/file2"
+       EOF
+
+       echo hi >hi &&
+       echo hello >hello &&
+       {
+               properties \
+                       svn:author author@example.com \
+                       svn:date "1999-02-02T00:01:02.000000Z" \
+                       svn:log "add directory with some files in it" &&
+               echo PROPS-END
+       } >props.setup &&
+       {
+               properties \
+                       svn:author brancher@example.com \
+                       svn:date "2007-12-06T21:38:34.000000Z" \
+                       svn:log "Updating fop to .94 and adjust fo-stylesheets" &&
+               echo PROPS-END
+       } >props.branch &&
+       {
+               cat <<-EOF &&
+               SVN-fs-dump-format-version: 3
+
+               Revision-number: 1
+               EOF
+               echo Prop-content-length: $(wc -c <props.setup) &&
+               echo Content-length: $(wc -c <props.setup) &&
+               echo &&
+               cat props.setup &&
+               cat <<-\EOF &&
+
+               Node-path: trunk
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: branches
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: trunk/file1
+               Node-kind: file
+               Node-action: add
+               EOF
+               text_no_props hello &&
+               cat <<-\EOF &&
+               Node-path: trunk/file2
+               Node-kind: file
+               Node-action: add
+               EOF
+               text_no_props hi &&
+               cat <<-\EOF &&
+
+               Revision-number: 2
+               EOF
+               echo Prop-content-length: $(wc -c <props.branch) &&
+               echo Content-length: $(wc -c <props.branch) &&
+               echo &&
+               cat props.branch &&
+               cat <<-\EOF
+
+               Node-path: branches/UpdateFOPto094\
+               Node-kind: dir
+               Node-action: add
+               Node-copyfrom-rev: 1
+               Node-copyfrom-path: trunk
+
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 34
+               Content-length: 34
+
+               K 13
+               svn:mergeinfo
+               V 0
+
+               PROPS-END
+               EOF
+       } >branch.dump &&
+       try_dump branch.dump &&
+
+       git ls-tree -r --name-only HEAD |
+       sort >actual.branch-files &&
+       test_cmp expect.branch-files actual.branch-files
+'
+
 test_expect_success PIPE 'node without action' '
        reinit_git &&
        cat >inaction.dump <<-\EOF &&
index a8ce5c64b26d693054fc4fc269f6a34b0cd543d5..4d57efabd50a428c280105bac758b2b7131c765e 100644 (file)
@@ -107,7 +107,7 @@ static void ls_from_active_commit(uint32_t depth, const uint32_t *path)
 {
        /* ls "path/to/file" */
        printf("ls \"");
-       pool_print_seq(depth, path, '/', stdout);
+       pool_print_seq_q(depth, path, '/', stdout);
        printf("\"\n");
        fflush(stdout);
 }
index c08abac71d3ed8b94fcfd2868e81055f8f1bede9..be43598d5be357e7640eeec9fff3a0b1c082b4cb 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "git-compat-util.h"
+#include "quote.h"
 #include "trp.h"
 #include "obj_pool.h"
 #include "string_pool.h"
@@ -75,6 +76,16 @@ void pool_print_seq(uint32_t len, const uint32_t *seq, char delim, FILE *stream)
        }
 }
 
+void pool_print_seq_q(uint32_t len, const uint32_t *seq, char delim, FILE *stream)
+{
+       uint32_t i;
+       for (i = 0; i < len && ~seq[i]; i++) {
+               quote_c_style(pool_fetch(seq[i]), NULL, stream, 1);
+               if (i < len - 1 && ~seq[i + 1])
+                       fputc(delim, stream);
+       }
+}
+
 uint32_t pool_tok_seq(uint32_t sz, uint32_t *seq, const char *delim, char *str)
 {
        char *context = NULL;
index 3720cf81642596a05dbbafe4d37a79e4e5c9995b..96e501dc5304d5381f982ce1c042f59910ce97e9 100644 (file)
@@ -5,6 +5,7 @@ uint32_t pool_intern(const char *key);
 const char *pool_fetch(uint32_t entry);
 uint32_t pool_tok_r(char *str, const char *delim, char **saveptr);
 void pool_print_seq(uint32_t len, const uint32_t *seq, char delim, FILE *stream);
+void pool_print_seq_q(uint32_t len, const uint32_t *seq, char delim, FILE *stream);
 uint32_t pool_tok_seq(uint32_t sz, uint32_t *seq, const char *delim, char *str);
 void pool_reset(void);