591603669c733e9b36ef614b72598ee6a0e5e235
1/*
2 * Licensed under a two-clause BSD-style license.
3 * See LICENSE for details.
4 */
5
6#include "git-compat-util.h"
7#include "line_buffer.h"
8#include "svndiff.h"
9
10/*
11 * svndiff0 applier
12 *
13 * See http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff.
14 *
15 * svndiff0 ::= 'SVN\0' window*
16 */
17
18static int error_short_read(struct line_buffer *input)
19{
20 if (buffer_ferror(input))
21 return error("error reading delta: %s", strerror(errno));
22 return error("invalid delta: unexpected end of file");
23}
24
25static int read_magic(struct line_buffer *in, off_t *len)
26{
27 static const char magic[] = {'S', 'V', 'N', '\0'};
28 struct strbuf sb = STRBUF_INIT;
29
30 if (*len < sizeof(magic) ||
31 buffer_read_binary(in, &sb, sizeof(magic)) != sizeof(magic))
32 return error_short_read(in);
33
34 if (memcmp(sb.buf, magic, sizeof(magic)))
35 return error("invalid delta: unrecognized file type");
36
37 *len -= sizeof(magic);
38 strbuf_release(&sb);
39 return 0;
40}
41
42int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
43 struct sliding_view *preimage, FILE *postimage)
44{
45 assert(delta && preimage && postimage);
46
47 if (read_magic(delta, &delta_len))
48 return -1;
49 if (delta_len)
50 return error("What do you think I am? A delta applier?");
51 return 0;
52}