| OLD | NEW |
| 1 /* | 1 /* |
| 2 bsdiff.c -- Binary patch generator. | 2 bsdiff.c -- Binary patch generator. |
| 3 | 3 |
| 4 Copyright 2003 Colin Percival | 4 Copyright 2003 Colin Percival |
| 5 | 5 |
| 6 For the terms under which this work may be distributed, please see | 6 For the terms under which this work may be distributed, please see |
| 7 the adjoining file "LICENSE". | 7 the adjoining file "LICENSE". |
| 8 | 8 |
| 9 ChangeLog: | 9 ChangeLog: |
| 10 2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit | 10 2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 stream->WriteVarint32(header->slen); | 196 stream->WriteVarint32(header->slen); |
| 197 stream->WriteVarint32(header->scrc32); | 197 stream->WriteVarint32(header->scrc32); |
| 198 stream->WriteVarint32(header->dlen); | 198 stream->WriteVarint32(header->dlen); |
| 199 } | 199 } |
| 200 | 200 |
| 201 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, | 201 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, |
| 202 SourceStream* new_stream, | 202 SourceStream* new_stream, |
| 203 SinkStream* patch_stream) | 203 SinkStream* patch_stream) |
| 204 { | 204 { |
| 205 base::Time start_bsdiff_time = base::Time::Now(); | 205 base::Time start_bsdiff_time = base::Time::Now(); |
| 206 LOG(INFO) << "Start bsdiff"; | 206 VLOG(1) << "Start bsdiff"; |
| 207 size_t initial_patch_stream_length = patch_stream->Length(); | 207 size_t initial_patch_stream_length = patch_stream->Length(); |
| 208 | 208 |
| 209 SinkStreamSet patch_streams; | 209 SinkStreamSet patch_streams; |
| 210 SinkStream* control_stream_copy_counts = patch_streams.stream(0); | 210 SinkStream* control_stream_copy_counts = patch_streams.stream(0); |
| 211 SinkStream* control_stream_extra_counts = patch_streams.stream(1); | 211 SinkStream* control_stream_extra_counts = patch_streams.stream(1); |
| 212 SinkStream* control_stream_seeks = patch_streams.stream(2); | 212 SinkStream* control_stream_seeks = patch_streams.stream(2); |
| 213 SinkStream* diff_skips = patch_streams.stream(3); | 213 SinkStream* diff_skips = patch_streams.stream(3); |
| 214 SinkStream* diff_bytes = patch_streams.stream(4); | 214 SinkStream* diff_bytes = patch_streams.stream(4); |
| 215 SinkStream* extra_bytes = patch_streams.stream(5); | 215 SinkStream* extra_bytes = patch_streams.stream(5); |
| 216 | 216 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 229 } | 229 } |
| 230 | 230 |
| 231 if (!V.Allocate(oldsize + 1)) { | 231 if (!V.Allocate(oldsize + 1)) { |
| 232 LOG(ERROR) << "Could not allocate V[], " << ((oldsize + 1) * sizeof(int)) | 232 LOG(ERROR) << "Could not allocate V[], " << ((oldsize + 1) * sizeof(int)) |
| 233 << " bytes"; | 233 << " bytes"; |
| 234 return MEM_ERROR; | 234 return MEM_ERROR; |
| 235 } | 235 } |
| 236 | 236 |
| 237 base::Time q_start_time = base::Time::Now(); | 237 base::Time q_start_time = base::Time::Now(); |
| 238 qsufsort(I, V, old, oldsize); | 238 qsufsort(I, V, old, oldsize); |
| 239 LOG(INFO) << " done qsufsort " | 239 VLOG(1) << " done qsufsort " |
| 240 << (base::Time::Now() - q_start_time).InSecondsF(); | 240 << (base::Time::Now() - q_start_time).InSecondsF(); |
| 241 V.clear(); | 241 V.clear(); |
| 242 | 242 |
| 243 const uint8* newbuf = new_stream->Buffer(); | 243 const uint8* newbuf = new_stream->Buffer(); |
| 244 const int newsize = new_stream->Remaining(); | 244 const int newsize = new_stream->Remaining(); |
| 245 | 245 |
| 246 int control_length = 0; | 246 int control_length = 0; |
| 247 int diff_bytes_length = 0; | 247 int diff_bytes_length = 0; |
| 248 int diff_bytes_nonzero = 0; | 248 int diff_bytes_nonzero = 0; |
| 249 int extra_bytes_length = 0; | 249 int extra_bytes_length = 0; |
| 250 | 250 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 391 |
| 392 uint32 copy_count = lenf; | 392 uint32 copy_count = lenf; |
| 393 uint32 extra_count = gap; | 393 uint32 extra_count = gap; |
| 394 int32 seek_adjustment = ((pos - lenb) - (lastpos + lenf)); | 394 int32 seek_adjustment = ((pos - lenb) - (lastpos + lenf)); |
| 395 | 395 |
| 396 control_stream_copy_counts->WriteVarint32(copy_count); | 396 control_stream_copy_counts->WriteVarint32(copy_count); |
| 397 control_stream_extra_counts->WriteVarint32(extra_count); | 397 control_stream_extra_counts->WriteVarint32(extra_count); |
| 398 control_stream_seeks->WriteVarint32Signed(seek_adjustment); | 398 control_stream_seeks->WriteVarint32Signed(seek_adjustment); |
| 399 ++control_length; | 399 ++control_length; |
| 400 #ifdef DEBUG_bsmedberg | 400 #ifdef DEBUG_bsmedberg |
| 401 LOG(INFO) << StringPrintf( | 401 VLOG(1) << StringPrintf("Writing a block: copy: %-8u extra: %-8u seek: " |
| 402 "Writing a block: copy: %-8u extra: %-8u seek: %+-9d", | 402 "%+-9d", copy_count, extra_count, |
| 403 copy_count, extra_count, seek_adjustment); | 403 seek_adjustment); |
| 404 #endif | 404 #endif |
| 405 | 405 |
| 406 lastscan = scan - lenb; // Include the backward extension in seed. | 406 lastscan = scan - lenb; // Include the backward extension in seed. |
| 407 lastpos = pos - lenb; // ditto. | 407 lastpos = pos - lenb; // ditto. |
| 408 lastoffset = lastpos - lastscan; | 408 lastoffset = lastpos - lastscan; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 diff_skips->WriteVarint32(pending_diff_zeros); | 412 diff_skips->WriteVarint32(pending_diff_zeros); |
| 413 | 413 |
| 414 I.clear(); | 414 I.clear(); |
| 415 | 415 |
| 416 MBSPatchHeader header; | 416 MBSPatchHeader header; |
| 417 // The string will have a null terminator that we don't use, hence '-1'. | 417 // The string will have a null terminator that we don't use, hence '-1'. |
| 418 COMPILE_ASSERT(sizeof(MBS_PATCH_HEADER_TAG) - 1 == sizeof(header.tag), | 418 COMPILE_ASSERT(sizeof(MBS_PATCH_HEADER_TAG) - 1 == sizeof(header.tag), |
| 419 MBS_PATCH_HEADER_TAG_must_match_header_field_size); | 419 MBS_PATCH_HEADER_TAG_must_match_header_field_size); |
| 420 memcpy(header.tag, MBS_PATCH_HEADER_TAG, sizeof(header.tag)); | 420 memcpy(header.tag, MBS_PATCH_HEADER_TAG, sizeof(header.tag)); |
| 421 header.slen = oldsize; | 421 header.slen = oldsize; |
| 422 header.scrc32 = CalculateCrc(old, oldsize); | 422 header.scrc32 = CalculateCrc(old, oldsize); |
| 423 header.dlen = newsize; | 423 header.dlen = newsize; |
| 424 | 424 |
| 425 WriteHeader(patch_stream, &header); | 425 WriteHeader(patch_stream, &header); |
| 426 | 426 |
| 427 size_t diff_skips_length = diff_skips->Length(); | 427 size_t diff_skips_length = diff_skips->Length(); |
| 428 patch_streams.CopyTo(patch_stream); | 428 patch_streams.CopyTo(patch_stream); |
| 429 | 429 |
| 430 LOG(INFO) << "Control tuples: " << control_length | 430 VLOG(1) << "Control tuples: " << control_length |
| 431 << " copy bytes: " << diff_bytes_length | 431 << " copy bytes: " << diff_bytes_length |
| 432 << " mistakes: " << diff_bytes_nonzero | 432 << " mistakes: " << diff_bytes_nonzero |
| 433 << " (skips: " << diff_skips_length << ")" | 433 << " (skips: " << diff_skips_length << ")" |
| 434 << " extra bytes: " << extra_bytes_length; | 434 << " extra bytes: " << extra_bytes_length; |
| 435 | 435 |
| 436 LOG(INFO) << "Uncompressed bsdiff patch size " | 436 VLOG(1) << "Uncompressed bsdiff patch size " |
| 437 << patch_stream->Length() - initial_patch_stream_length; | 437 << patch_stream->Length() - initial_patch_stream_length; |
| 438 | 438 |
| 439 LOG(INFO) << "End bsdiff " | 439 VLOG(1) << "End bsdiff " |
| 440 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); | 440 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); |
| 441 | 441 |
| 442 return OK; | 442 return OK; |
| 443 } | 443 } |
| 444 | 444 |
| 445 } // namespace | 445 } // namespace |
| OLD | NEW |