navid/veins / commit
445d1f5a8870
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: d99aa6ed5a2d
Browse files at this commit · Download source
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -498,7 +498,7 @@ * There is no staging area and no stash. Every on-disk edit is captured in history and can be restored through the operation log. * `vn new` starts a new empty change on top of `@`. `vn describe -message <msg>` sets a message. `vn commit -message <msg>` is `describe` followed by `new`.-* Checking out a revision means making it (or a new empty child of it) the working-copy commit, then updating the files.+* Checking out a revision means making a new empty child of it the working-copy commit, then updating the files. A fresh clone does the same, so `vn stat` is clean until the first edit. === Empty changes @@ -1081,7 +1081,7 @@ | `vn init [path] [-git-import:<gitdir>]` | Create a repository, optionally importing an existing git repo. | `vn clone <url> [-blobs head\|none\|all]` | Clone via the native protocol. | `vn status` | Working-copy changes, conflicts, files needing regeneration.-| `vn log [-rev <revset>] [-no-col-titles]` | Show history, newest first, flagging conflicted and divergent changes.+| `vn log [-rev <revset>] [-lN \| -fN] [-no-col-titles]` | Show history, newest first, flagging conflicted and divergent changes. | `vn show <rev>`, `vn diff [-rev <rev>]` | Display a commit or a diff. | `vn new [<rev>...]`, `vn describe [-message <message>]`, `vn commit -message <message>` | Create and describe changes. `vn commit` does nothing when the working copy has no changes. | `vn mv` | Move tracked files, recording renames.@@ -1107,7 +1107,7 @@ `vn cfg` reads and writes `.veins/config` by default. With `-global`, it edits the user-level `~/.local/config/veins/veins.toml`. `vn cfg <key>` prints a value, `vn cfg <key> <value>` sets one, `vn cfg -unset <key>` removes one, and `vn cfg` with no arguments lists the configuration. -`vn log` prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with `-no-col-titles`. Output is colored when standard output is a terminal; setting `NO_COLOR` disables color.+`vn log` prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with `-no-col-titles`. `-lN` limits the output to the last N commits (newest N), while `-fN` shows the first N commits (oldest N) in oldest-first order. The separated forms `-l N` and `-f N`, and the bare forms `lN` and `fN`, are also accepted. Output is colored when standard output is a terminal; setting `NO_COLOR` disables color. `vn status` colors its change markers (`A` bright green, `M` cyan, `D` red, and `C` bright red). `vn diff` prints unified hunks with context; removed lines are red and added lines are green. --- a/docs/SPECIFICATION_V1.html+++ b/docs/SPECIFICATION_V1.html@@ -1610,7 +1610,7 @@ <p><code>vn new</code> starts a new empty change on top of <code>@</code>. <code>vn describe -message <msg></code> sets a message. <code>vn commit -message <msg></code> is <code>describe</code> followed by <code>new</code>.</p> </li> <li>-<p>Checking out a revision means making it (or a new empty child of it) the working-copy commit, then updating the files.</p>+<p>Checking out a revision means making a new empty child of it the working-copy commit, then updating the files. A fresh clone does the same, so <code>vn stat</code> is clean until the first edit.</p> </li> </ul> </div>@@ -2943,7 +2943,7 @@ <td class="tableblock halign-left valign-top"><p class="tableblock">Working-copy changes, conflicts, files needing regeneration.</p></td> </tr> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn log [-rev <revset>] [-no-col-titles]</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn log [-rev <revset>] [-lN | -fN] [-no-col-titles]</code></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Show history, newest first, flagging conflicted and divergent changes.</p></td> </tr> <tr>@@ -3036,7 +3036,7 @@ <p><code>vn cfg</code> reads and writes <code>.veins/config</code> by default. With <code>-global</code>, it edits the user-level <code>~/.local/config/veins/veins.toml</code>. <code>vn cfg <key></code> prints a value, <code>vn cfg <key> <value></code> sets one, <code>vn cfg -unset <key></code> removes one, and <code>vn cfg</code> with no arguments lists the configuration.</p> </div> <div class="paragraph">-<p><code>vn log</code> prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with <code>-no-col-titles</code>. Output is colored when standard output is a terminal; setting <code>NO_COLOR</code> disables color.</p>+<p><code>vn log</code> prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with <code>-no-col-titles</code>. <code>-lN</code> limits the output to the last N commits (newest N), while <code>-fN</code> shows the first N commits (oldest N) in oldest-first order. The separated forms <code>-l N</code> and <code>-f N</code>, and the bare forms <code>lN</code> and <code>fN</code>, are also accepted. Output is colored when standard output is a terminal; setting <code>NO_COLOR</code> disables color.</p> </div> <div class="paragraph"> <p><code>vn status</code> colors its change markers (<code>A</code> bright green, <code>M</code> cyan, <code>D</code> red, and <code>C</code> bright red). <code>vn diff</code> prints unified hunks with context; removed lines are red and added lines are green.</p>@@ -3426,7 +3426,7 @@ <div id="footer"> <div id="footer-text"> Version 0.1-draft<br>-Last updated 2026-11-28 00:07:58 UTC+Last updated 2026-11-28 00:44:52 UTC </div> </div> </body>--- a/veins/src/cli/help_cmd.sx+++ b/veins/src/cli/help_cmd.sx@@ -224,12 +224,14 @@ } fn show_log() void = trust {- stdio.puts("usage: vn log [-rev <revset>] [-no-col-titles]")+ stdio.puts("usage: vn log [-rev <revset>] [-lN | -fN] [-no-col-titles]") stdio.puts("") stdio.puts("show commit history, newest first") stdio.puts("") stdio.puts("options:") stdio.puts(" -rev <revset> show only the given revision set")+ stdio.puts(" -lN, -l <N> show the last N commits (newest N)")+ stdio.puts(" -fN, -f <N> show the first N commits (oldest N)") stdio.puts(" -no-col-titles omit column titles") } --- a/veins/src/cli/log_cmd.sx+++ b/veins/src/cli/log_cmd.sx@@ -1,4 +1,4 @@-/// `vn log [-rev <revset>]`: show commit history, newest first.+/// `vn log [-rev <revset>] [-lN | -fN]`: show commit history, newest first. val str = use("std/string") val stdio = use("std/stdio")@@ -178,7 +178,13 @@ return bytes.Bytes.dup(bytes.Bytes.slice(target.cid, 0, len)) } -pub fn run(repo: layout.Repo, rev: bytes.Bytes, col_titles: bool) i32 = trust {+pub fn run(+ repo: layout.Repo,+ rev: bytes.Bytes,+ col_titles: bool,+ limit: usize,+ first: bool+) i32 = trust { val snap: i32 = snapshot.run(repo) if snap != 0 { return snap@@ -229,6 +235,33 @@ } } sort_recs(recs)+ if limit > 0 {+ val shown: mut list[ref LogRec] = lists.new[ref LogRec]()+ val n: usize = @len(recs)+ if first {+ val start: mut usize = 0+ if n > limit {+ start = n - limit+ }+ val i: mut usize = n+ for i > start {+ i--+ @append(shown, rec_at(recs, i))+ }+ } else {+ val count: mut usize = n+ if count > limit {+ count = limit+ }+ val i: mut usize = 0+ for i < count {+ @append(shown, rec_at(recs, i))+ i+++ }+ }+ @listfree(recs)+ recs = shown+ } val w_commit: usize = 12 val w_change: mut usize = 6 val w_date: usize = 19--- a/veins/src/main.sx+++ b/veins/src/main.sx@@ -60,6 +60,26 @@ return false } return @load8(a) == 45+}++fn parse_count(b: bytes.Bytes, start: usize) option[usize] = trust {+ if start >= b.len {+ return none+ }+ val value: mut usize = 0+ val i: mut usize = start+ for i < b.len {+ val c: u8 = bytes.Bytes.at(b, i)+ if c < 48 || c > 57 {+ return none+ }+ value = value * 10 + (c - 48) as usize+ i+++ }+ if value == 0 {+ return none+ }+ return some value } fn run_init(args: list[ref u8], start: usize) i32 = trust {@@ -166,10 +186,13 @@ val rev: mut bytes.Bytes = bytes.empty() val col_titles: mut bool = true val end_flags: mut bool = false+ val limit: mut usize = 0+ val first: mut bool = false val i: mut usize = start for i < @len(args) { val o = @get(args, i) if o is some a {+ val av: bytes.Bytes = bytes.from_cstr(a) if !end_flags && cmd_is(a, c"--", 2) { end_flags = true } elif !end_flags && (cmd_is(a, c"-r", 2) || cmd_is(a, c"-rev", 4)) {@@ -186,12 +209,53 @@ } } elif !end_flags && cmd_is(a, c"-no-col-titles", 14) { col_titles = false+ } elif !end_flags && (cmd_is(a, c"-l", 2) || cmd_is(a, c"-f", 2)) {+ if i + 1 >= @len(args) {+ msg.error_prefix()+ stdio.eprint("{s} requires a count\n", {str.from_cstr(a)})+ return 1+ }+ val v = @get(args, i + 1)+ val n_opt: mut option[usize] = none+ if v is some rv {+ n_opt = parse_count(bytes.from_cstr(rv), 0)+ }+ if n_opt is some n {+ limit = n+ first = cmd_is(a, c"-f", 2)+ i+++ } else {+ msg.error_prefix()+ stdio.eprint("{s} requires a positive count\n", {str.from_cstr(a)})+ return 1+ }+ } elif !end_flags && av.len > 2+ && bytes.Bytes.at(av, 0) == 45+ && (bytes.Bytes.at(av, 1) == 108 || bytes.Bytes.at(av, 1) == 102) {+ val n_opt = parse_count(av, 2)+ if n_opt is some n {+ limit = n+ first = bytes.Bytes.at(av, 1) == 102+ } else {+ msg.error_prefix()+ stdio.eprint("invalid log count: {s}\n", {str.from_cstr(a)})+ return 1+ }+ } elif !end_flags && av.len > 1+ && (bytes.Bytes.at(av, 0) == 108 || bytes.Bytes.at(av, 0) == 102) {+ val n_opt = parse_count(av, 1)+ if n_opt is some n {+ limit = n+ first = bytes.Bytes.at(av, 0) == 102+ } else {+ rev = av+ } } elif !end_flags && is_flag(a) { msg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)}) return 1 } else {- rev = bytes.from_cstr(a)+ rev = av } } i++@@ -199,7 +263,7 @@ val repo_opt = open_repo_or_error(str.from_cstr(c".")) match repo_opt { some repo => {- val status: i32 = log_cmd.run(repo, rev, col_titles)+ val status: i32 = log_cmd.run(repo, rev, col_titles, limit, first) layout.free_repo(repo) return status }--- a/veins/src/protocol/transfer.sx+++ b/veins/src/protocol/transfer.sx@@ -17,6 +17,7 @@ val view = use("../object/view.sx") val files = use("../io/files.sx") val msg_refs = use("../protocol/messages.sx")+val checkout = use("../worktree/checkout.sx") type ChunkWalk = { handles: mut list[ref store.Handle]@@ -343,7 +344,21 @@ if clone { val dt = default_target(refs) if dt is some id2 {- set_workspace(tx.view, id2)+ val child_opt = checkout.create_working_copy_commit(tx, repo, id2)+ match child_opt {+ some child => {+ set_workspace(tx.view, child)+ viewops.rebuild_heads(tx.view)+ if child.ptr != none {+ val cp: mut ref void = child.ptr as ref void+ @free(cp)+ }+ }+ none => {+ txnmod.abort(tx)+ return 1+ }+ } } } return txnmod.finish(tx, bytes.bytes(c"clone", 5))--- a/veins/src/worktree/checkout.sx+++ b/veins/src/worktree/checkout.sx@@ -13,7 +13,11 @@ val names = use("../object/names.sx") val blob = use("../object/blob.sx") val tree = use("../object/tree.sx")+val commit = use("../object/commit.sx") val conflict = use("../object/conflict.sx")+val prim = use("../core/primitives.sx")+val identity = use("../core/identity.sx")+val random = use("std/crypto/random") val repoconfig = use("../core/repoconfig.sx") val graph = use("../object/graph.sx") val treewalk = use("../object/treewalk.sx")@@ -1516,6 +1520,53 @@ /// Check out `rev` (empty means the working-copy commit) into the repository. /// The working-copy commit is moved to the target, so subsequent edits amend /// that commit and any bookmark naming it follows the rewrite.+pub fn create_working_copy_commit(+ tx: mut ref txn.Txn,+ repo: layout.Repo,+ parent: objid.Id+) option[objid.Id] = trust {+ val lc_opt = graph.load_commit(txn.handles(tx), parent)+ val lc: mut ref graph.LoadedCommit = none+ match lc_opt {+ some v => {+ lc = v+ }+ none => {+ return none+ }+ }+ val root: objid.Id = copy_id(lc.c.root_tree)+ graph.free_loaded(lc)+ val cid: ref u8 = @alloc(16) as ref u8+ random.random_bytes(cid as ref void, 16)+ val sig = identity.signature(repo)+ val parents: mut list[objid.Id] = lists.new[objid.Id]()+ @append(parents, parent)+ val renames: list[ref commit.Rename] = lists.new[ref commit.Rename]()+ val extra: list[ref prim.KeyValue] = lists.new[ref prim.KeyValue]()+ val nc: mut ref commit.Commit = @alloc(@sizeof(commit.Commit)) as ref commit.Commit+ nc.version = 1+ nc.parents = parents+ nc.root_tree = root+ nc.change_id = objid.change_id(cid)+ nc.author = sig+ nc.committer = sig+ nc.message = bytes.empty()+ nc.renames_state = commit.RENAMES_RECORDED+ nc.renames = renames+ nc.extra = extra+ val encoded: bytes.Bytes = commit.encode(nc)+ val new_id: objid.Id = txn.add_object(tx, types.COMMIT, encoded)+ @listfree(parents)+ @listfree(renames)+ @listfree(extra)+ @free(nc as ref void)+ @free(cid as ref void)+ identity.free_sig(sig)+ free_id(root)+ return some new_id+}+ pub fn run(repo: layout.Repo, rev: bytes.Bytes) i32 = trust { val snap: i32 = snapshot.run(repo) if snap != 0 {@@ -1594,6 +1645,21 @@ if have_wc { if objid.Id.eql(wc, target) { same_target = true+ } else {+ val wc_loaded = graph.load_commit(store_handle.handles, wc)+ if wc_loaded is some wl {+ if @len(wl.c.parents) == 1 {+ val parent0 = @get(wl.c.parents, 0)+ if parent0 is some p0 {+ if objid.Id.eql(p0, target)+ && objid.Id.eql(wl.c.root_tree, new_root)+ && wl.c.message.len == 0 {+ same_target = true+ }+ }+ }+ graph.free_loaded(wl)+ } } } if !same_target {@@ -1621,12 +1687,33 @@ if have_wc { viewops.remove_head(tx.view, wc) }- viewops.set_workspace(tx.view, target)+ val child_opt = create_working_copy_commit(tx, repo, target)+ val child: mut objid.Id = objid.id_none()+ val have_child: mut bool = false+ if child_opt is some cid {+ child = cid+ have_child = true+ }+ if !have_child {+ txn.abort(tx)+ store.close(store_handle)+ free_id(target)+ free_id(new_root)+ if have_wc {+ free_id(wc)+ }+ if old_root is some or3 {+ free_id(or3)+ }+ return 1+ }+ viewops.set_workspace(tx.view, child) viewops.rebuild_heads(tx.view) val op_status: i32 = txn.finish(tx, bytes.bytes(c"checkout", 8)) if op_status != 0 { status = op_status }+ free_id(child) } store.close(store_handle)--- a/xveins/src/cli.cpp+++ b/xveins/src/cli.cpp@@ -578,6 +578,23 @@ std::string rev; bool col_titles = true; bool end_flags = false;+ std::optional<std::size_t> limit;+ bool first = false;+ auto parse_count = [](std::string_view text,+ std::size_t &out) -> bool {+ if (text.empty())+ return false;+ std::size_t value = 0;+ for (char c : text) {+ if (c < '0' || c > '9')+ return false;+ value = value * 10 + static_cast<std::size_t>(c - '0');+ }+ if (value == 0)+ return false;+ out = value;+ return true;+ }; for (std::size_t i = 2; i < args.size(); ++i) { const std::string &arg = args[i]; if (!end_flags && arg == "--") {@@ -591,6 +608,39 @@ rev = args[++i]; } else if (!end_flags && arg == "-no-col-titles") { col_titles = false;+ } else if (!end_flags && (arg == "-l" || arg == "-f")) {+ if (i + 1 >= args.size()) {+ error_prefix();+ std::cout << arg << " requires a count\n";+ return 1;+ }+ std::size_t count = 0;+ if (!parse_count(args[++i], count)) {+ error_prefix();+ std::cout << arg << " requires a positive count\n";+ return 1;+ }+ limit = count;+ first = arg == "-f";+ } else if (!end_flags && arg.size() > 2 &&+ (arg[0] == '-' && (arg[1] == 'l' || arg[1] == 'f'))) {+ std::size_t count = 0;+ if (!parse_count(std::string_view(arg).substr(2), count)) {+ error_prefix();+ std::cout << "invalid log count: " << arg << "\n";+ return 1;+ }+ limit = count;+ first = arg[1] == 'f';+ } else if (!end_flags && arg.size() > 1 &&+ (arg[0] == 'l' || arg[0] == 'f')) {+ std::size_t count = 0;+ if (parse_count(std::string_view(arg).substr(1), count)) {+ limit = count;+ first = arg[0] == 'f';+ } else {+ rev = arg;+ } } else if (!end_flags && is_flag(arg)) { error_prefix(); std::cout << "unknown flag: " << arg << "\n";@@ -651,6 +701,17 @@ return a.seconds > b.seconds; }); + if (limit) {+ if (first) {+ if (recs.size() > *limit)+ recs.erase(recs.begin(),+ recs.end() - static_cast<std::ptrdiff_t>(*limit));+ std::reverse(recs.begin(), recs.end());+ } else if (recs.size() > *limit) {+ recs.resize(*limit);+ }+ }+ std::vector<std::string> change_ids; for (const auto &rec : recs) change_ids.push_back(rec.change);@@ -1973,10 +2034,12 @@ } void show_log() {- std::cout << "usage: vn log [-rev <revset>] [-no-col-titles]\n\n";+ std::cout << "usage: vn log [-rev <revset>] [-lN | -fN] [-no-col-titles]\n\n"; std::cout << "show commit history, newest first\n\n"; std::cout << "options:\n"; std::cout << " -rev <revset> show only the given revision set\n";+ std::cout << " -lN, -l <N> show the last N commits (newest N)\n";+ std::cout << " -fN, -f <N> show the first N commits (oldest N)\n"; std::cout << " -no-col-titles omit column titles\n"; } --- a/xveins/src/net_commands.cpp+++ b/xveins/src/net_commands.cpp@@ -157,8 +157,13 @@ } rebuild_heads(tx->view()); if (clone) {- if (auto target = default_target(refs))- set_workspace(tx->view(), *target);+ if (auto target = default_target(refs)) {+ auto child = create_working_copy_commit(*tx, *target);+ if (!child)+ return false;+ set_workspace(tx->view(), *child);+ rebuild_heads(tx->view());+ } } return tx->finish("clone").has_value(); }--- a/xveins/src/worktree.cpp+++ b/xveins/src/worktree.cpp@@ -919,6 +919,21 @@ } clear_stat_cache(root); return 0;+}++std::optional<Id> create_working_copy_commit(Txn &tx, const Id &parent) {+ auto loaded = load_commit(tx.store(), parent);+ if (!loaded)+ return std::nullopt;+ Commit commit;+ commit.version = 1;+ commit.parents = {parent};+ commit.root_tree = loaded->commit.root_tree;+ commit.change_id = random_change_id();+ commit.author = identity_signature(tx.store().root());+ commit.committer = commit.author;+ commit.renames_state = RENAMES_RECORDED;+ return tx.add_object(TYPE_COMMIT, encode_commit(commit)); } int checkout_run(const fs::path &root, std::string_view rev) {@@ -970,19 +985,36 @@ return materialized; if (!wc || std::memcmp(wc->data(), target->data(), ID_LEN) != 0) {- auto tx = Txn::begin(root, store);- if (!tx) {- error_prefix();- std::cout << "cannot load repository state\n";- return 1;+ bool already_empty_child = false;+ if (wc) {+ auto wc_loaded = load_commit(store, *wc);+ if (wc_loaded && wc_loaded->commit.parents.size() == 1 &&+ std::memcmp(wc_loaded->commit.parents.front().data(), target->data(),+ ID_LEN) == 0 &&+ std::memcmp(wc_loaded->commit.root_tree.data(),+ commit->root_tree.data(), ID_LEN) == 0 &&+ wc_loaded->commit.message.empty()) {+ already_empty_child = true;+ } }- if (wc)- remove_head(tx->view(), *wc);- set_workspace(tx->view(), *target);- rebuild_heads(tx->view());- const auto status = tx->finish("checkout");- if (!status)- return 1;+ if (!already_empty_child) {+ auto tx = Txn::begin(root, store);+ if (!tx) {+ error_prefix();+ std::cout << "cannot load repository state\n";+ return 1;+ }+ if (wc)+ remove_head(tx->view(), *wc);+ auto child = create_working_copy_commit(*tx, *target);+ if (!child)+ return 1;+ set_workspace(tx->view(), *child);+ rebuild_heads(tx->view());+ const auto status = tx->finish("checkout");+ if (!status)+ return 1;+ } } return 0; }--- a/xveins/src/worktree.h+++ b/xveins/src/worktree.h@@ -11,6 +11,7 @@ int snapshot_run(const fs::path &root, Store &store); int checkout_run(const fs::path &root, std::string_view rev);+std::optional<Id> create_working_copy_commit(Txn &tx, const Id &parent); int checkout_materialize_commit(const fs::path &root, Store &store, std::optional<Id> old_root, const Id &new_root); int checkout_materialize_optional(const fs::path &root, Store &store,