summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-04-04 17:47:19 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-04-04 17:51:47 +0800
commit158e40b8c2b89114ebc3b8c83266cc17ff67f614 (patch)
tree8d6cee2e74d3872b241d09dd76718ee7600d3b4e
parentcf421aeff4faa15a2a80495345ae76023830ca86 (diff)
downloadcvn-158e40b8c2b89114ebc3b8c83266cc17ff67f614.tar.gz
Refactor out make_patch() from add().
-rw-r--r--test_vcx.t6
-rw-r--r--vcx30
2 files changed, 20 insertions, 16 deletions
diff --git a/test_vcx.t b/test_vcx.t
index e619824..2467819 100644
--- a/test_vcx.t
+++ b/test_vcx.t
@@ -26,7 +26,7 @@ chdir($sandbox) or die "Cant enter sandbox: $!";
my $cmd = File::Spec->catfile($orig_dir, "vcx");
# Test 'init'
-ok(system("perl $cmd init") == 0, "Init command ran successfully");
+ok(system("perl $cmd init > /dev/null") == 0, "Init command ran successfully");
ok(-d ROOT, "ROOT directory created");
ok(-e HEAD, "Head file created");
ok(-d OBJ_DIR, "OBJ_DIR directory created");
@@ -110,8 +110,8 @@ symlink("link_a", "link_b");
system("perl $cmd add link_b > /dev/null");
system("perl $cmd commit -m 'Double link' > /dev/null");
-my $head = read_file(HEAD);
-my ($tree_ptr) = bsd_glob(File::Spec->catfile(REV_DIR, $head, "tree-*"));
+$head = read_file(HEAD);
+($tree_ptr) = bsd_glob(File::Spec->catfile(REV_DIR, $head, "tree-*"));
my $staged_link = File::Spec->catfile(OBJ_DIR, $tree_ptr =~ s/.*tree-//r, "link_b");
is(readlink($staged_link), "link_a", "Symlink-to-symlink preserved literal target");
diff --git a/vcx b/vcx
index e872961..cf8b4bc 100644
--- a/vcx
+++ b/vcx
@@ -191,22 +191,10 @@ sub run_add {
return if compare($_, $obj_in_head) == 0;
}
- # Generate deltas if modified
my $obj_name = sha1_hex($rel);
my $obj_path = File::Spec->catfile(OBJ_DIR, $obj_name);
- if (-e $obj_path) {
- my $p_path = File::Spec->catfile(TMP_DIFF, "$obj_name.patch");
- if (-T $_) {
- if (compare($_, $obj_path) != 0) {
- unless (-d TMP_DIFF) { make_path(TMP_DIFF); }
- system("diff -u '$obj_path' '$_' > '$p_path'");
- }
- } else {
- make_bin_patch($_, $obj_path, $p_path);
- }
- }
-
+ make_patch($File::Find::name, $obj_name, $obj_path);
stage_file($File::Find::name, $obj_path, $staged_path);
print $afh "$rel\n"; # Record in meta file for the commit command
}
@@ -425,6 +413,22 @@ sub stage_deletions {
}, $search);
}
+sub make_patch {
+ my ($src, $obj_name, $obj_path) = @_;
+
+ if (-e $obj_path) {
+ my $p_path = File::Spec->catfile(TMP_DIFF, "$obj_name.patch");
+ if (-T $src) {
+ if (compare($src, $obj_path) != 0) {
+ unless (-d TMP_DIFF) { make_path(TMP_DIFF); }
+ system("diff -u '$obj_path' '$src' > '$p_path'");
+ }
+ } else {
+ make_bin_patch($src, $obj_path, $p_path);
+ }
+ }
+}
+
sub make_bin_patch {
my ($new_file, $old_file, $patch_out) = @_;