restore rsyncable docs to man page
[debian/gzip] / debian / patches / rsyncable.diff
1 diff -u -r gzip-1.5/deflate.c /home/bdale/debian/gzip/deflate.c
2 --- gzip-1.5/deflate.c  2012-04-24 10:25:28.000000000 -0600
3 +++ /home/bdale/debian/gzip/deflate.c   2012-06-19 14:01:41.885498670 -0600
4 @@ -131,6 +131,14 @@
5  #endif
6  /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
7  
8 +#ifndef RSYNC_WIN
9 +#  define RSYNC_WIN 8192
10 +#endif
11 +/* Size of rsync window, must be < MAX_DIST */
12 +
13 +#define RSYNC_SUM_MATCH(sum) (((sum) & (RSYNC_WIN - 1)) == 0)
14 +/* Whether window sum matches magic value */
15 +
16  /* ===========================================================================
17   * Local data used by the "longest match" routines.
18   */
19 @@ -212,6 +220,8 @@
20  unsigned good_match;
21  /* Use a faster search when the previous match is longer than this */
22  
23 +local ulg rsync_sum;  /* rolling sum of rsync window */
24 +local ulg rsync_chunk_end; /* next rsync sequence point */
25  
26  /* Values for max_lazy_match, good_match and max_chain_length, depending on
27   * the desired pack level (0..9). The values given below have been tuned to
28 @@ -314,6 +324,10 @@
29  #endif
30      /* prev will be initialized on the fly */
31  
32 +    /* rsync params */
33 +    rsync_chunk_end = 0xFFFFFFFFUL;
34 +    rsync_sum = 0;
35 +
36      /* Set the default configuration parameters:
37       */
38      max_lazy_match   = configuration_table[pack_level].max_lazy;
39 @@ -331,6 +345,7 @@
40  
41      strstart = 0;
42      block_start = 0L;
43 +    rsync_chunk_end = 0xFFFFFFFFUL;
44  #ifdef ASMV
45      match_init(); /* initialize the asm code */
46  #endif
47 @@ -550,6 +565,8 @@
48          memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
49          match_start -= WSIZE;
50          strstart    -= WSIZE; /* we now have strstart >= MAX_DIST: */
51 +       if (rsync_chunk_end != 0xFFFFFFFFUL)
52 +           rsync_chunk_end -= WSIZE;
53  
54          block_start -= (long) WSIZE;
55  
56 @@ -579,6 +596,39 @@
57      }
58  }
59  
60 +local void rsync_roll(start, num)
61 +    unsigned start;
62 +    unsigned num;
63 +{
64 +    unsigned i;
65 +
66 +    if (start < RSYNC_WIN) {
67 +       /* before window fills. */
68 +       for (i = start; i < RSYNC_WIN; i++) {
69 +           if (i == start + num) return;
70 +           rsync_sum += (ulg)window[i];
71 +       }
72 +       num -= (RSYNC_WIN - start);
73 +       start = RSYNC_WIN;
74 +    }
75 +
76 +    /* buffer after window full */
77 +    for (i = start; i < start+num; i++) {
78 +       /* New character in */
79 +       rsync_sum += (ulg)window[i];
80 +       /* Old character out */
81 +       rsync_sum -= (ulg)window[i - RSYNC_WIN];
82 +       if (rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(rsync_sum))
83 +           rsync_chunk_end = i;
84 +    }
85 +}
86 +
87 +/* ===========================================================================
88 + * Set rsync_chunk_end if window sum matches magic value.
89 + */
90 +#define RSYNC_ROLL(s, n) \
91 +   do { if (rsync) rsync_roll((s), (n)); } while(0)
92 +
93  /* ===========================================================================
94   * Flush the current block, with given end-of-file flag.
95   * IN assertion: strstart is set to the end of the current match.
96 @@ -626,7 +676,8 @@
97  
98              lookahead -= match_length;
99  
100 -            /* Insert new strings in the hash table only if the match length
101 +           RSYNC_ROLL(strstart, match_length);
102 +           /* Insert new strings in the hash table only if the match length
103               * is not too large. This saves time but degrades compression.
104               */
105              if (match_length <= max_insert_length) {
106 @@ -654,9 +705,18 @@
107              /* No match, output a literal byte */
108              Tracevv((stderr,"%c",window[strstart]));
109              flush = ct_tally (0, window[strstart]);
110 +           RSYNC_ROLL(strstart, 1);
111              lookahead--;
112              strstart++;
113          }
114 +        if (rsync && strstart > rsync_chunk_end) {
115 +            ush  attr = 0;          /* ascii/binary flag */
116 +
117 +            flush = 1;
118 +            /* Reset huffman tree */
119 +            ct_init(&attr, &method);
120 +            rsync_chunk_end = 0xFFFFFFFFUL;
121 +        }
122          if (flush) FLUSH_BLOCK(0), block_start = strstart;
123  
124          /* Make sure that we always have enough lookahead, except
125 @@ -730,6 +790,7 @@
126               */
127              lookahead -= prev_length-1;
128              prev_length -= 2;
129 +           RSYNC_ROLL(strstart, prev_length+1);
130              do {
131                  strstart++;
132                  INSERT_STRING(strstart, hash_head);
133 @@ -742,24 +803,51 @@
134              match_available = 0;
135              match_length = MIN_MATCH-1;
136              strstart++;
137 -            if (flush) FLUSH_BLOCK(0), block_start = strstart;
138  
139 +           if (rsync && strstart > rsync_chunk_end) {
140 +               ush  attr = 0;          /* ascii/binary flag */
141 +
142 +               /* Reset huffman tree */
143 +               ct_init(&attr, &method);
144 +               rsync_chunk_end = 0xFFFFFFFFUL;
145 +               flush = 1;
146 +           }
147 +            if (flush) FLUSH_BLOCK(0), block_start = strstart;
148          } else if (match_available) {
149              /* If there was no match at the previous position, output a
150               * single literal. If there was a match but the current match
151               * is longer, truncate the previous match to a single literal.
152               */
153              Tracevv((stderr,"%c",window[strstart-1]));
154 -            if (ct_tally (0, window[strstart-1])) {
155 -                FLUSH_BLOCK(0), block_start = strstart;
156 -            }
157 +           flush = ct_tally (0, window[strstart-1]);
158 +           if (rsync && strstart > rsync_chunk_end) {
159 +               ush  attr = 0;          /* ascii/binary flag */
160 +
161 +               /* Reset huffman tree */
162 +               ct_init(&attr, &method);
163 +               rsync_chunk_end = 0xFFFFFFFFUL;
164 +
165 +               flush = 1;
166 +           }
167 +            if (flush) FLUSH_BLOCK(0), block_start = strstart;
168 +           RSYNC_ROLL(strstart, 1);
169              strstart++;
170              lookahead--;
171          } else {
172              /* There is no previous match to compare with, wait for
173               * the next step to decide.
174               */
175 +           if (rsync && strstart > rsync_chunk_end) {
176 +               ush  attr = 0;          /* ascii/binary flag */
177 +
178 +               /* Reset huffman tree */
179 +               ct_init(&attr, &method);
180 +               rsync_chunk_end = 0xFFFFFFFFUL;
181 +
182 +               FLUSH_BLOCK(0), block_start = strstart;
183 +           }
184              match_available = 1;
185 +           RSYNC_ROLL(strstart, 1);
186              strstart++;
187              lookahead--;
188          }
189 diff -u -r gzip-1.5/doc/gzip.texi /home/bdale/debian/gzip/doc/gzip.texi
190 --- gzip-1.5/doc/gzip.texi      2012-01-01 01:53:58.000000000 -0700
191 +++ /home/bdale/debian/gzip/doc/gzip.texi       2012-06-19 14:09:36.041559612 -0600
192 @@ -207,6 +207,7 @@
193    -V, --version     display version number
194    -1, --fast        compress faster
195    -9, --best        compress better
196 +    --rsyncable   Make rsync-friendly archive
197  
198  With no FILE, or when FILE is -, read standard input.
199  
200 @@ -353,6 +354,30 @@
201  into the directory and compress all the files it finds there (or
202  decompress them in the case of @command{gunzip}).
203  
204 +@item --rsyncable
205 +While compressing, synchronize the output occasionally based on the
206 +input.  This can reduce the compression slightly in some cases, but
207 +means that the @code{rsync} program can take advantage of similarities
208 +in the uncompressed input when syncronizing two files compressed with
209 +this flag.  @code{gunzip} cannot tell the difference between a
210 +compressed file created with this option, and one created without it.
211 +
212 +@item --rsyncable
213 +While compressing, synchronize the output occasionally based on
214 +the input.  This increases size by less than 1 percent most
215 +cases, but means that the @command{rsync} program can much more efficiently
216 +synchronize files compressed with this flag.  @command{gunzip}
217 +cannot tell the difference between a compressed file created
218 +with this option, and one created without it.
219 +
220 +@item --rsyncable
221 +While compressing, synchronize the output occasionally based on the
222 +input.  This can reduce the compression slightly in some cases, but
223 +means that the @code{rsync} program can take advantage of similarities
224 +in the uncompressed input when syncronizing two files compressed with
225 +this flag.  @code{gunzip} cannot tell the difference between a
226 +compressed file created with this option, and one created without it.
227 +
228  @item --suffix @var{suf}
229  @itemx -S @var{suf}
230  Use suffix @var{suf} instead of @samp{.gz}.  Any suffix can be
231 --- gzip-1.5/gzip.c     2012-04-24 10:25:28.000000000 -0600
232 +++ /home/bdale/debian/gzip/gzip.c      2012-06-19 14:00:43.283873180 -0600
233 @@ -213,6 +213,7 @@
234  unsigned insize;           /* valid bytes in inbuf */
235  unsigned inptr;            /* index of next byte to be processed in inbuf */
236  unsigned outcnt;           /* bytes in output buffer */
237 +int rsync = 0;             /* make ryncable chunks */
238  
239  static int handled_sig[] =
240    {
241 @@ -270,7 +271,7 @@
242      {"best",       0, 0, '9'}, /* compress better */
243      {"lzw",        0, 0, 'Z'}, /* make output compatible with old compress */
244      {"bits",       1, 0, 'b'}, /* max number of bits per code (implies -Z) */
245 -
246 +    {"rsyncable",  0, 0, 'R'}, /* make rsync-friendly archive */
247      { 0, 0, 0, 0 }
248  };
249  
250 @@ -353,6 +354,7 @@
251   "  -Z, --lzw         produce output compatible with old compress",
252   "  -b, --bits=BITS   max number of bits per code (implies -Z)",
253  #endif
254 + "  --rsyncable       Make rsync-friendly archive",
255   "",
256   "With no FILE, or when FILE is -, read standard input.",
257   "",
258 @@ -481,8 +483,11 @@
259  #else
260              recursive = 1;
261  #endif
262 -            break;
263 -        case 'S':
264 +           break;
265 +        case 'R':
266 +           rsync = 1; break;
267 +
268 +       case 'S':
269  #ifdef NO_MULTIPLE_DOTS
270              if (*optarg == '.') optarg++;
271  #endif
272 diff -u -r gzip-1.5/gzip.h /home/bdale/debian/gzip/gzip.h
273 --- gzip-1.5/gzip.h     2012-01-01 01:53:58.000000000 -0700
274 +++ /home/bdale/debian/gzip/gzip.h      2012-06-19 13:57:36.833883093 -0600
275 @@ -140,6 +140,7 @@
276  extern unsigned insize; /* valid bytes in inbuf */
277  extern unsigned inptr;  /* index of next byte to be processed in inbuf */
278  extern unsigned outcnt; /* bytes in output buffer */
279 +extern int rsync;  /* deflate into rsyncable chunks */
280  
281  extern off_t bytes_in;   /* number of input bytes */
282  extern off_t bytes_out;  /* number of output bytes */
283 diff --git a/gzip.1 b/gzip.1
284 index 71e097c..faee860 100644
285 --- a/gzip.1
286 +++ b/gzip.1
287 @@ -5,6 +5,7 @@ gzip, gunzip, zcat \- compress or expand files
288  .ll +8
289  .B gzip
290  .RB [ " \-acdfhklLnNrtvV19 " ]
291 +.RB [ --rsyncable ]
292  .RB [ \-S\ suffix ]
293  [
294  .I "name \&..."
295 @@ -287,6 +288,16 @@ will descend into the directory and compress all the files it finds there
296  .I gunzip
297  ).
298  .TP
299 +.B --rsyncable
300 +While compressing, synchronize the output occasionally based on the input.
301 +This increases size by less than 1 percent most cases, but means that the
302 +.BR rsync (1)
303 +program can take advantage of similarities in the uncompressed input
304 +when syncronizing two files compressed with this flag.
305 +.I gunzip
306 +cannot tell the difference between a compressed file created with this option,
307 +and one created without it.
308 +.TP
309  .B \-S .suf   --suffix .suf
310  When compressing, use suffix .suf instead of .gz.
311  Any non-empty suffix can be given, but suffixes