mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
10 KiB

  1. < http://rsync.samba.org/ftp/unpacked/rsync/patches/gzip-rsyncable.diff >
  2. From: Rusty Russell <rusty@rustcorp.com.au>
  3. [NOTE: this patch is for _gzip_! --Wayne]
  4. It's pending for actual gzip inclusion! The maintainer was dug up and
  5. everything: it'll even be on by default.
  6. But here's the old patch,
  7. Rusty.
  8. --
  9. Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
  10. --- gzip-1.2.4.orig/deflate.c Fri Aug 13 22:35:31 1993
  11. +++ gzip-1.2.4-rsync/deflate.c Sat Dec 30 15:33:25 2000
  12. @@ -121,6 +121,14 @@
  13. #endif
  14. /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
  15. +#ifndef RSYNC_WIN
  16. +# define RSYNC_WIN 4096
  17. +#endif
  18. +/* Size of rsync window, must be < MAX_DIST */
  19. +
  20. +#define RSYNC_SUM_MATCH(sum) ((sum) % RSYNC_WIN == 0)
  21. +/* Whether window sum matches magic value */
  22. +
  23. /* ===========================================================================
  24. * Local data used by the "longest match" routines.
  25. */
  26. @@ -202,6 +210,8 @@
  27. unsigned near good_match;
  28. /* Use a faster search when the previous match is longer than this */
  29. +local ulg rsync_sum; /* rolling sum of rsync window */
  30. +local ulg rsync_chunk_end; /* next rsync sequence point */
  31. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  32. * the desired pack level (0..9). The values given below have been tuned to
  33. @@ -300,6 +310,10 @@
  34. #endif
  35. /* prev will be initialized on the fly */
  36. + /* rsync params */
  37. + rsync_chunk_end = 0xFFFFFFFFUL;
  38. + rsync_sum = 0;
  39. +
  40. /* Set the default configuration parameters:
  41. */
  42. max_lazy_match = configuration_table[pack_level].max_lazy;
  43. @@ -536,6 +550,8 @@
  44. memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
  45. match_start -= WSIZE;
  46. strstart -= WSIZE; /* we now have strstart >= MAX_DIST: */
  47. + if (rsync_chunk_end != 0xFFFFFFFFUL)
  48. + rsync_chunk_end -= WSIZE;
  49. block_start -= (long) WSIZE;
  50. @@ -563,13 +579,46 @@
  51. }
  52. }
  53. +local void rsync_roll(start, num)
  54. + unsigned start;
  55. + unsigned num;
  56. +{
  57. + unsigned i;
  58. +
  59. + if (start < RSYNC_WIN) {
  60. + /* before window fills. */
  61. + for (i = start; i < RSYNC_WIN; i++) {
  62. + if (i == start + num) return;
  63. + rsync_sum += (ulg)window[i];
  64. + }
  65. + num -= (RSYNC_WIN - start);
  66. + start = RSYNC_WIN;
  67. + }
  68. +
  69. + /* buffer after window full */
  70. + for (i = start; i < start+num; i++) {
  71. + /* New character in */
  72. + rsync_sum += (ulg)window[i];
  73. + /* Old character out */
  74. + rsync_sum -= (ulg)window[i - RSYNC_WIN];
  75. + if (rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(rsync_sum))
  76. + rsync_chunk_end = i;
  77. + }
  78. +}
  79. +
  80. +/* ===========================================================================
  81. + * Set rsync_chunk_end if window sum matches magic value.
  82. + */
  83. +#define RSYNC_ROLL(s, n) \
  84. + do { if (rsync) rsync_roll((s), (n)); } while(0)
  85. +
  86. /* ===========================================================================
  87. * Flush the current block, with given end-of-file flag.
  88. * IN assertion: strstart is set to the end of the current match.
  89. */
  90. #define FLUSH_BLOCK(eof) \
  91. flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \
  92. - (char*)NULL, (long)strstart - block_start, (eof))
  93. + (char*)NULL, (long)strstart - block_start, flush-1, (eof))
  94. /* ===========================================================================
  95. * Processes a new input file and return its compressed length. This
  96. @@ -580,7 +629,7 @@
  97. local ulg deflate_fast()
  98. {
  99. IPos hash_head; /* head of the hash chain */
  100. - int flush; /* set if current block must be flushed */
  101. + int flush; /* set if current block must be flushed, 2=>and padded */
  102. unsigned match_length = 0; /* length of best match */
  103. prev_length = MIN_MATCH-1;
  104. @@ -609,6 +658,7 @@
  105. lookahead -= match_length;
  106. + RSYNC_ROLL(strstart, match_length);
  107. /* Insert new strings in the hash table only if the match length
  108. * is not too large. This saves time but degrades compression.
  109. */
  110. @@ -637,9 +687,14 @@
  111. /* No match, output a literal byte */
  112. Tracevv((stderr,"%c",window[strstart]));
  113. flush = ct_tally (0, window[strstart]);
  114. + RSYNC_ROLL(strstart, 1);
  115. lookahead--;
  116. strstart++;
  117. }
  118. + if (rsync && strstart > rsync_chunk_end) {
  119. + rsync_chunk_end = 0xFFFFFFFFUL;
  120. + flush = 2;
  121. + }
  122. if (flush) FLUSH_BLOCK(0), block_start = strstart;
  123. /* Make sure that we always have enough lookahead, except
  124. @@ -715,6 +770,7 @@
  125. */
  126. lookahead -= prev_length-1;
  127. prev_length -= 2;
  128. + RSYNC_ROLL(strstart, prev_length+1);
  129. do {
  130. strstart++;
  131. INSERT_STRING(strstart, hash_head);
  132. @@ -727,24 +783,39 @@
  133. match_available = 0;
  134. match_length = MIN_MATCH-1;
  135. strstart++;
  136. - if (flush) FLUSH_BLOCK(0), block_start = strstart;
  137. + if (rsync && strstart > rsync_chunk_end) {
  138. + rsync_chunk_end = 0xFFFFFFFFUL;
  139. + flush = 2;
  140. + }
  141. + if (flush) FLUSH_BLOCK(0), block_start = strstart;
  142. } else if (match_available) {
  143. /* If there was no match at the previous position, output a
  144. * single literal. If there was a match but the current match
  145. * is longer, truncate the previous match to a single literal.
  146. */
  147. Tracevv((stderr,"%c",window[strstart-1]));
  148. - if (ct_tally (0, window[strstart-1])) {
  149. - FLUSH_BLOCK(0), block_start = strstart;
  150. - }
  151. + flush = ct_tally (0, window[strstart-1]);
  152. + if (rsync && strstart > rsync_chunk_end) {
  153. + rsync_chunk_end = 0xFFFFFFFFUL;
  154. + flush = 2;
  155. + }
  156. + if (flush) FLUSH_BLOCK(0), block_start = strstart;
  157. + RSYNC_ROLL(strstart, 1);
  158. strstart++;
  159. lookahead--;
  160. } else {
  161. /* There is no previous match to compare with, wait for
  162. * the next step to decide.
  163. */
  164. + if (rsync && strstart > rsync_chunk_end) {
  165. + /* Reset huffman tree */
  166. + rsync_chunk_end = 0xFFFFFFFFUL;
  167. + flush = 2;
  168. + FLUSH_BLOCK(0), block_start = strstart;
  169. + }
  170. match_available = 1;
  171. + RSYNC_ROLL(strstart, 1);
  172. strstart++;
  173. lookahead--;
  174. }
  175. --- gzip-1.2.4.orig/gzip.c Thu Aug 19 23:39:43 1993
  176. +++ gzip-1.2.4-rsync/gzip.c Fri Dec 29 21:20:54 2000
  177. @@ -239,6 +239,7 @@
  178. unsigned insize; /* valid bytes in inbuf */
  179. unsigned inptr; /* index of next byte to be processed in inbuf */
  180. unsigned outcnt; /* bytes in output buffer */
  181. +int rsync = 0; /* make ryncable chunks */
  182. struct option longopts[] =
  183. {
  184. @@ -268,6 +269,7 @@
  185. {"best", 0, 0, '9'}, /* compress better */
  186. {"lzw", 0, 0, 'Z'}, /* make output compatible with old compress */
  187. {"bits", 1, 0, 'b'}, /* max number of bits per code (implies -Z) */
  188. + {"rsyncable", 0, 0, 'R'}, /* make rsync-friendly archive */
  189. { 0, 0, 0, 0 }
  190. };
  191. @@ -357,6 +359,7 @@
  192. " -Z --lzw produce output compatible with old compress",
  193. " -b --bits maxbits max number of bits per code (implies -Z)",
  194. #endif
  195. + " --rsyncable Make rsync-friendly archive",
  196. " file... files to (de)compress. If none given, use standard input.",
  197. 0};
  198. char **p = help_msg;
  199. @@ -516,6 +519,9 @@
  200. #else
  201. recursive = 1; break;
  202. #endif
  203. + case 'R':
  204. + rsync = 1; break;
  205. +
  206. case 'S':
  207. #ifdef NO_MULTIPLE_DOTS
  208. if (*optarg == '.') optarg++;
  209. --- gzip-1.2.4.orig/gzip.h Fri Aug 13 22:35:33 1993
  210. +++ gzip-1.2.4-rsync/gzip.h Sat Dec 30 15:26:56 2000
  211. @@ -131,6 +131,7 @@
  212. extern unsigned insize; /* valid bytes in inbuf */
  213. extern unsigned inptr; /* index of next byte to be processed in inbuf */
  214. extern unsigned outcnt; /* bytes in output buffer */
  215. +extern int rsync; /* deflate into rsyncable chunks */
  216. extern long bytes_in; /* number of input bytes */
  217. extern long bytes_out; /* number of output bytes */
  218. @@ -282,7 +283,7 @@
  219. /* in trees.c */
  220. void ct_init OF((ush *attr, int *method));
  221. int ct_tally OF((int dist, int lc));
  222. -ulg flush_block OF((char *buf, ulg stored_len, int eof));
  223. +ulg flush_block OF((char *buf, ulg stored_len, int pad, int eof));
  224. /* in bits.c */
  225. void bi_init OF((file_t zipfile));
  226. --- gzip-1.2.4.orig/gzip.texi Thu Aug 19 06:42:50 1993
  227. +++ gzip-1.2.4-rsync/gzip.texi Fri Dec 29 21:20:54 2000
  228. @@ -316,6 +316,14 @@
  229. into the directory and compress all the files it finds there (or
  230. decompress them in the case of @code{gunzip}).
  231. +@item --rsyncable
  232. +While compressing, synchronize the output occasionally based on the
  233. +input. This reduces compression by about 1 percent most cases, but
  234. +means that the @code{rsync} program can take advantage of similarities
  235. +in the uncompressed input when syncronizing two files compressed with
  236. +this flag. @code{gunzip} cannot tell the difference between a
  237. +compressed file created with this option, and one created without it.
  238. +
  239. @item --suffix @var{suf}
  240. @itemx -S @var{suf}
  241. Use suffix @samp{@var{suf}} instead of @samp{.gz}. Any suffix can be
  242. --- gzip-1.2.4.orig/trees.c Wed Aug 18 03:36:32 1993
  243. +++ gzip-1.2.4-rsync/trees.c Sat Dec 30 15:37:00 2000
  244. @@ -850,9 +850,10 @@
  245. * trees or store, and output the encoded block to the zip file. This function
  246. * returns the total compressed length for the file so far.
  247. */
  248. -ulg flush_block(buf, stored_len, eof)
  249. +ulg flush_block(buf, stored_len, pad, eof)
  250. char *buf; /* input block, or NULL if too old */
  251. ulg stored_len; /* length of input block */
  252. + int pad; /* pad output to byte boundary */
  253. int eof; /* true if this is the last block for a file */
  254. {
  255. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  256. @@ -944,6 +967,10 @@
  257. Assert (input_len == isize, "bad input size");
  258. bi_windup();
  259. compressed_len += 7; /* align on byte boundary */
  260. + } else if (pad && (compressed_len % 8) != 0) {
  261. + send_bits((STORED_BLOCK<<1)+eof, 3); /* send block type */
  262. + compressed_len = (compressed_len + 3 + 7) & ~7L;
  263. + copy_block(buf, 0, 1); /* with header */
  264. }
  265. Tracev((stderr,"\ncomprlen %lu(%lu) ", compressed_len>>3,
  266. compressed_len-7*eof));