summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-03-27 16:34:27 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-03-27 16:34:40 +0800
commitb322fe254bffa08481427230403c4d9b3a58623a (patch)
tree06e6cf942a4e622a39e75c156364039a8b3f1106
parentc54970aed7e1ecbec194863dc42484075a77bcbe (diff)
downloadcvn-b322fe254bffa08481427230403c4d9b3a58623a.tar.gz
Hash filename.
-rw-r--r--vcx49
1 files changed, 23 insertions, 26 deletions
diff --git a/vcx b/vcx
index 2c95691..1fcbd09 100644
--- a/vcx
+++ b/vcx
@@ -8,6 +8,7 @@ use File::Find;
use File::Basename;
use File::Glob qw(:bsd_glob);
use File::Spec;
+use Digest::SHA qw(sha1_hex);
use constant VCX_DIR => '.vcx';
use constant BSE_DIR => VCX_DIR . '/bse';
@@ -72,24 +73,20 @@ sub check_staged_status {
my $tmp_link = File::Spec->catfile(TMP_DIR, $path);
return 0 unless -l $tmp_link;
- # 1. Get the staging target (what's in .vcx/obj/)
my $staged_target = readlink($tmp_link);
- # 2. CASE: Work tree entry is a SYMLINK
- if (-l $path) {
- # Compare where the work tree link points vs where the staging link points
- return (readlink($path) eq $staged_target);
- }
-
- # 3. CASE: Work tree entry is a REGULAR FILE
if (-f $path) {
# The staged target (e.g., ../obj/path.tmp) must exist to diff
my $abs_target = File::Spec->rel2abs($staged_target, dirname($tmp_link));
return 0 unless -e $abs_target;
-
return (system("diff -q '$path' '$abs_target' > /dev/null") == 0);
}
+ if (-l $path) {
+ # Compare where the work tree link points vs where the staging link points
+ return (readlink($path) eq $staged_target);
+ }
+
return 0;
}
@@ -107,12 +104,10 @@ sub run_add {
my $tmp_link = File::Spec->catfile(TMP_DIR, $rel);
my $base_link = File::Spec->catfile(BSE_DIR, $rel);
- # CASE 1: File (Regular)
if (-f $File::Find::name && !-l $File::Find::name) {
my $obj_path = File::Spec->catfile(OBJ_DIR, $rel . ".tmp");
_sync_file_to_obj($File::Find::name, $obj_path, $tmp_link);
}
- # CASE 2: Symlink
elsif (-l $File::Find::name) {
_sync_symlink_to_tmp($File::Find::name, $tmp_link);
}
@@ -126,21 +121,23 @@ sub run_add {
# For Regular Files: Copy to OBJ and link to TMP
sub _sync_file_to_obj {
- my ($src, $obj, $tmp) = @_;
-
- # 1. Ensure the directory path to the OBJ file exists
- make_path(dirname($obj));
- # 2. Ensure the directory path to the TMP symlink exists
- make_path(dirname($tmp));
-
- copy($src, $obj);
-
- # Create relative link from TMP to OBJ
- my $rel_target = File::Spec->abs2rel(File::Spec->rel2abs($obj), dirname($tmp));
-
- unlink($tmp) if -e $tmp || -l $tmp;
- symlink($rel_target, $tmp);
- print "[Add File] $src\n";
+ my ($src, $obj_path_not_used, $tmp) = @_;
+
+ my $rel_path = File::Spec->abs2rel($src, '.');
+ $rel_path =~ s|^\./||;
+
+ my $filename = sha1_hex($rel_path);
+ my $obj = File::Spec->catfile(OBJ_DIR, $filename);
+
+ make_path(dirname($tmp));
+ copy($src, $obj) or die "Copy failed: $!";
+
+ my $target = File::Spec->abs2rel($obj, dirname($tmp));
+
+ unlink($tmp) if -e $tmp || -l $tmp;
+ symlink($target, $tmp) or die "Symlink failed: $!";
+
+ print "[Add File] $src (stored as $filename)\n";
}
# For Symlinks: Mirror the symlink into TMP