diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-17 18:45:12 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-17 18:45:12 +0800 |
| commit | 3c2a198686336707eaa76bb63e6639fe04460e5a (patch) | |
| tree | fb3c0a298f0c5bd833189ade363df13742239a73 /vcx | |
| parent | 1d8f6ad42cb51cfb8ba8b430b0df93d1769237d0 (diff) | |
| download | cvn-3c2a198686336707eaa76bb63e6639fe04460e5a.tar.gz | |
Diffstat (limited to 'vcx')
| -rw-r--r-- | vcx | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -63,6 +63,76 @@ sub run_init { } sub run_status { + my $it_idx = stream_index(); + my $it_wrk = stream_tree("."); + + my $head = read_head() // '0'; + print "On Revision: $head\n\n"; + + my $idx = $it_idx->(); + my $wrk = $it_wrk->(); + my $found_changes = 0; + + while ($idx || $wrk) { + # Determine walk direction: -1 (Index only), 1 (Disk only), 0 (Both) + my $cmp = !defined $idx ? 1 + : !defined $wrk ? -1 + : $idx->{path} cmp $wrk->{path}; + + my $flag = ""; + my $suffix = ""; + my $path = ""; + + if ($cmp < 0) { + # File exists in Index but is missing from the Disk + $path = $idx->{path}; + $flag = "[D]"; + $idx = $it_idx->(); + } + elsif ($cmp > 0) { + # File is on Disk but not yet known to the Index + $path = $wrk->{path}; + $flag = "[N]"; + $wrk = $it_wrk->(); + } + else { + # Path exists in both; check for modifications + $path = $idx->{path}; + my $stg_path = File::Spec->catfile(TMP_DIR, $path); + my $is_staged = -e $stg_path; + + # Compare workspace metadata against the metadata stored in the Index + # (The Index metadata was updated during the last 'add' or 'commit') + my $workspace_changed = ($wrk->{mtime} != $idx->{mtime} || $wrk->{size} != $idx->{size}); + + if ($is_staged) { + if ($workspace_changed) { + # It's staged, but the workspace has been touched since the 'add' + $flag = "[M]"; + $suffix = "(dirty)"; + } else { + # It's staged and matches the workspace exactly + # Use hash comparison to see if it's a brand new file + $flag = ($idx->{s_hash} eq $idx->{b_hash}) ? "[N]" : "[M]"; + $suffix = "(staged)"; + } + } elsif ($workspace_changed) { + # Not staged, but differs from the last commit + $flag = "[M]"; + } + + $idx = $it_idx->(); + $wrk = $it_wrk->(); + } + + if ($flag ne "") { + printf "%s %s %s\n", $flag, $path, $suffix; + $found_changes = 1; + } + } + + print "No changes detected.\n" unless $found_changes; + print "\n"; } sub run_add { |
