vcs-svn: read the preimage when applying deltas
authorJonathan Nieder <jrnieder@gmail.com>
Wed, 13 Oct 2010 09:30:37 +0000 (04:30 -0500)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 28 Mar 2011 03:50:01 +0000 (22:50 -0500)
The source view offset heading each svndiff0 window represents a
number of bytes past the beginning of the preimage.  Together with the
source view length, it dictates to the delta applier what portion of
the preimage instructions will refer to.  Read that portion right away
using the sliding window code.

Maybe some day we will use mmap to read data more lazily.

Subversion's implementation tolerates source view offsets pointing
past the end of the preimage file but we do not, for simplicity.

This does not teach the delta applier to read instructions or copy
data from the source view.  Deltas that could produce nonempty output
will still be rejected.

Improved-by: Ramkumar Ramachandra <artagnon@gmail.com>
Improved-by: David Barr <david.barr@cordelta.com>
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 be1234094fc5a5913955ce51973b59aae28f0206..90b6058ab67d38edcd576ec040e1dd3cee2368d0 100755 (executable)
@@ -86,4 +86,39 @@ test_expect_success 'nonempty (but unused) preimage view' '
        test_cmp empty actual
 '
 
+test_expect_success 'preimage view: right endpoint cannot backtrack' '
+       printf "SVNQ%b%b" "Q\003QQQ" "Q\002QQQ" |
+               q_to_nul >clear.backtrack &&
+       test_must_fail test-svn-fe -d preimage clear.backtrack 14
+'
+
+test_expect_success 'preimage view: left endpoint can advance' '
+       printf "SVNQ%b%b" "Q\003QQQ" "\001\002QQQ" |
+               q_to_nul >clear.preshrink &&
+       printf "SVNQ%b%b" "Q\003QQQ" "\001\001QQQ" |
+               q_to_nul >clear.shrinkbacktrack &&
+       test-svn-fe -d preimage clear.preshrink 14 >actual &&
+       test_must_fail test-svn-fe -d preimage clear.shrinkbacktrack 14 &&
+       test_cmp empty actual
+'
+
+test_expect_success 'preimage view: offsets compared by value' '
+       printf "SVNQ%b%b" "\001\001QQQ" "\0200Q\003QQQ" |
+               q_to_nul >clear.noisybacktrack &&
+       printf "SVNQ%b%b" "\001\001QQQ" "\0200\001\002QQQ" |
+               q_to_nul >clear.noisyadvance &&
+       test_must_fail test-svn-fe -d preimage clear.noisybacktrack 15 &&
+       test-svn-fe -d preimage clear.noisyadvance 15 &&
+       test_cmp empty actual
+'
+
+test_expect_success 'preimage view: reject truncated preimage' '
+       printf "SVNQ%b" "\010QQQQ" | q_to_nul >clear.lateemptyread &&
+       printf "SVNQ%b" "\010\001QQQ" | q_to_nul >clear.latenonemptyread &&
+       printf "SVNQ%b" "\001\010QQQ" | q_to_nul >clear.longread &&
+       test_must_fail test-svn-fe -d preimage clear.lateemptyread 9 &&
+       test_must_fail test-svn-fe -d preimage clear.latenonemptyread 9 &&
+       test_must_fail test-svn-fe -d preimage clear.longread 9
+'
+
 test_done
index 249efb6eeda1b6fe7eff488cdeedbaf74fddff73..b7c2c8bf53aabfe29af32be3b2b11bc20f2e7b86 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "git-compat-util.h"
+#include "sliding_window.h"
 #include "line_buffer.h"
 #include "svndiff.h"
 
@@ -127,6 +128,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
 
                if (read_offset(delta, &pre_off, &delta_len) ||
                    read_length(delta, &pre_len, &delta_len) ||
+                   move_window(preimage, pre_off, pre_len) ||
                    apply_one_window(delta, &delta_len))
                        return -1;
        }