diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-04 11:34:40 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-04 11:34:40 +0800 |
| commit | 3af329abee56900dd42cb305bd7a431ab3ded90a (patch) | |
| tree | d7461d57f93867773adf9cc115f6bfaa9f14c42a | |
| parent | 2203cfea1a05c274da879301e2cc48bd748bb05c (diff) | |
| download | cvn-3af329abee56900dd42cb305bd7a431ab3ded90a.tar.gz | |
Introduce opt flags: commit -am.
| -rw-r--r-- | vcx | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -2,6 +2,7 @@ use strict; use warnings; + use File::Path qw(make_path); use File::Copy qw(copy); use File::Find; @@ -9,6 +10,7 @@ use File::Compare; use File::Basename; use File::Glob qw(:bsd_glob); use File::Spec; +use Getopt::Long; use Digest::SHA qw(sha1_hex); use POSIX qw(strftime); @@ -23,6 +25,8 @@ use constant TMP_TREE => TMP_DIR . '/tree'; use constant TMP_DIFF => TMP_DIR . '/deltas'; use constant TMP_META_FILE => TMP_DIR . '/meta'; +Getopt::Long::Configure("bundling"); + my $cmd = shift @ARGV // ''; my @args = @ARGV; @@ -34,10 +38,10 @@ if ($cmd eq 'init') { die "Usage: $0 add [path1] [path2] ...\n" unless @args; run_add(@args); } elsif ($cmd eq 'commit') { - # If the user typed: vcx commit "My message" - # $args[0] will contain the message. If not, it's empty. - my $message = join(' ', @args); - run_commit($message); + my ($m, $a); + GetOptions('m=s' => \$m, 'a' => \$a); + if ($a) { run_add("."); } + run_commit($m); } elsif ($cmd eq 'log') { run_log(); } else { @@ -180,7 +184,7 @@ sub run_add { my $prev_link = File::Spec->catfile($latest_tree_dir, $rel); # CASE 1: Regular File - if (-f $_ && !-l _) { + if (-f $_ && !-l $_) { return if -e $staged_path; # Already staged if (-l $prev_link) { @@ -209,7 +213,7 @@ sub run_add { } # CASE 2: Symlink - elsif (-l $File::Find::name) { + elsif (-l _) { my $target = readlink($File::Find::name); if (-l $prev_link) { @@ -236,8 +240,7 @@ sub run_add { } sub run_commit { - my ($message) = @_; - + my ($msg) = @_; my $content_changed = -s TMP_META_FILE; my ($staged_tree_ptr) = bsd_glob(File::Spec->catfile(TMP_DIR, "tree-*")); @@ -251,9 +254,9 @@ sub run_commit { return; } - if (!$message || $message eq "") { - $message = launch_editor(); - die "Commit aborted: empty message.\n" unless $message =~ /\S/; + if (!$msg || $msg eq "") { + $msg = launch_editor(); + die "Commit aborted: empty message.\n" unless $msg =~ /\S/; } # Prepare IDs @@ -291,12 +294,12 @@ sub run_commit { or die "Failed to move deltas to $dest_diff_dir: $!"; } - write_file(File::Spec->catfile($rev_dir, "message"), "$message\n"); + write_file(File::Spec->catfile($rev_dir, "message"), "$msg\n"); write_file(HEAD, "$next_id_hex\n"); # Update head File::Path::remove_tree(TMP_DIR) if -d TMP_DIR; - my ($subject) = split(/\n/, $message); + my ($subject) = split(/\n/, $msg); print "Committed revision [$next_id_hex]: $subject\n"; } |
