diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-18 18:06:37 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-18 18:06:37 +0800 |
| commit | bc4760cd1c0e8fd40c7bb66c743da13c0c841dc3 (patch) | |
| tree | 8e2fd29ee4c0922bc6dcd1c7fba21a2fab441da9 /vcx | |
| parent | cba12cec2ca9b55720610d48622dfff9a50ff140 (diff) | |
| download | urn-bc4760cd1c0e8fd40c7bb66c743da13c0c841dc3.tar.gz | |
Stage deleted files.
Diffstat (limited to 'vcx')
| -rw-r--r-- | vcx | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -149,7 +149,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->(); @@ -159,40 +160,46 @@ sub run_add { : !defined $wrk_entry ? -1 : $idx_entry->{path} cmp $wrk_entry->{path}; - my ($s, $c, $b, $m, $z, $p); - if ($cmp == 0) { - ($p, $m, $z) = ($wrk_entry->{path}, $wrk_entry->{mtime}, $wrk_entry->{size}); - $c = $idx_entry->{c_hash} // "-"; - $b = $idx_entry->{b_hash} // "-"; - - if ($idx_entry->{mtime} == $wrk_entry->{mtime} && $idx_entry->{size} == $wrk_entry->{size}) { - $s = $idx_entry->{s_hash}; + if ($idx_entry->{mtime} == $wrk_entry->{mtime} && + $idx_entry->{size} == $wrk_entry->{size}) { + # No change: Preserve all 3 hashes and metadata + printf $out "%-40s\t%-40s\t%-40s\t%-12d\t%-10d\t%s\n", + $idx_entry->{s_hash}, $idx_entry->{c_hash}, $idx_entry->{b_hash}, + $idx_entry->{mtime}, $idx_entry->{size}, $idx_entry->{path}; } else { - $s = hash_file_content($p); + my $p = $wrk_entry->{path}; + my $current_hash = hash_file_content($p); my $stg_path = File::Spec->catfile(TMP_DIR, $p); make_path(dirname($stg_path)); + (-l $p) ? symlink(readlink($p), $stg_path) : copy($p, $stg_path); + + # Update staged hash, preserve committed and base hashes + printf $out "%-40s\t%-40s\t%-40s\t%-12d\t%-10d\t%s\n", + $current_hash, $idx_entry->{c_hash}, $idx_entry->{b_hash}, + $wrk_entry->{mtime}, $wrk_entry->{size}, $p; } $idx_entry = $it_idx->(); $wrk_entry = $it_wrk->(); } elsif ($cmp > 0) { - ($p, $m, $z) = ($wrk_entry->{path}, $wrk_entry->{mtime}, $wrk_entry->{size}); - $s = hash_file_content($p); - ($c, $b) = ("-", "-"); - + # New File: hash and snapshot to staging + my $p = $wrk_entry->{path}; + my $hash = hash_file_content($p); my $stg_path = File::Spec->catfile(TMP_DIR, $p); make_path(dirname($stg_path)); + (-l $p) ? symlink(readlink($p), $stg_path) : copy($p, $stg_path); + + # Staged is the new hash; Committed and Base are '-' + printf $out "%-40s\t%-40s\t%-40s\t%-12d\t%-10d\t%s\n", + $hash, "-", "-", $wrk_entry->{mtime}, $wrk_entry->{size}, $p; $wrk_entry = $it_wrk->(); } - else { - ($s, $c, $b, $m, $z, $p) = ($idx_entry->{s_hash}, $idx_entry->{c_hash}, $idx_entry->{b_hash}, $idx_entry->{mtime}, $idx_entry->{size}, $idx_entry->{path}); + else { # Deleted $idx_entry = $it_idx->(); } - - printf $out "%-40s\t%-40s\t%-40s\t%-12d\t%-10d\t%s\n", $s, $c, $b, $m, $z, $p; } close $out; |
