Skip to content

Commit c846e41

Browse files
committed
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 <[email protected]> Improved-by: David Barr <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Acked-by: Ramkumar Ramachandra <[email protected]>
1 parent d3f131b commit c846e41

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

t/t9011-svn-da.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,39 @@ test_expect_success 'catch copy that overflows' '
210210
test_must_fail test-svn-fe -d preimage copytarget.overflow $len
211211
'
212212

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+
213248
test_done

vcs-svn/svndiff.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* view_selector ::= copyfrom_source
2525
* | copyfrom_target
2626
* ;
27+
* copyfrom_source ::= # binary 00 000000;
2728
* copyfrom_target ::= # binary 01 000000;
2829
* copyfrom_data ::= # binary 10 000000;
2930
* packed_view_selector ::= # view_selector OR-ed with 6 bit value;
@@ -34,6 +35,7 @@
3435
*/
3536

3637
#define INSN_MASK 0xc0
38+
#define INSN_COPYFROM_SOURCE 0x00
3739
#define INSN_COPYFROM_TARGET 0x40
3840
#define INSN_COPYFROM_DATA 0x80
3941
#define OPERAND_MASK 0x3f
@@ -43,12 +45,13 @@
4345
#define VLI_BITS_PER_DIGIT 7
4446

4547
struct window {
48+
struct sliding_view *in;
4649
struct strbuf out;
4750
struct strbuf instructions;
4851
struct strbuf data;
4952
};
5053

51-
#define WINDOW_INIT { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }
54+
#define WINDOW_INIT(w) { (w), STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }
5255

5356
static void window_release(struct window *ctx)
5457
{
@@ -161,6 +164,19 @@ static int read_length(struct line_buffer *in, size_t *result, off_t *len)
161164
return 0;
162165
}
163166

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+
164180
static int copyfrom_target(struct window *ctx, const char **instructions,
165181
size_t nbytes, const char *instructions_end)
166182
{
@@ -209,12 +225,14 @@ static int execute_one_instruction(struct window *ctx,
209225
if (parse_first_operand(instructions, &nbytes, insns_end))
210226
return -1;
211227
switch (instruction & INSN_MASK) {
228+
case INSN_COPYFROM_SOURCE:
229+
return copyfrom_source(ctx, instructions, nbytes, insns_end);
212230
case INSN_COPYFROM_TARGET:
213231
return copyfrom_target(ctx, instructions, nbytes, insns_end);
214232
case INSN_COPYFROM_DATA:
215233
return copyfrom_data(ctx, data_pos, nbytes);
216234
default:
217-
return error("Unknown instruction %x", instruction);
235+
return error("invalid delta: unrecognized instruction");
218236
}
219237
}
220238

@@ -238,9 +256,9 @@ static int apply_window_in_core(struct window *ctx)
238256
}
239257

240258
static int apply_one_window(struct line_buffer *delta, off_t *delta_len,
241-
FILE *out)
259+
struct sliding_view *preimage, FILE *out)
242260
{
243-
struct window ctx = WINDOW_INIT;
261+
struct window ctx = WINDOW_INIT(preimage);
244262
size_t out_len;
245263
size_t instructions_len;
246264
size_t data_len;
@@ -283,7 +301,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
283301
if (read_offset(delta, &pre_off, &delta_len) ||
284302
read_length(delta, &pre_len, &delta_len) ||
285303
move_window(preimage, pre_off, pre_len) ||
286-
apply_one_window(delta, &delta_len, postimage))
304+
apply_one_window(delta, &delta_len, preimage, postimage))
287305
return -1;
288306
}
289307
return 0;

0 commit comments

Comments
 (0)