diff options
| -rw-r--r-- | vcx | 37 |
1 files changed, 15 insertions, 22 deletions
@@ -22,10 +22,7 @@ use constant HEAD => REPO . '/head'; # Current revision ID use constant INDEX => REPO . '/index'; # Index use constant OBJ_DIR => REPO . '/obj'; # Object store use constant REV_DIR => REPO . '/rev'; # Revisions - -# Staging area -use constant TMP_DIR => REPO . '/stg'; -use constant TMP_DIFF => TMP_DIR . '/delta.tar.gz'; +use constant TMP_DIR => REPO . '/stg'; # Staging area use constant MEM_LIMIT => 64 * 1024 * 1024; use constant MAX_INDEX_SIZE => 16 * 1024 * 1024; @@ -276,21 +273,11 @@ sub run_commit { my $stg_file = File::Spec->catfile(TMP_DIR, $out_p); my $patch = (-T $stg_file) - ? qx(diff -u '$base_obj' '$stg_file') + ? qx(diff '$base_obj' '$stg_file') : make_bin_patch($stg_file, $base_obj); - # DEBUG CODE START - if (defined $patch) { - my $raw_l = length($patch); - my $gz_p = Compress::Zlib::compress($patch); - my $gz_l = length($gz_p); - my $ratio = $raw_l > 0 ? ($gz_l / $raw_l) * 100 : 0; - printf("DEBUG: %s | File: %d | Raw Patch: %d | GZ Patch: %d (%.2f%% ratio)\n", - $out_p, $out_z, $raw_l, $gz_l, $ratio); - } - # DEBUG CODE END - - if (defined $patch && length($patch) < ($out_z * 0.5)) { + # 1.0 Factor: Use patch if it is smaller than or equal to the file size + if (defined $patch && length($patch) <= $out_z) { if (!$use_disk_patch && ($patch_mem_size + length($patch)) > MEM_LIMIT) { ($pt_fh, $pt_path) = tempfile(DIR => TMP_DIR, UNLINK => 0); my $tar = Archive::Tar->new; @@ -309,7 +296,7 @@ sub run_commit { $patch_mem_size += length($patch); } $out_b = $old->{hash}; - unlink($stg_file); # Remove staged file since we only need the patch + unlink($stg_file); } else { $out_b = $out_s; my $obj_path = get_obj_path($out_b); @@ -318,6 +305,7 @@ sub run_commit { } } } else { + # 0.0 Factor: Identity check (no changes) $out_b = $old->{hash}; } $idx = $it_idx->(); @@ -370,10 +358,15 @@ sub run_commit { $tar->add_data($_, $patches{$_}) for keys %patches; $tar_data = $tar->write(); } - my $gzipped_payload; - gzip \$tar_data => \$gzipped_payload or die "Gzip failed: $GzipError"; - $patch_bundle_hash = sha1_hex($gzipped_payload); - write_file(get_obj_path($patch_bundle_hash), $gzipped_payload); + + my $final_payload = $tar_data; + # 512 byte factor: Only gzip if bundle is large enough to be worth the overhead + if (length($tar_data) > 512) { + gzip \$tar_data => \$final_payload or die "Gzip failed: $GzipError"; + } + + $patch_bundle_hash = sha1_hex($final_payload); + write_file(get_obj_path($patch_bundle_hash), $final_payload); } # Revision file |
