summaryrefslogtreecommitdiffstats
path: root/vcx
diff options
context:
space:
mode:
Diffstat (limited to 'vcx')
-rw-r--r--vcx43
1 files changed, 25 insertions, 18 deletions
diff --git a/vcx b/vcx
index f1772c9..8c3cbc3 100644
--- a/vcx
+++ b/vcx
@@ -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;