summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-04-16 22:04:52 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-04-16 22:04:52 +0800
commit3836351da68f85cb99e9186f80bb0d4d8a23742d (patch)
treecbd57b7ee22134d787b86482c944406b7231da4e
parent746683fb793b1ac30b6e418ec7143d298c12647c (diff)
downloadcvn-3836351da68f85cb99e9186f80bb0d4d8a23742d.tar.gz
Simplify run_add().HEADmaster
-rw-r--r--vcx69
1 files changed, 29 insertions, 40 deletions
diff --git a/vcx b/vcx
index 559d449..a0b4564 100644
--- a/vcx
+++ b/vcx
@@ -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;