0.17.31
by John Arbash Meinel
Bring in the 'rabin' experiment. |
1 |
/*
|
2 |
* delta.h: headers for delta functionality
|
|
3 |
*
|
|
4 |
* Adapted from GIT for Bazaar by
|
|
5 |
* John Arbash Meinel <john@arbash-meinel.com> (C) 2009
|
|
6 |
*
|
|
7 |
* This code is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License version 2 as
|
|
9 |
* published by the Free Software Foundation.
|
|
10 |
*/
|
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
11 |
#ifndef DELTA_H
|
12 |
#define DELTA_H
|
|
13 |
||
14 |
/* opaque object for delta index */
|
|
15 |
struct delta_index; |
|
16 |
||
0.23.42
by John Arbash Meinel
Change the code around again. |
17 |
struct source_info { |
0.23.57
by John Arbash Meinel
Change the formatting, replace \t with spaces to be consistent with bzr coding. |
18 |
const void *buf; /* Pointer to the beginning of source data */ |
19 |
unsigned long size; /* Total length of source data */ |
|
20 |
unsigned long agg_offset; /* Start of source data as part of the |
|
21 |
aggregate source */
|
|
0.23.42
by John Arbash Meinel
Change the code around again. |
22 |
};
|
23 |
||
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
24 |
|
25 |
/* result type for functions that have multiple failure modes */
|
|
26 |
typedef enum { |
|
27 |
DELTA_OK, /* Success */ |
|
28 |
DELTA_OUT_OF_MEMORY, /* Could not allocate required memory */ |
|
29 |
DELTA_INDEX_NEEDED, /* A delta_index must be passed */ |
|
30 |
DELTA_SOURCE_EMPTY, /* A source_info had no content */ |
|
31 |
DELTA_SOURCE_BAD, /* A source_info had invalid or corrupt content */ |
|
5698.2.6
by Martin
Also adapt create_delta to the return code interface as it uses malloc |
32 |
DELTA_BUFFER_EMPTY, /* A buffer pointer and size */ |
5698.2.7
by Martin
Non-code fixes noticed looking at full diff |
33 |
DELTA_SIZE_TOO_BIG, /* Delta data is larger than the max requested */ |
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
34 |
} delta_result; |
35 |
||
36 |
||
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
37 |
/*
|
38 |
* create_delta_index: compute index data from given buffer
|
|
39 |
*
|
|
5698.2.8
by Martin
Tweak function descriptions in delta header for clarity |
40 |
* Returns a delta_result status, when DELTA_OK then *fresh is set to a struct
|
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
41 |
* delta_index that should be passed to subsequent create_delta() calls, or to
|
5698.2.8
by Martin
Tweak function descriptions in delta header for clarity |
42 |
* free_delta_index(). Other values are a failure, and *fresh is unset.
|
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
43 |
* The given buffer must not be freed nor altered before free_delta_index() is
|
44 |
* called. The resultant struct must be freed using free_delta_index().
|
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
45 |
*/
|
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
46 |
extern delta_result |
0.23.43
by John Arbash Meinel
Change the internals to allow delta indexes to be expanded with new source data. |
47 |
create_delta_index(const struct source_info *src, |
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
48 |
struct delta_index *old, |
49 |
struct delta_index **fresh); |
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
50 |
|
0.23.45
by John Arbash Meinel
Add a function that updates the index for delta bytes. |
51 |
|
52 |
/*
|
|
53 |
* create_delta_index_from_delta: compute index data from given buffer
|
|
54 |
*
|
|
5698.2.8
by Martin
Tweak function descriptions in delta header for clarity |
55 |
* Returns a delta_result status, when DELTA_OK then *fresh is set to a struct
|
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
56 |
* delta_index that should be passed to subsequent create_delta() calls, or to
|
5698.2.8
by Martin
Tweak function descriptions in delta header for clarity |
57 |
* free_delta_index(). Other values are a failure, and *fresh is unset.
|
0.23.45
by John Arbash Meinel
Add a function that updates the index for delta bytes. |
58 |
* The bytes must be in the form of a delta structure, as generated by
|
59 |
* create_delta(). The generated index will only index the insert bytes, and
|
|
60 |
* not any of the control structures.
|
|
61 |
*/
|
|
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
62 |
extern delta_result |
0.23.45
by John Arbash Meinel
Add a function that updates the index for delta bytes. |
63 |
create_delta_index_from_delta(const struct source_info *delta, |
5698.2.5
by Martin
Switch approach to delta function interfaces and use a return code and outparam |
64 |
struct delta_index *old, |
65 |
struct delta_index **fresh); |
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
66 |
/*
|
67 |
* free_delta_index: free the index created by create_delta_index()
|
|
68 |
*
|
|
69 |
* Given pointer must be what create_delta_index() returned, or NULL.
|
|
70 |
*/
|
|
71 |
extern void free_delta_index(struct delta_index *index); |
|
72 |
||
73 |
/*
|
|
74 |
* sizeof_delta_index: returns memory usage of delta index
|
|
75 |
*
|
|
76 |
* Given pointer must be what create_delta_index() returned, or NULL.
|
|
77 |
*/
|
|
78 |
extern unsigned long sizeof_delta_index(struct delta_index *index); |
|
79 |
||
80 |
/*
|
|
81 |
* create_delta: create a delta from given index for the given buffer
|
|
82 |
*
|
|
83 |
* This function may be called multiple times with different buffers using
|
|
84 |
* the same delta_index pointer. If max_delta_size is non-zero and the
|
|
5698.2.6
by Martin
Also adapt create_delta to the return code interface as it uses malloc |
85 |
* resulting delta is to be larger than max_delta_size then DELTA_SIZE_TOO_BIG
|
5698.2.8
by Martin
Tweak function descriptions in delta header for clarity |
86 |
* is returned. Otherwise on success, DELTA_OK is returned and *delta_data is
|
87 |
* set to a new buffer with the delta data and *delta_size is updated with its
|
|
88 |
* size. That buffer must be freed by the caller.
|
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
89 |
*/
|
5698.2.6
by Martin
Also adapt create_delta to the return code interface as it uses malloc |
90 |
extern delta_result |
0.23.44
by John Arbash Meinel
Remove the multi-index handling now that we have index combining instead. |
91 |
create_delta(const struct delta_index *index, |
5698.2.6
by Martin
Also adapt create_delta to the return code interface as it uses malloc |
92 |
const void *buf, unsigned long bufsize, |
93 |
unsigned long *delta_size, unsigned long max_delta_size, |
|
94 |
void **delta_data); |
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
95 |
|
3735.38.1
by John Arbash Meinel
Change the delta byte stream to remove the 'source length' entry. |
96 |
/* the smallest possible delta size is 3 bytes
|
97 |
* Target size, Copy command, Copy length
|
|
98 |
*/
|
|
99 |
#define DELTA_SIZE_MIN 3
|
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
100 |
|
101 |
/*
|
|
102 |
* This must be called twice on the delta data buffer, first to get the
|
|
103 |
* expected source buffer size, and again to get the target buffer size.
|
|
104 |
*/
|
|
3735.36.7
by John Arbash Meinel
Get rid of inline and const, to reduce warnings and errors. |
105 |
static unsigned long |
106 |
get_delta_hdr_size(unsigned char **datap, const unsigned char *top) |
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
107 |
{
|
3735.36.7
by John Arbash Meinel
Get rid of inline and const, to reduce warnings and errors. |
108 |
unsigned char *data = *datap; |
0.23.57
by John Arbash Meinel
Change the formatting, replace \t with spaces to be consistent with bzr coding. |
109 |
unsigned char cmd; |
110 |
unsigned long size = 0; |
|
111 |
int i = 0; |
|
112 |
do { |
|
113 |
cmd = *data++; |
|
114 |
size |= (cmd & ~0x80) << i; |
|
115 |
i += 7; |
|
116 |
} while (cmd & 0x80 && data < top); |
|
117 |
*datap = data; |
|
118 |
return size; |
|
0.23.5
by John Arbash Meinel
Minor changes to get diff-delta.c and patch-delta.c to compile. |
119 |
}
|
120 |
||
121 |
#endif
|