summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-04-13 18:01:28 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-04-13 18:08:22 +0800
commit7a657f4af5316fe13ed27386b9a024fbd8c6371b (patch)
tree8419a3fd3a54fce6bb19ba2e7eabd9fe874e73bb
parent84e743dae0188fa5eea7a2b33209640c2a0b9898 (diff)
downloadcvn-7a657f4af5316fe13ed27386b9a024fbd8c6371b.tar.gz
wip: commit structure.
-rw-r--r--vcx26
1 files changed, 17 insertions, 9 deletions
diff --git a/vcx b/vcx
index 4c10d3f..7a98e1f 100644
--- a/vcx
+++ b/vcx
@@ -60,17 +60,25 @@ sub run_init {
touch_file(INDEX);
my $rev_id = to_hex_id(0);
- my $rev_dir = File::Spec->catfile(REV_DIR, $rev_id);
- make_path($rev_dir);
- write_file(HEAD, "$rev_id\n");
+ my $rev_file = File::Spec->catfile(REV_DIR, $rev_id);
- # Baseline tree (empty)
- my $tree_hash = sha1_hex("");
- my $tree_file = File::Spec->catfile($rev_dir, "tree-$tree_hash");
- open my $fh, '>', $tree_file or die $!; close $fh;
- make_path(File::Spec->catdir(OBJ_DIR, $tree_hash));
+ my $empty_tree = sha1_hex("");
+ touch_file(File::Spec->catfile(OBJ_DIR, $empty_tree));
- open my $mfh, '>', File::Spec->catfile($rev_dir, "message"); close $mfh;
+ my $ts = time();
+ my $msg = "Revision zero.\n";
+ my $msg_len = length($msg);
+
+ open my $fh, '>:raw', $rev_file or die $!;
+ print $fh "tree:$empty_tree\n";
+ print $fh "parent:none\n";
+ print $fh "date:$ts\n";
+ print $fh "len:$msg_len\n";
+ print $fh "\n"; # The "Header/body" separator
+ print $fh $msg;
+ close $fh;
+
+ write_file(HEAD, "$rev_id\n");
print "Initialized repository.\n";
}