navid/veins / commit
9892cd4abd2c
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: 849788d17ec4
Browse files at this commit · Download source
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -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 co <bookmark>` and `vn bmk set <name>` set the current bookmark, stored as `bookmark.current` in local config. Snapshots, `describe`, and `go` advance the current bookmark, and `vn push <remote>` uses it when no bookmark argument is given.+`vn co <bookmark>` and `vn bmk set <name>` set the current bookmark, stored as `bookmark.current` in local config. `vn clone` and `vn git import` initialize it from the default branch (the checked-out or imported `HEAD`). Snapshots, `describe`, and `go` advance the current bookmark, and `vn push <remote>` uses it when no bookmark argument is given. `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. --- a/docs/SPECIFICATION_V1.html+++ b/docs/SPECIFICATION_V1.html@@ -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 co <bookmark></code> and <code>vn bmk set <name></code> set the current bookmark, stored as <code>bookmark.current</code> in local config. Snapshots, <code>describe</code>, and <code>go</code> advance the current bookmark, and <code>vn push <remote></code> uses it when no bookmark argument is given.</p>+<p><code>vn co <bookmark></code> and <code>vn bmk set <name></code> set the current bookmark, stored as <code>bookmark.current</code> in local config. <code>vn clone</code> and <code>vn git import</code> initialize it from the default branch (the checked-out or imported <code>HEAD</code>). Snapshots, <code>describe</code>, and <code>go</code> advance the current bookmark, and <code>vn push <remote></code> uses it when no bookmark argument is given.</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>. <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>@@ -3429,7 +3429,7 @@ <div id="footer"> <div id="footer-text"> Version 0.1-draft<br>-Last updated 2026-11-28 00:59:08 UTC+Last updated 2026-11-28 01:19:24 UTC </div> </div> </body>--- a/veins/src/git/import.sx+++ b/veins/src/git/import.sx@@ -27,6 +27,7 @@ val txn = use("../store/txn.sx") val viewops = use("../store/viewops.sx") val identity = use("../core/identity.sx")+val repoconfig = use("../core/repoconfig.sx") val files = use("../io/files.sx") val object = use("object.sx") val lazy = use("lazy.sx")@@ -673,6 +674,55 @@ @free(rp) } @listfree(xs)+}++fn pick_current_branch(+ branches: list[ref ImportNamedTarget],+ head_commit: option[bytes.Bytes]+) option[bytes.Bytes] = trust {+ val fallback: mut option[bytes.Bytes] = none+ if head_commit is some hc {+ for b in branches {+ if bytes.Bytes.eql(b.oid, hc) {+ if bytes.Bytes.eql(b.name, bytes.bytes(c"main", 4))+ || bytes.Bytes.eql(b.name, bytes.bytes(c"master", 6)) {+ return some b.name+ }+ if fallback is none {+ fallback = some b.name+ }+ }+ }+ if fallback is some f {+ return some f+ }+ }+ for b in branches {+ if bytes.Bytes.eql(b.name, bytes.bytes(c"main", 4))+ || bytes.Bytes.eql(b.name, bytes.bytes(c"master", 6)) {+ return some b.name+ }+ }+ if @len(branches) > 0 {+ val first = @get(branches, 0)+ if first is some b {+ return some b.name+ }+ }+ return none+}++fn apply_current_bookmark(+ repo: layout.Repo,+ branches: list[ref ImportNamedTarget],+ head_commit: option[bytes.Bytes]+) void = trust {+ val current = pick_current_branch(branches, head_commit)+ if current is some name {+ val _ = repoconfig.set_current_bookmark(repo, name)+ } else {+ val _ = repoconfig.clear_current_bookmark(repo)+ } } @@ -1320,6 +1370,7 @@ val np: mut ref void = new_encoded.ptr as ref void @free(np) }+ apply_current_bookmark(repo, branches, head_commit) clear_view_view(v, !view_from_store) free_commit_records(records) free_named_targets(branches)@@ -1441,6 +1492,7 @@ val _ = state.delete_head(repo, ph3) } }+ apply_current_bookmark(repo, branches, head_commit) } msg.info_prefix()--- a/xveins/src/git.cpp+++ b/xveins/src/git.cpp@@ -758,7 +758,32 @@ head_commit = peel_to_commit(*repo, *refset.head); if (head_commit) tips.push_back(*head_commit);+ }++ std::optional<std::string> current_branch;+ if (head_commit) {+ std::optional<std::string> match;+ for (const auto &branch : branches) {+ if (std::memcmp(branch.oid.data(), head_commit->data(),+ head_commit->size()) != 0)+ continue;+ if (branch.name == "main" || branch.name == "master")+ match = branch.name;+ else if (!match)+ match = branch.name;+ }+ current_branch = match;+ }+ if (!current_branch) {+ for (const auto &branch : branches) {+ if (branch.name == "main" || branch.name == "master") {+ current_branch = branch.name;+ break;+ }+ } }+ if (!current_branch && !branches.empty())+ current_branch = branches.front().name; std::vector<CommitRecord> records; std::set<Oid, OidLess> seen;@@ -935,6 +960,10 @@ const bool has_new_objects = new_commits > 0 || new_trees > 0 || new_blobs > 0; if (unchanged && !has_new_objects) {+ if (current_branch)+ (void)set_current_bookmark(root, *current_branch);+ else+ (void)clear_current_bookmark(root); info_prefix(); std::cout << "already up to date\n"; return 0;@@ -945,6 +974,10 @@ std::cout << "failed to write object pack\n"; return 1; }+ if (current_branch)+ (void)set_current_bookmark(root, *current_branch);+ else+ (void)clear_current_bookmark(root); for (const auto &raw : raw_saves) (void)git::save_raw(root, raw.first, Bytes(raw.second.data(), raw.second.size()));