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.

275 lines
9.7 KiB

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