navid/veins / commit
849788d17ec4
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: 445d1f5a8870
Browse files at this commit · Download source
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -1094,7 +1094,7 @@ | `vn regenerate` | Run configured regeneration commands for `merge=regenerate` paths. | `vn undo`, `vn op log`, `vn op restore <op>`, `vn op revert <op>` | Operation log commands. | `vn bookmark set\|list\|delete`, `vn tag set\|ls\|rm\|latest` | Manage named pointers.-| `vn fetch`, `vn push` | Native protocol.+| `vn fetch`, `vn push [<remote>] [<bookmark>]` | Native protocol; `push` uses the current bookmark when omitted. | `vn git import [-source:<gitdir>] [path]`, `vn git export`, `vn git materialize [path]`, `vn git fetch`, `vn git push`, `vn git remote` | Git bridge. | `vn serve -stdio <repo>`, `vn serve -listen <addr:port> -root <dir> ...` | Run the native server over stdio or TLS. | `vn key generate\|list\|show\|import` | Manage client keys.@@ -1106,6 +1106,8 @@ |=== `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 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@@ -2995,8 +2995,8 @@ <td class="tableblock halign-left valign-top"><p class="tableblock">Manage named pointers.</p></td> </tr> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn fetch</code>, <code>vn push</code></p></td>-<td class="tableblock halign-left valign-top"><p class="tableblock">Native protocol.</p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn fetch</code>, <code>vn push [<remote>] [<bookmark>]</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock">Native protocol; <code>push</code> uses the current bookmark when omitted.</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn git import [-source:<gitdir>] [path]</code>, <code>vn git export</code>, <code>vn git materialize [path]</code>, <code>vn git fetch</code>, <code>vn git push</code>, <code>vn git remote</code></p></td>@@ -3036,6 +3036,9 @@ <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>+</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> </div> <div class="paragraph">@@ -3426,7 +3429,7 @@ <div id="footer"> <div id="footer-text"> Version 0.1-draft<br>-Last updated 2026-11-28 00:44:52 UTC+Last updated 2026-11-28 00:59:08 UTC </div> </div> </body>--- a/veins/src/cli/bookmark_cmd.sx+++ b/veins/src/cli/bookmark_cmd.sx@@ -5,24 +5,25 @@ /// switches the working copy to it. Rewriting a working-copy commit (through a /// snapshot, `describe`, or `rm`) moves any bookmark that named that commit. -val str = use("std/string")-val stdio = use("std/stdio")-val msg = use("../core/msg.sx")-val terminal = use("std/terminal")-val bytes = use("../core/bytes.sx")-val buf = use("../core/buf.sx")-val lists = use("../core/lists.sx")-val prim = use("../core/primitives.sx")-val objid = use("../object/id.sx")-val view = use("../object/view.sx")-val graph = use("../object/graph.sx")-val changeid = use("../object/changeid.sx")-val store = use("../store/store.sx")-val layout = use("../store/layout.sx")-val state = use("../store/state.sx")-val txn = use("../store/txn.sx")-val viewops = use("../store/viewops.sx")-val snapshot = use("../worktree/snapshot.sx")+val str = use("std/string")+val stdio = use("std/stdio")+val msg = use("../core/msg.sx")+val terminal = use("std/terminal")+val bytes = use("../core/bytes.sx")+val buf = use("../core/buf.sx")+val lists = use("../core/lists.sx")+val prim = use("../core/primitives.sx")+val objid = use("../object/id.sx")+val view = use("../object/view.sx")+val graph = use("../object/graph.sx")+val changeid = use("../object/changeid.sx")+val store = use("../store/store.sx")+val layout = use("../store/layout.sx")+val state = use("../store/state.sx")+val repoconfig = use("../core/repoconfig.sx")+val txn = use("../store/txn.sx")+val viewops = use("../store/viewops.sx")+val snapshot = use("../worktree/snapshot.sx") fn cmd_is(a: ref u8, text: ref u8, len: usize) bool = trust { return bytes.Bytes.eql(bytes.from_cstr(a), bytes.bytes(text, len))@@ -297,6 +298,7 @@ } if !changed {+ val _ = repoconfig.set_current_bookmark(repo, name) msg.info_prefix() stdio.print( "bookmark {s} is already at {s}\n",@@ -312,6 +314,7 @@ val description: bytes.Bytes = make_description(bytes.bytes(c"bookmark set", 12), name) val status: i32 = txn.finish(tx, description) if status == 0 {+ val _ = repoconfig.set_current_bookmark(repo, name) msg.info_prefix() stdio.print( "bookmark {s} set to {s}\n",@@ -390,6 +393,13 @@ val description: bytes.Bytes = make_description(bytes.bytes(c"bookmark delete", 15), name) val status: i32 = txn.finish(tx, description) if status == 0 {+ val cur = repoconfig.current_bookmark(repo)+ if cur is some cname {+ if bytes.Bytes.eql(cname, name) {+ val _ = repoconfig.clear_current_bookmark(repo)+ }+ bytes.free_owned(cname)+ } msg.info_prefix() stdio.print("deleted bookmark {s}\n", {str.view(name.ptr, name.len as i64)}) }--- a/veins/src/cli/cfg_cmd.sx+++ b/veins/src/cli/cfg_cmd.sx@@ -97,55 +97,51 @@ val path: str.StringView = layout.config_path(repo) val data_opt = files.read_all(path) files.free_path(path)- match data_opt {- some data => {- val pos: mut usize = 0- val start: mut usize = 0- for pos <= data.len {- val at_end: bool = pos == data.len- if at_end || bytes.Bytes.at(data, pos) == 10 {- val line: bytes.Bytes = trim(- bytes.Bytes.slice(data, start, pos)- )- if line.len > 0 && bytes.Bytes.at(line, 0) != 35 {- val eq: mut i64 = -1- val i: mut usize = 0- for i < line.len {- if bytes.Bytes.at(line, i) == 61 {- eq = i as i64- break- }- i+++ if data_opt is some data {+ val pos: mut usize = 0+ val start: mut usize = 0+ for pos <= data.len {+ val at_end: bool = pos == data.len+ if at_end || bytes.Bytes.at(data, pos) == 10 {+ val line: bytes.Bytes = trim(+ bytes.Bytes.slice(data, start, pos)+ )+ if line.len > 0 && bytes.Bytes.at(line, 0) != 35 {+ val eq: mut i64 = -1+ val i: mut usize = 0+ for i < line.len {+ if bytes.Bytes.at(line, i) == 61 {+ eq = i as i64+ break }- if eq >= 0 {- val key: bytes.Bytes = trim(- bytes.Bytes.slice(line, 0, eq as usize)- )- if key.len > 0 {- val value: bytes.Bytes = trim(- bytes.Bytes.slice(- line,- eq as usize + 1,- line.len- )+ i+++ }+ if eq >= 0 {+ val key: bytes.Bytes = trim(+ bytes.Bytes.slice(line, 0, eq as usize)+ )+ if key.len > 0 {+ val value: bytes.Bytes = trim(+ bytes.Bytes.slice(+ line,+ eq as usize + 1,+ line.len )- val kv: mut ref prim.KeyValue = @alloc(- @sizeof(prim.KeyValue)- ) as ref prim.KeyValue- kv.key = bytes.Bytes.dup(key)- kv.value = bytes.Bytes.dup(value)- @append(entries, kv)- }+ )+ val kv: mut ref prim.KeyValue = @alloc(+ @sizeof(prim.KeyValue)+ ) as ref prim.KeyValue+ kv.key = bytes.Bytes.dup(key)+ kv.value = bytes.Bytes.dup(value)+ @append(entries, kv) } }- start = pos + 1 }- pos+++ start = pos + 1 }- files.free_buffer(data)- }- none => {+ pos++ }+ files.free_buffer(data) } sort_entries(entries) return entries@@ -276,11 +272,11 @@ end_flags = true } elif !end_flags && (cmd_is(a, c"-global", 7) || cmd_is(a, c"--global", 8)- || cmd_is(a, c"-g", 2)) {+ || cmd_is(a, c"-g", 2)) { global = true } elif !end_flags && (cmd_is(a, c"-list", 5) || cmd_is(a, c"--list", 6)- || cmd_is(a, c"-l", 2)) {+ || cmd_is(a, c"-l", 2)) { list = true } elif !end_flags && (cmd_is(a, c"-unset", 6) || cmd_is(a, c"--unset", 7)) { unset = true--- a/veins/src/cli/git_cmd.sx+++ b/veins/src/cli/git_cmd.sx@@ -1,16 +1,16 @@ /// `vn git`: the git bridge. M1 provides `import`. -val str = use("std/string")-val bytes = use("../core/bytes.sx")-val stdio = use("std/stdio")-val msg = use("../core/msg.sx")-val layout = use("../store/layout.sx")-val mirror = use("../git/mirror.sx")-val import = use("../git/import.sx")-val export = use("../git/export.sx")+val str = use("std/string")+val bytes = use("../core/bytes.sx")+val stdio = use("std/stdio")+val msg = use("../core/msg.sx")+val layout = use("../store/layout.sx")+val mirror = use("../git/mirror.sx")+val import = use("../git/import.sx")+val export = use("../git/export.sx") val materialize = use("../git/materialize.sx")-val remote = use("../git/remote.sx")-val config = use("../core/repoconfig.sx")+val remote = use("../git/remote.sx")+val config = use("../core/repoconfig.sx") pub fn run(args: list[ref u8], start: usize) i32 = trust { val sub_opt = @get(args, start)--- a/veins/src/cli/help_cmd.sx+++ b/veins/src/cli/help_cmd.sx@@ -431,10 +431,11 @@ } fn show_push() void = trust {- stdio.puts("usage: vn push [-key:<name>] [<remote>] <bookmark> [path]")+ stdio.puts("usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]") stdio.puts("") stdio.puts("push a bookmark to a configured native remote") stdio.puts("")+ stdio.puts("without <bookmark>, the current bookmark is pushed") stdio.puts("auth falls back to remote.<name>.key, then 'vn auth use'") } --- a/veins/src/cli/new_cmd.sx+++ b/veins/src/cli/new_cmd.sx@@ -1,25 +1,26 @@ /// `vn desc` (alias `vn describe`), `vn new`, and `vn go` (alias `vn commit`). -val stdio = use("std/stdio")-val msg = use("../core/msg.sx")-val bytes = use("../core/bytes.sx")-val buf = use("../core/buf.sx")-val lists = use("../core/lists.sx")-val prim = use("../core/primitives.sx")-val random = use("std/crypto/random")-val objid = use("../object/id.sx")-val types = use("../object/types.sx")-val commit = use("../object/commit.sx")-val graph = use("../object/graph.sx")-val view = use("../object/view.sx")-val store = use("../store/store.sx")-val layout = use("../store/layout.sx")-val txn = use("../store/txn.sx")-val viewops = use("../store/viewops.sx")-val identity = use("../core/identity.sx")-val gitmap = use("../git/map.sx")-val snapshot = use("../worktree/snapshot.sx")-val checkout = use("../worktree/checkout.sx")+val stdio = use("std/stdio")+val msg = use("../core/msg.sx")+val bytes = use("../core/bytes.sx")+val buf = use("../core/buf.sx")+val lists = use("../core/lists.sx")+val prim = use("../core/primitives.sx")+val random = use("std/crypto/random")+val objid = use("../object/id.sx")+val types = use("../object/types.sx")+val commit = use("../object/commit.sx")+val graph = use("../object/graph.sx")+val view = use("../object/view.sx")+val store = use("../store/store.sx")+val layout = use("../store/layout.sx")+val txn = use("../store/txn.sx")+val viewops = use("../store/viewops.sx")+val identity = use("../core/identity.sx")+val gitmap = use("../git/map.sx")+val repoconfig = use("../core/repoconfig.sx")+val snapshot = use("../worktree/snapshot.sx")+val checkout = use("../worktree/checkout.sx") val NOTHING_TO_COMMIT: i32 = 2 @@ -191,6 +192,9 @@ nc.change_id = lc.c.change_id nc.author = lc.c.author nc.committer = sig+ if !changed {+ nc.author = sig+ } nc.message = message nc.renames_state = lc.c.renames_state nc.renames = renames@@ -201,6 +205,13 @@ // Repointing a bookmark at the rewritten working-copy commit is what makes // an edited named branch advance with its commit. viewops.move_bookmarks(tx.view, wc, new_id)+ val current = repoconfig.current_bookmark(repo)+ if current is some name {+ if viewops.find_bookmark(tx.view, name) is some _ {+ viewops.set_bookmark(tx.view, name, new_id)+ }+ bytes.free_owned(name)+ } viewops.set_workspace(tx.view, new_id) viewops.rebuild_heads(tx.view) val status: i32 = txn.finish(tx, bytes.bytes(c"describe", 8))--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -11,6 +11,7 @@ val state = use("../store/state.sx") val layout = use("../store/layout.sx") val remote_config = use("../git/remote.sx")+val repoconfig = use("../core/repoconfig.sx") val credentials = use("../auth/credentials.sx") val client = use("../protocol/client.sx") val transfer = use("../protocol/transfer.sx")@@ -82,11 +83,6 @@ } } i++- }- if bookmark.ptr == none {- cmsg.error_prefix()- stdio.eprint("push requires a bookmark name\n", {})- return 1 } val repo_opt = layout.discover(path) val repo: mut layout.Repo = layout.Repo{root: bytes.empty()}@@ -98,7 +94,19 @@ cmsg.error_prefix() stdio.eprint("not a veins repository\n", {}) return 1+ }+ }+ if bookmark.ptr == none {+ val cur = repoconfig.current_bookmark(repo)+ if cur is some name {+ bookmark = name }+ }+ if bookmark.ptr == none {+ cmsg.error_prefix()+ stdio.eprint("push requires a bookmark name (or a current bookmark)\n", {})+ layout.free_repo(repo)+ return 1 } val url_opt = remote_config.url_of(repo, remote_name) if url_opt is none {--- a/veins/src/cli/remote_cmd.sx+++ b/veins/src/cli/remote_cmd.sx@@ -12,7 +12,13 @@ return bytes.Bytes.eql(bytes.from_cstr(a), bytes.bytes(text, len)) } -fn set_field(repo: layout.Repo, name: bytes.Bytes, field: ref u8, field_len: usize, value: bytes.Bytes) bool = trust {+fn set_field(+ repo: layout.Repo,+ name: bytes.Bytes,+ field: ref u8,+ field_len: usize,+ value: bytes.Bytes+) bool = trust { val key: bytes.Bytes = remote.key_for(name, bytes.bytes(field, field_len)) val passed: bool = config.set(repo, key, value) bytes.free_owned(key)--- a/veins/src/core/repoconfig.sx+++ b/veins/src/core/repoconfig.sx@@ -119,6 +119,18 @@ /// Read a text key. The result is owned by the caller. pub fn get_text(repo: layout.Repo, key: bytes.Bytes) option[bytes.Bytes] = trust { return get(repo, key)+}++pub fn current_bookmark(repo: layout.Repo) option[bytes.Bytes] = trust {+ return get(repo, bytes.bytes(c"bookmark.current", 16))+}++pub fn set_current_bookmark(repo: layout.Repo, name: bytes.Bytes) bool = trust {+ return set(repo, bytes.bytes(c"bookmark.current", 16), name)+}++pub fn clear_current_bookmark(repo: layout.Repo) bool = trust {+ return remove(repo, bytes.bytes(c"bookmark.current", 16)) } /// Set a key, replacing an existing value. The file is rewritten atomically.--- a/veins/src/core/userconfig.sx+++ b/veins/src/core/userconfig.sx@@ -349,12 +349,12 @@ } } else { if (want_name- && bytes.Bytes.eql(name, bytes.bytes(c"user.name", 9)))+ && bytes.Bytes.eql(name, bytes.bytes(c"user.name", 9))) || (want_email- && bytes.Bytes.eql(- name,- bytes.bytes(c"user.email", 10)- )) {+ && bytes.Bytes.eql(+ name,+ bytes.bytes(c"user.email", 10)+ )) { keep = false } }--- a/veins/src/git/materialize.sx+++ b/veins/src/git/materialize.sx@@ -109,15 +109,11 @@ fn record_raw(ctx: mut MatCtx, old_id: objid.Id, new_id: objid.Id) void = trust { val raw_opt = gitmap.load_raw(ctx.repo, old_id)- match raw_opt {- some body => {- val rs: mut ref RawSave = @alloc(@sizeof(RawSave)) as ref RawSave- rs.id = copy_id(new_id)- rs.body = body- @append(ctx.raw_saves, rs)- }- none => {- }+ if raw_opt is some body {+ val rs: mut ref RawSave = @alloc(@sizeof(RawSave)) as ref RawSave+ rs.id = copy_id(new_id)+ rs.body = body+ @append(ctx.raw_saves, rs) } } --- a/veins/src/protocol/transfer.sx+++ b/veins/src/protocol/transfer.sx@@ -1,23 +1,24 @@ /// View construction and chunk selection shared by clone and fetch. -val bytes = use("../core/bytes.sx")-val lists = use("../core/lists.sx")-val objid = use("../object/id.sx")-val types = use("../object/types.sx")-val tree = use("../object/tree.sx")-val blob = use("../object/blob.sx")-val conflict = use("../object/conflict.sx")-val graph = use("../object/graph.sx")-val store = use("../store/store.sx")-val state = use("../store/state.sx")-val layout = use("../store/layout.sx")-val idmap = use("../store/idmap.sx")-val txnmod = use("../store/txn.sx")-val viewops = use("../store/viewops.sx")-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")+val bytes = use("../core/bytes.sx")+val lists = use("../core/lists.sx")+val objid = use("../object/id.sx")+val types = use("../object/types.sx")+val tree = use("../object/tree.sx")+val blob = use("../object/blob.sx")+val conflict = use("../object/conflict.sx")+val graph = use("../object/graph.sx")+val store = use("../store/store.sx")+val state = use("../store/state.sx")+val layout = use("../store/layout.sx")+val idmap = use("../store/idmap.sx")+val txnmod = use("../store/txn.sx")+val viewops = use("../store/viewops.sx")+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")+val repoconfig = use("../core/repoconfig.sx") type ChunkWalk = { handles: mut list[ref store.Handle]@@ -302,6 +303,23 @@ for r in refs { if r.kind == 0 { return some objid.id(r.target.ptr)+ }+ }+ return none+}++pub fn default_ref_name(refs: list[msg_refs.RefInfo]) option[bytes.Bytes] = trust {+ for r in refs {+ if r.kind == 0 && (bytes.Bytes.eql(+ r.name,+ bytes.bytes(c"main", 4)+ ) || bytes.Bytes.eql(r.name, bytes.bytes(c"master", 6))) {+ return some r.name+ }+ }+ for r in refs {+ if r.kind == 0 {+ return some r.name } } return none@@ -361,5 +379,14 @@ } } }- return txnmod.finish(tx, bytes.bytes(c"clone", 5))+ val status: i32 = txnmod.finish(tx, bytes.bytes(c"clone", 5))+ if status == 0 && clone {+ val name_opt = default_ref_name(refs)+ if name_opt is some name {+ val _ = repoconfig.set_current_bookmark(repo, name)+ } else {+ val _ = repoconfig.clear_current_bookmark(repo)+ }+ }+ return status }--- a/veins/src/store/viewops.sx+++ b/veins/src/store/viewops.sx@@ -164,6 +164,25 @@ i++ } return none+}++pub fn set_bookmark(v: ref view.View, name: bytes.Bytes, id: objid.Id) void = trust {+ val idx = find_bookmark(v, name)+ if idx is some i {+ val o = @get(v.bookmarks, i)+ if o is some bm {+ @listfree(bm.targets.adds)+ @listfree(bm.targets.removes)+ bm.targets = view.empty_target_set()+ @append(bm.targets.adds, copy_id(id))+ }+ return+ }+ val bm2: mut ref view.Bookmark = @alloc(@sizeof(view.Bookmark)) as ref view.Bookmark+ bm2.name = bytes.Bytes.dup(name)+ bm2.targets = view.empty_target_set()+ @append(bm2.targets.adds, copy_id(id))+ @append(v.bookmarks, bm2) } pub fn sort_bookmarks(xs: mut list[ref view.Bookmark]) void = trust {--- a/veins/src/worktree/checkout.sx+++ b/veins/src/worktree/checkout.sx@@ -1620,6 +1620,15 @@ val wc: mut objid.Id = objid.id_none() val have_wc: mut bool = false val old_root: mut option[objid.Id] = none+ val bookmark_checkout: mut bool = false+ val detach_bookmark: mut bool = false+ if rev.len > 0 && !bytes.Bytes.eql(rev, bytes.bytes(c"@", 1)) {+ if viewops.find_bookmark(v, rev) is some _ {+ bookmark_checkout = true+ } else {+ detach_bookmark = true+ }+ } if wc_opt is some id2 { wc = id2 have_wc = true@@ -1717,6 +1726,13 @@ } store.close(store_handle)+ if status == 0 {+ if bookmark_checkout {+ val _ = repoconfig.set_current_bookmark(repo, rev)+ } elif detach_bookmark {+ val _ = repoconfig.clear_current_bookmark(repo)+ }+ } free_id(target) free_id(new_root) if have_wc {--- a/veins/src/worktree/snapshot.sx+++ b/veins/src/worktree/snapshot.sx@@ -21,6 +21,7 @@ val commit = use("../object/commit.sx") val blob = use("../object/blob.sx") val treewalk = use("../object/treewalk.sx")+val graph = use("../object/graph.sx") val store = use("../store/store.sx") val layout = use("../store/layout.sx") val state = use("../store/state.sx")@@ -1007,11 +1008,26 @@ val committer: prim.Sig = identity.signature(repo) val author: mut prim.Sig = committer+ val old_empty: mut bool = false+ if c != none {+ if @len(c.parents) == 1 {+ val p0 = @get(c.parents, 0)+ if p0 is some pid {+ val parent_opt = graph.load_commit(handles, pid)+ if parent_opt is some parent {+ old_empty = objid.Id.eql(c.root_tree, parent.c.root_tree)+ graph.free_loaded(parent)+ }+ }+ }+ } val parents: mut list[objid.Id] = lists.new[objid.Id]() val change_id: mut objid.ChangeId = objid.change_id(none) val message: mut bytes.Bytes = bytes.empty() if c != none {- author = c.author+ if !old_empty {+ author = c.author+ } for p in c.parents { @append(parents, copy_id(p)) }@@ -1091,6 +1107,13 @@ remove_wc_head(tx.view, wc) // A bookmark that named the amended commit follows it. viewops.move_bookmarks(tx.view, wc, new_commit)+ }+ val current = repoconfig.current_bookmark(repo)+ if current is some name {+ if viewops.find_bookmark(tx.view, name) is some _ {+ viewops.set_bookmark(tx.view, name, new_commit)+ }+ bytes.free_owned(name) } viewops.set_workspace(tx.view, new_commit) viewops.rebuild_heads(tx.view)--- a/xveins/src/bookmark.cpp+++ b/xveins/src/bookmark.cpp@@ -149,6 +149,7 @@ } if (!changed) {+ (void)set_current_bookmark(*root, name); info_prefix(); std::cout << "bookmark " << name << " is already at " << short_commit(*target) << "\n";@@ -159,6 +160,7 @@ const auto status = tx->finish("bookmark set " + name); if (!status) return 1;+ (void)set_current_bookmark(*root, name); info_prefix(); std::cout << "bookmark " << name << " set to " << short_commit(*target) << "\n";@@ -216,6 +218,8 @@ const auto status = tx->finish("bookmark delete " + name); if (!status) return 1;+ if (auto current = current_bookmark_name(*root); current && *current == name)+ (void)clear_current_bookmark(*root); info_prefix(); std::cout << "deleted bookmark " << name << "\n"; return 0;--- a/xveins/src/cli.cpp+++ b/xveins/src/cli.cpp@@ -1252,11 +1252,17 @@ const Sig sig = identity_signature(root); Commit commit = loaded->commit; commit.committer = sig;+ if (!changed)+ commit.author = sig; commit.message = message; const auto encoded = encode_commit(commit); const Id new_id = tx->add_object(TYPE_COMMIT, encoded); remove_head(tx->view(), *wc); move_bookmarks(tx->view(), *wc, new_id);+ if (auto current = current_bookmark_name(root)) {+ if (find_bookmark(tx->view(), *current))+ set_bookmark_target(tx->view(), *current, new_id);+ } set_workspace(tx->view(), new_id); rebuild_heads(tx->view()); const auto status = tx->finish("describe");--- a/xveins/src/common.cpp+++ b/xveins/src/common.cpp@@ -1485,6 +1485,20 @@ bool user_config_remove(std::string_view key) { return update_user_config(key, std::nullopt);+}++std::optional<std::string> current_bookmark_name(const fs::path &repo_root) {+ return repo_config_value(repo_root, "bookmark.current");+}++bool set_current_bookmark(const fs::path &repo_root, std::string_view name) {+ if (name.empty())+ return repo_config_remove(repo_root, "bookmark.current");+ return repo_config_set(repo_root, "bookmark.current", name);+}++bool clear_current_bookmark(const fs::path &repo_root) {+ return repo_config_remove(repo_root, "bookmark.current"); } static std::optional<std::string> env_value(const char *name) {--- a/xveins/src/common.h+++ b/xveins/src/common.h@@ -386,6 +386,10 @@ std::optional<std::string> user_config_author_email(); bool user_config_set(std::string_view key, std::string_view value); bool user_config_remove(std::string_view key);++std::optional<std::string> current_bookmark_name(const fs::path &repo_root);+bool set_current_bookmark(const fs::path &repo_root, std::string_view name);+bool clear_current_bookmark(const fs::path &repo_root); // --------------------------------------------------------------------------- // Ignore rules--- a/xveins/src/net_commands.cpp+++ b/xveins/src/net_commands.cpp@@ -84,6 +84,19 @@ for (const auto &ref : refs) { if (ref.kind == 0) return ref.target;+ }+ return std::nullopt;+}++std::optional<std::string>+default_ref_name(const std::vector<proto::RefInfo> &refs) {+ for (const auto &ref : refs) {+ if (ref.kind == 0 && (ref.name == "main" || ref.name == "master"))+ return ref.name;+ }+ for (const auto &ref : refs) {+ if (ref.kind == 0)+ return ref.name; } return std::nullopt; }@@ -165,7 +178,14 @@ rebuild_heads(tx->view()); } }- return tx->finish("clone").has_value();+ const bool ok = tx->finish("clone").has_value();+ if (ok && clone) {+ if (auto name = default_ref_name(refs))+ (void)set_current_bookmark(root, *name);+ else+ (void)clear_current_bookmark(root);+ }+ return ok; } struct Walker {@@ -773,11 +793,6 @@ } else { path = arg; }- }- if (bookmark.empty()) {- error_prefix();- std::cout << "push requires a bookmark name\n";- return 1; } auto repo = discover_repo(path_from_bytes(path)); if (!repo) {@@ -786,6 +801,15 @@ return 1; } const fs::path root = *repo;+ if (bookmark.empty()) {+ if (auto current = current_bookmark_name(root))+ bookmark = *current;+ }+ if (bookmark.empty()) {+ error_prefix();+ std::cout << "push requires a bookmark name (or a current bookmark)\n";+ return 1;+ } auto url = config_value(root, remote_key(remote_name, "url")); if (!url) { error_prefix();@@ -1258,8 +1282,9 @@ return true; } if (command == "push") {- std::cout << "usage: vn push [-key:<name>] [<remote>] <bookmark> [path]\n\n";+ std::cout << "usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]\n\n"; std::cout << "push a bookmark to a configured native remote\n\n";+ std::cout << "without <bookmark>, the current bookmark is pushed\n"; std::cout << "auth falls back to remote.<name>.key, then 'vn auth use'\n"; return true; }--- a/xveins/src/store.cpp+++ b/xveins/src/store.cpp@@ -886,7 +886,19 @@ bookmark.targets.adds = {new_id}; bookmark.targets.removes.clear(); }+ }+}++void set_bookmark_target(View &view, std::string_view name, const Id &id) {+ if (auto index = find_bookmark(view, name)) {+ view.bookmarks[*index].targets.adds = {id};+ view.bookmarks[*index].targets.removes.clear();+ return; }+ Bookmark bookmark;+ bookmark.name = std::string(name);+ bookmark.targets.adds = {id};+ view.bookmarks.push_back(std::move(bookmark)); } std::optional<std::size_t> find_bookmark(const View &view,--- a/xveins/src/store.h+++ b/xveins/src/store.h@@ -220,6 +220,7 @@ void set_workspace(View &view, const Id &id); void remove_head(View &view, const Id &id); void move_bookmarks(View &view, const Id &old_id, const Id &new_id);+void set_bookmark_target(View &view, std::string_view name, const Id &id); void add_unique_head(View &view, const Id &id); std::optional<std::size_t> find_bookmark(const View &view,--- a/xveins/src/worktree.cpp+++ b/xveins/src/worktree.cpp@@ -761,6 +761,7 @@ const auto wc = working_copy_id(tx->view()); std::optional<Commit> old_commit; std::optional<Id> old_tree;+ bool old_empty = false; bool have_wc = false; if (wc) { have_wc = true;@@ -778,6 +779,16 @@ } old_commit = std::move(*decoded); old_tree = old_commit->root_tree;+ if (old_commit->parents.size() == 1) {+ auto parent_body =+ tx->store().read_body(old_commit->parents.front(), TYPE_COMMIT);+ if (parent_body) {+ auto parent_commit = decode_commit(bytes_of(*parent_body));+ if (parent_commit)+ old_empty = std::memcmp(parent_commit->root_tree.data(),+ old_commit->root_tree.data(), ID_LEN) == 0;+ }+ } } IgnoreRules rules = ignore_empty();@@ -819,7 +830,8 @@ ChangeId change_id{}; std::string message; if (old_commit) {- author = old_commit->author;+ if (!old_empty)+ author = old_commit->author; parents = old_commit->parents; change_id = old_commit->change_id; message = old_commit->message;@@ -863,6 +875,10 @@ if (have_wc) { remove_head(tx->view(), *wc); move_bookmarks(tx->view(), *wc, new_commit);+ }+ if (auto current = current_bookmark_name(root)) {+ if (find_bookmark(tx->view(), *current))+ set_bookmark_target(tx->view(), *current, new_commit); } set_workspace(tx->view(), new_commit); rebuild_heads(tx->view());@@ -954,6 +970,12 @@ error_prefix(); std::cout << "unknown revision: " << rev << "\n"; return 1;+ }+ bool bookmark_checkout = false;+ bool detach_bookmark = false;+ if (!rev.empty() && rev != "@") {+ bookmark_checkout = find_bookmark(*view, rev).has_value();+ detach_bookmark = !bookmark_checkout; } auto commit_body = store.read_body(*target, TYPE_COMMIT); if (!commit_body) {@@ -1016,6 +1038,10 @@ return 1; } }+ if (bookmark_checkout)+ (void)set_current_bookmark(root, rev);+ else if (detach_bookmark)+ (void)clear_current_bookmark(root); return 0; }