diff options
| -rw-r--r-- | vcx | 69 |
1 files changed, 29 insertions, 40 deletions
@@ -24,9 +24,8 @@ 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_META => TMP_DIR . '/meta'; -use constant TMP_DIFF => TMP_DIR . '/delta.tar.gz'; +use constant TMP_DIR => REPO . '/stg'; +use constant TMP_DIFF => TMP_DIR . '/delta.tar.gz'; use constant MEM_LIMIT => 64 * 1024 * 1024; use constant MAX_INDEX_SIZE => 16 * 1024 * 1024; @@ -76,7 +75,8 @@ sub run_add { my $it_idx = stream_index(); my $it_wrk = stream_tree(@paths); - open(my $out, ">:raw", $tmp_idx) or die "Could not create $tmp_idx: $!"; + open(my $out, ">:raw", $tmp_idx) + or die "Could not create $tmp_idx: $!"; my $idx_entry = $it_idx->(); my $wrk_entry = $it_wrk->(); @@ -87,54 +87,43 @@ sub run_add { : $idx_entry->{path} cmp $wrk_entry->{path}; my $path = ($cmp <= 0) ? $idx_entry->{path} : $wrk_entry->{path}; - my $matches_spec = matches_paths($path, \@paths); - if ($cmp == 0) { - if ($matches_spec) { - if ($idx_entry->{mtime} == $wrk_entry->{mtime} && - $idx_entry->{size} == $wrk_entry->{size}) { - # No change - print $out join("\t", $idx_entry->{staged_hash}, $idx_entry->{base_hash}, - $idx_entry->{mtime}, $idx_entry->{size}, $idx_entry->{path}) . "\n"; + if ($idx_entry->{mtime} == $wrk_entry->{mtime} && + $idx_entry->{size} == $wrk_entry->{size}) { + # No change + print $out join("\t", $idx_entry->{staged_hash}, + $idx_entry->{base_hash}, $idx_entry->{mtime}, + $idx_entry->{size}, $idx_entry->{path}) . "\n"; + } else { + my $current_hash = hash_file_content($wrk_entry->{path}); + if ($current_hash eq $idx_entry->{staged_hash}) { + # mtime changed, but content is identical. + # Refresh mtime/size in index, but keep staged/base hashes. + print $out join("\t", $idx_entry->{staged_hash}, + $idx_entry->{base_hash}, $wrk_entry->{mtime}, + $wrk_entry->{size}, $wrk_entry->{path}) . "\n"; } else { - my $current_hash = hash_file_content($wrk_entry->{path}); - if ($current_hash eq $idx_entry->{staged_hash}) { - # mtime changed, but content is identical. - # Refresh mtime/size in index, but keep staged/base hashes. - print $out join("\t", $idx_entry->{staged_hash}, $idx_entry->{base_hash}, - $wrk_entry->{mtime}, $wrk_entry->{size}, $wrk_entry->{path}) . "\n"; - } else { - # Modified: update staged_hash to the new content, keep base_hash as-is. - print $out join("\t", $current_hash, $idx_entry->{base_hash}, - $wrk_entry->{mtime}, $wrk_entry->{size}, $wrk_entry->{path}) . "\n"; - } + # Modified: update staged_hash to the new content, keep base_hash as-is. + print $out join("\t", $current_hash, $idx_entry->{base_hash}, + $wrk_entry->{mtime}, $wrk_entry->{size}, $wrk_entry->{path}) . "\n"; } - } else { - # Outside pathspec: keep index row - print $out join("\t", $idx_entry->{staged_hash}, $idx_entry->{base_hash}, - $idx_entry->{mtime}, $idx_entry->{size}, $idx_entry->{path}) . "\n"; } $idx_entry = $it_idx->(); $wrk_entry = $it_wrk->(); } elsif ($cmp > 0) { # New File on disk - if ($matches_spec) { - my $hash = hash_file_content($wrk_entry->{path}); - # For a brand new file, staged and base start as the same hash. - print $out join("\t", $hash, $hash, $wrk_entry->{mtime}, $wrk_entry->{size}, - $wrk_entry->{path}) . "\n"; - } + my $hash = hash_file_content($wrk_entry->{path}); + print $out join("\t", $hash, $hash, $wrk_entry->{mtime}, + $wrk_entry->{size}, $wrk_entry->{path}) . "\n"; $wrk_entry = $it_wrk->(); } else { # File in index but missing from disk (deletion) - if (!$matches_spec) { - # Not in our current 'add' scope; keep it in the index. - print $out join("\t", $idx_entry->{staged_hash}, $idx_entry->{base_hash}, - $idx_entry->{mtime}, $idx_entry->{size}, $idx_entry->{path}) . "\n"; - } - # If it matches spec but is gone from disk, we drop it (staging the deletion). + # Not in our current 'add' scope; keep it in the index. + print $out join("\t", $idx_entry->{staged_hash}, + $idx_entry->{base_hash}, $idx_entry->{mtime}, + $idx_entry->{size}, $idx_entry->{path}) . "\n"; $idx_entry = $it_idx->(); } } @@ -595,7 +584,7 @@ sub snapshot_tree { close $tmp_fh; rename($tmp_path, $obj_path) or die "Rename failed: $!"; } else { - write_file($obj_path, join("", @buffer)); + write_file($obj_path, join("", @buf)); } } else { unlink($tmp_path) if $use_disk; |
