@matheusbsbs / matheus-bagliano / commits / c846e41078
Fork 0

vcs-svn: let deltas use data from preimage

The copyfrom_source instruction appends data from the preimage buffer to the end of output. Its arguments are a length and an offset relative to the beginning of the source view. With this change, the delta applier is able to reproduce all 5,636,613 blobs in the early history of the ASF repository. Tested with mkfifo backflow svn-fe <svn-asf-public-r0:940166 3<backflow | git fast-import --cat-blob-fd=3 3>backflow with svn-asf-public-r0:940166 produced by whatever version of Subversion the dumps in /dump/ on svn.apache.org use (presumably 1.6.something). 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>

Jonathan Nieder committed Oct 13, 2010 at 04:58 UTC c846e4107876936bed7177a811559bd74a72dcd8
2 files changed +58 -5
t/t9011-svn-da.sh
+35
@@ -210,4 +210,39 @@ test_expect_success 'catch copy that overflows' '
210 test_must_fail test-svn-fe -d preimage copytarget.overflow $len
211 '
212
213 +test_expect_success 'copyfrom source' '
214 + printf foo >expect &&
215 + printf "SVNQ%b%b" "Q\003\003\002Q" "\003Q" | q_to_nul >copysource.all &&
216 + test-svn-fe -d preimage copysource.all 11 >actual &&
217 + test_cmp expect actual
218 +'
219 +
220 +test_expect_success 'copy backwards' '
221 + printf oof >expect &&
222 + printf "SVNQ%b%b" "Q\003\003\006Q" "\001\002\001\001\001Q" |
223 + q_to_nul >copysource.rev &&
224 + test-svn-fe -d preimage copysource.rev 15 >actual &&
225 + test_cmp expect actual
226 +'
227 +
228 +test_expect_success 'offsets are relative to window' '
229 + printf fo >expect &&
230 + printf "SVNQ%b%b%b%b" "Q\003\001\002Q" "\001Q" \
231 + "\002\001\001\002Q" "\001Q" |
232 + q_to_nul >copysource.two &&
233 + test-svn-fe -d preimage copysource.two 18 >actual &&
234 + test_cmp expect actual
235 +'
236 +
237 +test_expect_success 'example from notes/svndiff' '
238 + printf aaaaccccdddddddd >expect &&
239 + printf aaaabbbbcccc >source &&
240 + printf "SVNQ%b%b%s" "Q\014\020\007\001" \
241 + "\004Q\004\010\0201\0107\010" d |
242 + q_to_nul >delta.example &&
243 + len=$(wc -c <delta.example) &&
244 + test-svn-fe -d source delta.example $len >actual &&
245 + test_cmp expect actual
246 +'
247 +
248 test_done
vcs-svn/svndiff.c
+23 -5
@@ -24,6 +24,7 @@
24 * view_selector ::= copyfrom_source
25 * | copyfrom_target
26 * ;
27 + * copyfrom_source ::= # binary 00 000000;
28 * copyfrom_target ::= # binary 01 000000;
29 * copyfrom_data ::= # binary 10 000000;
30 * packed_view_selector ::= # view_selector OR-ed with 6 bit value;
@@ -34,6 +35,7 @@
35 */
36
37 #define INSN_MASK 0xc0
38 +#define INSN_COPYFROM_SOURCE 0x00
39 #define INSN_COPYFROM_TARGET 0x40
40 #define INSN_COPYFROM_DATA 0x80
41 #define OPERAND_MASK 0x3f
@@ -43,12 +45,13 @@
45 #define VLI_BITS_PER_DIGIT 7
46
47 struct window {
48 + struct sliding_view *in;
49 struct strbuf out;
50 struct strbuf instructions;
51 struct strbuf data;
52 };
53
51 -#define WINDOW_INIT { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }
54 +#define WINDOW_INIT(w) { (w), STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }
55
56 static void window_release(struct window *ctx)
57 {
@@ -161,6 +164,19 @@ static int read_length(struct line_buffer *in, size_t *result, off_t *len)
164 return 0;
165 }
166
167 +static int copyfrom_source(struct window *ctx, const char **instructions,
168 + size_t nbytes, const char *insns_end)
169 +{
170 + size_t offset;
171 + if (parse_int(instructions, &offset, insns_end))
172 + return -1;
173 + if (unsigned_add_overflows(offset, nbytes) ||
174 + offset + nbytes > ctx->in->width)
175 + return error("invalid delta: copies source data outside view");
176 + strbuf_add(&ctx->out, ctx->in->buf.buf + offset, nbytes);
177 + return 0;
178 +}
179 +
180 static int copyfrom_target(struct window *ctx, const char **instructions,
181 size_t nbytes, const char *instructions_end)
182 {
@@ -209,12 +225,14 @@ static int execute_one_instruction(struct window *ctx,
225 if (parse_first_operand(instructions, &nbytes, insns_end))
226 return -1;
227 switch (instruction & INSN_MASK) {
228 + case INSN_COPYFROM_SOURCE:
229 + return copyfrom_source(ctx, instructions, nbytes, insns_end);
230 case INSN_COPYFROM_TARGET:
231 return copyfrom_target(ctx, instructions, nbytes, insns_end);
232 case INSN_COPYFROM_DATA:
233 return copyfrom_data(ctx, data_pos, nbytes);
234 default:
217 - return error("Unknown instruction %x", instruction);
235 + return error("invalid delta: unrecognized instruction");
236 }
237 }
238
@@ -238,9 +256,9 @@ static int apply_window_in_core(struct window *ctx)
256 }
257
258 static int apply_one_window(struct line_buffer *delta, off_t *delta_len,
241 - FILE *out)
259 + struct sliding_view *preimage, FILE *out)
260 {
243 - struct window ctx = WINDOW_INIT;
261 + struct window ctx = WINDOW_INIT(preimage);
262 size_t out_len;
263 size_t instructions_len;
264 size_t data_len;
@@ -283,7 +301,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
301 if (read_offset(delta, &pre_off, &delta_len) ||
302 read_length(delta, &pre_len, &delta_len) ||
303 move_window(preimage, pre_off, pre_len) ||
286 - apply_one_window(delta, &delta_len, postimage))
304 + apply_one_window(delta, &delta_len, preimage, postimage))
305 return -1;
306 }
307 return 0;