vcs-svn: read instructions from deltas
authorJonathan Nieder <jrnieder@gmail.com>
Wed, 13 Oct 2010 09:38:01 +0000 (04:38 -0500)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 28 Mar 2011 04:02:05 +0000 (23:02 -0500)
Buffer the instruction section upon encountering it for later
interpretation.

An alternative design would involve parsing the instructions
at this point and buffering them in some processed form. Using
the unprocessed form is simpler.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Ramkumar Ramachandra <artagnon@gmail.com>
t/t9011-svn-da.sh
vcs-svn/svndiff.c
index 26a4a3694a8f322e579d7a3678d13e61b077e317..d9acd0c8a61f519bf99eaa4d8856ace56cefca96 100755 (executable)
@@ -133,4 +133,9 @@ test_expect_success 'reject truncated inline data' '
        test_must_fail test-svn-fe -d preimage inline.trunc 10
 '
 
+test_expect_success 'reject truncated inline data (after instruction section)' '
+       printf "SVNQ%b%b%s" "QQ\001\001\003" "\0201" "b" | q_to_nul >insn.trunc &&
+       test_must_fail test-svn-fe -d preimage insn.trunc 11
+'
+
 test_done
index 175168f599839c4db471540cb0f0759c065b7429..8968fdb4eb7c5d09edc3a865a9639dc9c7cf8491 100644 (file)
 #define VLI_BITS_PER_DIGIT 7
 
 struct window {
+       struct strbuf instructions;
        struct strbuf data;
 };
 
-#define WINDOW_INIT    { STRBUF_INIT }
+#define WINDOW_INIT    { STRBUF_INIT, STRBUF_INIT }
 
 static void window_release(struct window *ctx)
 {
+       strbuf_release(&ctx->instructions);
        strbuf_release(&ctx->data);
 }
 
@@ -124,7 +126,8 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len)
        /* "source view" offset and length already handled; */
        if (read_length(delta, &out_len, delta_len) ||
            read_length(delta, &instructions_len, delta_len) ||
-           read_length(delta, &data_len, delta_len))
+           read_length(delta, &data_len, delta_len) ||
+           read_chunk(delta, delta_len, &ctx.instructions, instructions_len))
                goto error_out;
        if (instructions_len) {
                error("What do you think I am?  A delta applier?");