navid/veins / commit

4dfebe4c79e3

Navid M <navidmomtahen@gmail.com> · 2026-11-26

parents: 2fddc3e8c59a

Browse files at this commit · Download source

all: various bugfixes and formatting fixes
--- a/veins/src/cli/clone_cmd.sx+++ b/veins/src/cli/clone_cmd.sx@@ -1,21 +1,21 @@ /// `vn clone`: fetch a repository over the native protocol. -val stdio   = use("std/stdio")-val str     = use("std/string")-val bytes   = use("../core/bytes.sx")-val lists   = use("../core/lists.sx")-val objid   = use("../object/id.sx")-val store   = use("../store/store.sx")-val layout  = use("../store/layout.sx")-val files   = use("../io/files.sx")-val config  = use("../core/repoconfig.sx")+val stdio         = use("std/stdio")+val str           = use("std/string")+val bytes         = use("../core/bytes.sx")+val lists         = use("../core/lists.sx")+val objid         = use("../object/id.sx")+val store         = use("../store/store.sx")+val layout        = use("../store/layout.sx")+val files         = use("../io/files.sx")+val config        = use("../core/repoconfig.sx") val remote_config = use("../git/remote.sx")-val client  = use("../protocol/client.sx")-val msg_refs = use("../protocol/messages.sx")-val transfer = use("../protocol/transfer.sx")-val promisor = use("../protocol/promisor.sx")-val checkout = use("../worktree/checkout.sx")-val cmsg    = use("../core/msg.sx")+val client        = use("../protocol/client.sx")+val msg_refs      = use("../protocol/messages.sx")+val transfer      = use("../protocol/transfer.sx")+val promisor      = use("../protocol/promisor.sx")+val checkout      = use("../worktree/checkout.sx")+val cmsg          = use("../core/msg.sx")  fn last_segment(path: bytes.Bytes) bytes.Bytes = trust {     val slash: mut i64 = -1@@ -146,6 +146,11 @@     val url_key: bytes.Bytes = remote_config.key_for(remote_name, bytes.bytes(c"url", 3))     config.set(repo, url_key, url)     bytes.free_owned(url_key)+    if key_name.ptr != none {+        val remote_key: bytes.Bytes = remote_config.key_for(remote_name, bytes.bytes(c"key", 3))+        config.set(repo, remote_key, key_name)+        bytes.free_owned(remote_key)+    }     if tls_pin.len > 0 {         val pk: bytes.Bytes = remote_config.key_for(remote_name, bytes.bytes(c"tls-pin", 7))         config.set(repo, pk, tls_pin)@@ -187,6 +192,14 @@         if r.target.ptr != none {             @append(wants, bytes.Bytes.dup(bytes.bytes(r.target.ptr, 32)))         }+    }+    if @len(wants) == 0 {+        @listfree(wants)+        client.free_client(c)+        cmsg.info_prefix()+        stdio.print("cloned empty repository into {s}\n", {str.view(pv.ptr, pv.len as i64)})+        layout.free_repo(repo)+        return 0     }     val haves: list[bytes.Bytes] = lists.new[bytes.Bytes]()     client.negotiate(c, wants, haves)--- a/veins/src/cli/fetch_cmd.sx+++ b/veins/src/cli/fetch_cmd.sx@@ -1,18 +1,18 @@ /// `vn fetch`: native incremental fetch. -val stdio   = use("std/stdio")-val str     = use("std/string")-val bytes   = use("../core/bytes.sx")-val lists   = use("../core/lists.sx")-val objid   = use("../object/id.sx")-val store   = use("../store/store.sx")-val state   = use("../store/state.sx")-val layout  = use("../store/layout.sx")+val stdio         = use("std/stdio")+val str           = use("std/string")+val bytes         = use("../core/bytes.sx")+val lists         = use("../core/lists.sx")+val objid         = use("../object/id.sx")+val store         = use("../store/store.sx")+val state         = use("../store/state.sx")+val layout        = use("../store/layout.sx") val remote_config = use("../git/remote.sx")-val client  = use("../protocol/client.sx")-val transfer = use("../protocol/transfer.sx")-val msg_refs = use("../protocol/messages.sx")-val cmsg    = use("../core/msg.sx")+val client        = use("../protocol/client.sx")+val transfer      = use("../protocol/transfer.sx")+val msg_refs      = use("../protocol/messages.sx")+val cmsg          = use("../core/msg.sx")  fn send_chunks(c: ref client.Client, repo: layout.Repo, all: list[bytes.Bytes]) bool = trust {     val st: store.Store = store.open_all(repo)--- a/veins/src/cli/key_cmd.sx+++ b/veins/src/cli/key_cmd.sx@@ -1,11 +1,11 @@ /// `vn key`: manage local Ed25519 keys. -val stdio  = use("std/stdio")-val str    = use("std/string")-val bytes  = use("../core/bytes.sx")-val keys   = use("../auth/keys.sx")-val ed     = use("../crypto/ed25519.sx")-val cmsg   = use("../core/msg.sx")+val stdio = use("std/stdio")+val str   = use("std/string")+val bytes = use("../core/bytes.sx")+val keys  = use("../auth/keys.sx")+val ed    = use("../crypto/ed25519.sx")+val cmsg  = use("../core/msg.sx")  fn print_key(k: keys.Key) void = trust {     val pub_text: bytes.Bytes = ed.format_public(k.public_key)--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -1,20 +1,20 @@ /// `vn push`: native push. -val stdio   = use("std/stdio")-val str     = use("std/string")-val bytes   = use("../core/bytes.sx")-val lists   = use("../core/lists.sx")-val objid   = use("../object/id.sx")-val graph   = use("../object/graph.sx")-val view    = use("../object/view.sx")-val store   = use("../store/store.sx")-val state   = use("../store/state.sx")-val layout  = use("../store/layout.sx")+val stdio         = use("std/stdio")+val str           = use("std/string")+val bytes         = use("../core/bytes.sx")+val lists         = use("../core/lists.sx")+val objid         = use("../object/id.sx")+val graph         = use("../object/graph.sx")+val view          = use("../object/view.sx")+val store         = use("../store/store.sx")+val state         = use("../store/state.sx")+val layout        = use("../store/layout.sx") val remote_config = use("../git/remote.sx")-val client  = use("../protocol/client.sx")-val transfer = use("../protocol/transfer.sx")-val msg_refs = use("../protocol/messages.sx")-val cmsg    = use("../core/msg.sx")+val client        = use("../protocol/client.sx")+val transfer      = use("../protocol/transfer.sx")+val msg_refs      = use("../protocol/messages.sx")+val cmsg          = use("../core/msg.sx")  fn find_server_target(refs: list[msg_refs.RefInfo], name: bytes.Bytes) bytes.Bytes = trust {     for r in refs {@@ -190,7 +190,10 @@     cmsg.info_prefix()     stdio.print(         "pushed {s} to {s}\n",-        {str.view(bookmark.ptr, bookmark.len as i64), str.view(remote_name.ptr, remote_name.len as i64)}+        {+            str.view(bookmark.ptr, bookmark.len as i64),+            str.view(remote_name.ptr, remote_name.len as i64)+        }     )     bytes.free_owned(bookmark)     bytes.free_owned(remote_name)--- a/veins/src/cli/whoami_cmd.sx+++ b/veins/src/cli/whoami_cmd.sx@@ -1,13 +1,13 @@ /// `vn whoami`: report the role and fingerprint granted by a server. -val stdio  = use("std/stdio")-val str    = use("std/string")-val bytes  = use("../core/bytes.sx")-val layout = use("../store/layout.sx")+val stdio         = use("std/stdio")+val str           = use("std/string")+val bytes         = use("../core/bytes.sx")+val layout        = use("../store/layout.sx") val remote_config = use("../git/remote.sx")-val ed = use("../crypto/ed25519.sx")-val client = use("../protocol/client.sx")-val cmsg   = use("../core/msg.sx")+val ed            = use("../crypto/ed25519.sx")+val client        = use("../protocol/client.sx")+val cmsg          = use("../core/msg.sx")  fn role_text(role: u8) bytes.Bytes = {     if role == 2 {@@ -60,12 +60,8 @@             layout.free_repo(repo)             return 1         }-        match u {-            some v => {-                url = v-            }-            none => {-            }+        if u is some v {+            url = v         }         val kn = remote_config.key_name_of(repo, remote)         if kn is some k {--- a/veins/src/core/repoconfig.sx+++ b/veins/src/core/repoconfig.sx@@ -134,7 +134,10 @@                 val line: bytes.Bytes = bytes.Bytes.slice(d, start, pos)                 val t: bytes.Bytes = trim(line)                 val eq: i64 = index_of(t, 61)-                val is_key: bool = eq >= 0 && bytes.Bytes.eql(trim(bytes.Bytes.slice(t, 0, eq as usize)), key)+                val is_key: bool = eq >= 0 && bytes.Bytes.eql(+                    trim(bytes.Bytes.slice(t, 0, eq as usize)),+                    key+                )                 if !is_key {                     buf.Buf.put_bytes(b, line)                     if pos < d.len {@@ -183,7 +186,10 @@                 val line: bytes.Bytes = bytes.Bytes.slice(d, start, pos)                 val t: bytes.Bytes = trim(line)                 val eq: i64 = index_of(t, 61)-                val is_key: bool = eq >= 0 && bytes.Bytes.eql(trim(bytes.Bytes.slice(t, 0, eq as usize)), key)+                val is_key: bool = eq >= 0 && bytes.Bytes.eql(+                    trim(bytes.Bytes.slice(t, 0, eq as usize)),+                    key+                )                 if !is_key {                     buf.Buf.put_bytes(b, line)                     if pos < d.len {--- a/veins/src/crypto/ed25519.sx+++ b/veins/src/crypto/ed25519.sx@@ -11,7 +11,7 @@ pub val FINGERPRINT_LEN: usize = 16  extern (C) fn vn_ed25519_public_from_seed(seed: ref u8, public_out: ref u8) i32 =-    "vn_ed25519_public_from_seed"+"vn_ed25519_public_from_seed" extern (C) fn vn_ed25519_sign(     seed: ref u8,     msg: ref u8,--- a/veins/src/crypto/tls.sx+++ b/veins/src/crypto/tls.sx@@ -23,7 +23,7 @@ extern (C) fn vn_tls_read(ssl: ref void, buf: ref void, len: usize) i64 = "vn_tls_read" extern (C) fn vn_tls_write(ssl: ref void, buf: ref void, len: usize) i64 = "vn_tls_write" extern (C) fn vn_tls_exporter(ssl: ref void, out: ref u8, len: usize) i32 =-    "vn_tls_exporter"+"vn_tls_exporter" extern (C) fn vn_tls_peer_sha256(ssl: ref void, out: ref u8) i32 = "vn_tls_peer_sha256" extern (C) fn vn_tls_free(ssl: ref void) void = "vn_tls_free" extern (C) fn vn_tls_ctx_free(ctx: ref void) void = "vn_tls_ctx_free"--- a/veins/src/git/import.sx+++ b/veins/src/git/import.sx@@ -1372,7 +1372,7 @@     free_commit_records(records)     free_named_targets(branches)     free_named_targets(tags)-        free_named_targets(remotes)+    free_named_targets(remotes)     if head_commit is some h7 {         val hp7: mut ref void = h7.ptr as ref void         @free(hp7)--- a/veins/src/git/remote.sx+++ b/veins/src/git/remote.sx@@ -246,4 +246,3 @@     }     return -1 }---- a/veins/src/main.sx+++ b/veins/src/main.sx@@ -837,7 +837,11 @@         to_copy = max_records     }     if to_copy > 0 && d.records != none {-        @memcpy(copy as ref void, d.records as ref void, (to_copy * (@sizeof(testing.LeakRecord) as i64)) as usize)+        @memcpy(+            copy as ref void,+            d.records as ref void,+            (to_copy * (@sizeof(testing.LeakRecord) as i64)) as usize+        )     }     val i: mut i64 = 0     for i < to_copy {--- a/veins/src/net/stream.sx+++ b/veins/src/net/stream.sx@@ -1,7 +1,7 @@ /// Reliable byte streams over a plain fd, TLS, stdio, or a child process. -val bytes = use("../core/bytes.sx")-val tls   = use("../crypto/tls.sx")+val bytes  = use("../core/bytes.sx")+val tls    = use("../crypto/tls.sx") val native = use("../io/native.sx")  extern (C) fn c_pipe(fds: ref i32) i32 = "pipe"--- a/veins/src/object/content.sx+++ b/veins/src/object/content.sx@@ -1,16 +1,16 @@ /// Materialize a blob into memory for diff and inspection commands. -val bytes  = use("../core/bytes.sx")-val buf    = use("../core/buf.sx")-val objid  = use("../object/id.sx")-val types  = use("../object/types.sx")-val blob   = use("../object/blob.sx")-val state  = use("../store/state.sx")-val store  = use("../store/store.sx")-val files  = use("../io/files.sx")-val lazy   = use("../git/lazy.sx")-val object = use("../git/object.sx")-val txnmod = use("../store/txn.sx")+val bytes    = use("../core/bytes.sx")+val buf      = use("../core/buf.sx")+val objid    = use("../object/id.sx")+val types    = use("../object/types.sx")+val blob     = use("../object/blob.sx")+val state    = use("../store/state.sx")+val store    = use("../store/store.sx")+val files    = use("../io/files.sx")+val lazy     = use("../git/lazy.sx")+val object   = use("../git/object.sx")+val txnmod   = use("../store/txn.sx") val promisor = use("../protocol/promisor.sx")  fn read_body_any(--- a/veins/src/protocol/client.sx+++ b/veins/src/protocol/client.sx@@ -1,24 +1,23 @@--val time     = use("std/time")-val bytes    = use("../core/bytes.sx")-val buf      = use("../core/buf.sx")-val lists    = use("../core/lists.sx")-val reader   = use("../core/reader.sx")-val objid    = use("../object/id.sx")-val store    = use("../store/store.sx")-val state    = use("../store/state.sx")-val layout   = use("../store/layout.sx")-val writer   = use("../store/writer.sx")-val zstd     = use("../store/zstd.sx")-val stream   = use("../net/stream.sx")-val wire     = use("../protocol/wire.sx")-val msg      = use("../protocol/messages.sx")-val ed       = use("../crypto/ed25519.sx")-val tls      = use("../crypto/tls.sx")-val keys     = use("../auth/keys.sx")+val time      = use("std/time")+val bytes     = use("../core/bytes.sx")+val buf       = use("../core/buf.sx")+val lists     = use("../core/lists.sx")+val reader    = use("../core/reader.sx")+val objid     = use("../object/id.sx")+val store     = use("../store/store.sx")+val state     = use("../store/state.sx")+val layout    = use("../store/layout.sx")+val writer    = use("../store/writer.sx")+val zstd      = use("../store/zstd.sx")+val stream    = use("../net/stream.sx")+val wire      = use("../protocol/wire.sx")+val msg       = use("../protocol/messages.sx")+val ed        = use("../crypto/ed25519.sx")+val tls       = use("../crypto/tls.sx")+val keys      = use("../auth/keys.sx") val handshake = use("../auth/handshake.sx")-val b3       = use("../crypto/blake3.sx")-val random   = use("std/crypto/random")+val b3        = use("../crypto/blake3.sx")+val random    = use("std/crypto/random")  pub type Client = {     s: mut stream.Stream--- a/veins/src/protocol/promisor.sx+++ b/veins/src/protocol/promisor.sx@@ -1,12 +1,12 @@ /// Lazy chunk fetching for repositories cloned with promised blobs. -val bytes   = use("../core/bytes.sx")-val lists   = use("../core/lists.sx")-val objid   = use("../object/id.sx")-val store   = use("../store/store.sx")-val layout  = use("../store/layout.sx")+val bytes  = use("../core/bytes.sx")+val lists  = use("../core/lists.sx")+val objid  = use("../object/id.sx")+val store  = use("../store/store.sx")+val layout = use("../store/layout.sx") val config = use("../core/repoconfig.sx")-val client  = use("../protocol/client.sx")+val client = use("../protocol/client.sx")  fn key_for(remote: bytes.Bytes, field: bytes.Bytes) bytes.Bytes = trust {     val out: ref u8 = @alloc(7 + remote.len + 1 + field.len) as ref u8--- a/veins/src/protocol/transfer.sx+++ b/veins/src/protocol/transfer.sx@@ -1,21 +1,21 @@ /// 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 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 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")  type ChunkWalk = {@@ -252,7 +252,12 @@     @append(v.tags, t) } -fn set_remote(v: mut ref view.View, remote: bytes.Bytes, name: bytes.Bytes, id: objid.Id) void = trust {+fn set_remote(+    v: mut ref view.View,+    remote: bytes.Bytes,+    name: bytes.Bytes,+    id: objid.Id+) void = trust {     val i: mut usize = 0     for i < @len(v.remote_refs) {         val o = @get(v.remote_refs, i)@@ -286,7 +291,10 @@  pub fn default_target(refs: list[msg_refs.RefInfo]) option[objid.Id] = 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))) {+        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 objid.id(r.target.ptr)         }     }@@ -340,4 +348,3 @@     }     return txnmod.finish(tx, bytes.bytes(c"clone", 5)) }---- a/veins/src/server/serve.sx+++ b/veins/src/server/serve.sx@@ -1,41 +1,41 @@ /// Native veins server: stdio and TLS transports. -val stdio   = use("std/stdio")-val str     = use("std/string")-val cmsg    = use("../core/msg.sx")-val reader  = use("../core/reader.sx")-val random  = use("std/crypto/random")-val time    = use("std/time")-val bytes   = use("../core/bytes.sx")-val buf     = use("../core/buf.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 commit = use("../object/commit.sx")-val view    = use("../object/view.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 writer  = use("../store/writer.sx")-val txnmod  = use("../store/txn.sx")-val viewops = use("../store/viewops.sx")-val zstd    = use("../store/zstd.sx")-val files   = use("../io/files.sx")-val stream  = use("../net/stream.sx")-val net     = use("std/net")+val stdio      = use("std/stdio")+val str        = use("std/string")+val cmsg       = use("../core/msg.sx")+val reader     = use("../core/reader.sx")+val random     = use("std/crypto/random")+val time       = use("std/time")+val bytes      = use("../core/bytes.sx")+val buf        = use("../core/buf.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 commit     = use("../object/commit.sx")+val view       = use("../object/view.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 writer     = use("../store/writer.sx")+val txnmod     = use("../store/txn.sx")+val viewops    = use("../store/viewops.sx")+val zstd       = use("../store/zstd.sx")+val files      = use("../io/files.sx")+val stream     = use("../net/stream.sx")+val net        = use("std/net") val allocators = use("std/allocators")-val wire    = use("../protocol/wire.sx")-val msg     = use("../protocol/messages.sx")-val ed      = use("../crypto/ed25519.sx")-val tls     = use("../crypto/tls.sx")-val access  = use("../auth/access.sx")-val handshake = use("../auth/handshake.sx")-val b3      = use("../crypto/blake3.sx")+val wire       = use("../protocol/wire.sx")+val msg        = use("../protocol/messages.sx")+val ed         = use("../crypto/ed25519.sx")+val tls        = use("../crypto/tls.sx")+val access     = use("../auth/access.sx")+val handshake  = use("../auth/handshake.sx")+val b3         = use("../crypto/blake3.sx")  val MAX_CHUNKS_PER_REQUEST: usize = 4096 @@ -92,7 +92,12 @@             return false         }         if !s.authed {-            wire.write_error(s.s, rid, wire.ERR_UNAUTHENTICATED, bytes.bytes(c"authentication required", 23))+            wire.write_error(+                s.s,+                rid,+                wire.ERR_UNAUTHENTICATED,+                bytes.bytes(c"authentication required", 23)+            )         } else {             wire.write_error(s.s, rid, wire.ERR_FORBIDDEN, bytes.bytes(c"write role required", 19))         }@@ -102,7 +107,12 @@         return false     }     if !s.authed {-        wire.write_error(s.s, rid, wire.ERR_UNAUTHENTICATED, bytes.bytes(c"authentication required", 23))+        wire.write_error(+            s.s,+            rid,+            wire.ERR_UNAUTHENTICATED,+            bytes.bytes(c"authentication required", 23)+        )     } else {         wire.write_error(s.s, rid, wire.ERR_FORBIDDEN, bytes.bytes(c"read role required", 18))     }@@ -387,7 +397,12 @@         }     }     if h.min_version > msg.PROTOCOL_VERSION || h.max_version < msg.PROTOCOL_VERSION {-        wire.write_error(s.s, f.request_id, wire.ERR_UNSUPPORTED_VERSION, bytes.bytes(c"no common version", 17))+        wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_UNSUPPORTED_VERSION,+            bytes.bytes(c"no common version", 17)+        )         msg.free_hello(h)         return false     }@@ -409,7 +424,12 @@                 "access file error at line {d} in {s}\n",                 {s.access.error_line, layout.root_view(s.repo)}             )-            wire.write_error(s.s, f.request_id, wire.ERR_INTERNAL, bytes.bytes(c"invalid access file", 19))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_INTERNAL,+                bytes.bytes(c"invalid access file", 19)+            )             msg.free_hello(h)             return false         }@@ -463,7 +483,12 @@         }         err _ => {             s.failed_auth++-            wire.write_error(s.s, f.request_id, wire.ERR_AUTH_FAILED, bytes.bytes(c"authentication failed", 21))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_AUTH_FAILED,+                bytes.bytes(c"authentication failed", 21)+            )             return false         }     }@@ -482,7 +507,12 @@     bytes.free_owned(message)     if !sig_ok {         s.failed_auth++-        wire.write_error(s.s, f.request_id, wire.ERR_AUTH_FAILED, bytes.bytes(c"authentication failed", 21))+        wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_AUTH_FAILED,+            bytes.bytes(c"authentication failed", 21)+        )         if a.public_key.ptr != none {             bytes.free_ptr(a.public_key.ptr)         }@@ -496,12 +526,8 @@     }     val fp_opt = ed.fingerprint_bytes(a.public_key)     val fp: mut bytes.Bytes = bytes.empty()-    match fp_opt {-        some v => {-            fp = v-        }-        none => {-        }+    if fp_opt is some v {+        fp = v     }     s.authed = true     s.role = role@@ -604,7 +630,12 @@             haves = v.haves         }         err _ => {-            wire.write_error(s.s, f.request_id, wire.ERR_BAD_FRAME, bytes.bytes(c"bad NEGOTIATE", 13))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_BAD_FRAME,+                bytes.bytes(c"bad NEGOTIATE", 13)+            )             return true         }     }@@ -720,7 +751,12 @@             ids = v         }         err _ => {-            wire.write_error(s.s, f.request_id, wire.ERR_BAD_FRAME, bytes.bytes(c"bad chunk list", 14))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_BAD_FRAME,+                bytes.bytes(c"bad chunk list", 14)+            )             return true         }     }@@ -764,7 +800,12 @@             ids = v         }         err _ => {-            wire.write_error(s.s, f.request_id, wire.ERR_BAD_FRAME, bytes.bytes(c"bad HAVE_QUERY", 14))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_BAD_FRAME,+                bytes.bytes(c"bad HAVE_QUERY", 14)+            )             return true         }     }@@ -981,12 +1022,22 @@     @free(hash as ref void)     if failed {         writer.abort(w)-        wire.write_error(s.s, f.request_id, wire.ERR_HASH_MISMATCH, bytes.bytes(c"record rejected", 15))+        wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_HASH_MISMATCH,+            bytes.bytes(c"record rejected", 15)+        )         return true     }     val passed: bool = writer.finish(w)     if !passed {-        wire.write_error(s.s, f.request_id, wire.ERR_INTERNAL, bytes.bytes(c"pack write failed", 17))+        wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_INTERNAL,+            bytes.bytes(c"pack write failed", 17)+        )         return true     }     open_session_store(s)@@ -1007,7 +1058,12 @@     }     @listfree(accepted)     if !closure_ok {-        return wire.write_error(s.s, f.request_id, wire.ERR_MISSING_CLOSURE, bytes.bytes(c"missing object closure", 22))+        return wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_MISSING_CLOSURE,+            bytes.bytes(c"missing object closure", 22)+        )     }     return wire.write_frame(s.s, wire.END, f.request_id, bytes.empty()) }@@ -1139,7 +1195,12 @@             updates = v         }         err _ => {-            wire.write_error(s.s, f.request_id, wire.ERR_BAD_FRAME, bytes.bytes(c"bad UPDATE_REFS", 15))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_BAD_FRAME,+                bytes.bytes(c"bad UPDATE_REFS", 15)+            )             return true         }     }@@ -1151,7 +1212,12 @@         }         none => {             msg.free_updates(updates)-            wire.write_error(s.s, f.request_id, wire.ERR_INTERNAL, bytes.bytes(c"cannot update refs", 18))+            wire.write_error(+                s.s,+                f.request_id,+                wire.ERR_INTERNAL,+                bytes.bytes(c"cannot update refs", 18)+            )             return true         }     }@@ -1165,7 +1231,12 @@     if conflict {         txnmod.abort(tx)         msg.free_updates(updates)-        return wire.write_error(s.s, f.request_id, wire.ERR_REF_CONFLICT, bytes.bytes(c"ref changed", 11))+        return wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_REF_CONFLICT,+            bytes.bytes(c"ref changed", 11)+        )     }     for u in updates {         apply_ref(tx.view, u.name, u.target)@@ -1174,7 +1245,12 @@     val status: i32 = txnmod.finish(tx, bytes.bytes(c"remote push", 11))     msg.free_updates(updates)     if status != 0 {-        return wire.write_error(s.s, f.request_id, wire.ERR_INTERNAL, bytes.bytes(c"commit failed", 13))+        return wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_INTERNAL,+            bytes.bytes(c"commit failed", 13)+        )     }     val fp_text: bytes.Bytes = ed.base32_text(s.fingerprint)     val line: ref u8 = @fmtalloc(@@ -1198,7 +1274,12 @@         return handle_whoami(s, f)     }     if !s.repo_present {-        wire.write_error(s.s, f.request_id, wire.ERR_UNAUTHENTICATED, bytes.bytes(c"authentication required", 23))+        wire.write_error(+            s.s,+            f.request_id,+            wire.ERR_UNAUTHENTICATED,+            bytes.bytes(c"authentication required", 23)+        )         return true     }     if f.kind == wire.LIST_REFS {@@ -1222,7 +1303,12 @@     if f.kind == wire.UPDATE_REFS {         return handle_update_refs(s, f)     }-    return wire.write_error(s.s, f.request_id, wire.ERR_BAD_FRAME, bytes.bytes(c"unknown request", 15))+    return wire.write_error(+        s.s,+        f.request_id,+        wire.ERR_BAD_FRAME,+        bytes.bytes(c"unknown request", 15)+    ) }  fn free_session(s: mut ref Session) void = trust {--- a/veins/src/store/txn.sx+++ b/veins/src/store/txn.sx@@ -185,7 +185,61 @@     for w in src.working_copies {         if find_workspace(dst, w.workspace) < 0 {             @append(dst.working_copies, clone_workspace(w))+        }+    }+}++fn sort_remote_refs(xs: mut list[ref view.RemoteRef]) void = trust {+    val i: mut usize = 1+    for i < @len(xs) {+        val cur = @get(xs, i)+        val c: mut ref view.RemoteRef = none+        if cur is some v {+            c = v+        }+        val j: mut usize = i+        for j > 0 {+            val prev_opt = @get(xs, j - 1)+            val prev: mut ref view.RemoteRef = none+            if prev_opt is some v2 {+                prev = v2+            }+            val cmp: i64 = bytes.Bytes.cmp(prev.remote, c.remote)+            val ordered: bool = cmp < 0 || (cmp == 0 && bytes.Bytes.cmp(prev.name, c.name) <= 0)+            if ordered {+                break+            }+            @set(xs, j, prev)+            j--+        }+        @set(xs, j, c)+        i+++    }+}++fn sort_heads(xs: mut list[objid.Id]) void = trust {+    val i: mut usize = 1+    for i < @len(xs) {+        val cur = @get(xs, i)+        val c: mut objid.Id = objid.id_none()+        if cur is some v {+            c = v+        }+        val j: mut usize = i+        for j > 0 {+            val prev_opt = @get(xs, j - 1)+            val prev: mut objid.Id = objid.id_none()+            if prev_opt is some v2 {+                prev = v2+            }+            if objid.Id.cmp(prev, c) <= 0 {+                break+            }+            @set(xs, j, prev)+            j--         }+        @set(xs, j, c)+        i++     } } @@ -452,11 +506,25 @@ pub fn abort(tx: mut ref Txn) void = trust {     writer.abort(tx.writer)     free_txn(tx)+}++/// Put view entries back into the canonical order required by the format.+fn prepare_view(v: mut ref view.View) void = trust {+    sort_heads(v.heads)+    sort_bookmarks(v.bookmarks)+    sort_tags(v.tags)+    sort_remote_refs(v.remote_refs)+    sort_workspaces(v.working_copies)+}++fn encode_canonical_view(v: mut ref view.View) bytes.Bytes = trust {+    prepare_view(v)+    return view.encode(v) }  /// Encode the view, write an operation, and advance the heads. pub fn finish(tx: mut ref Txn, description: bytes.Bytes) i32 = trust {-    val view_body: bytes.Bytes = view.encode(tx.view)+    val view_body: bytes.Bytes = encode_canonical_view(tx.view)     val view_id: objid.Id = writer.add(tx.writer, types.VIEW, view_body)     val now: i64 = time.unix_now_millis()     val hostname: bytes.Bytes = host_from_env()@@ -511,4 +579,69 @@         return 1     }     return 0+}++fn test_id(fill: u8) objid.Id = trust {+    val p: ref u8 = @alloc(32) as ref u8+    val i: mut usize = 0+    for i < 32 {+        @store8(@ptradd(p, i as i64), fill)+        i+++    }+    return objid.id(p)+}++test "transaction view entries are sorted before encoding" {+    trust {+        val v: mut ref view.View = state.empty_view()+        val low: objid.Id = test_id(17)+        val high: objid.Id = test_id(34)+        @append(v.heads, copy_id(high))+        @append(v.heads, copy_id(low))++        val main_bm: mut ref view.Bookmark = @alloc(@sizeof(view.Bookmark)) as ref view.Bookmark+        main_bm.name = bytes.Bytes.dup(bytes.bytes(c"main", 4))+        main_bm.targets = view.empty_target_set()+        @append(main_bm.targets.adds, copy_id(low))+        @append(v.bookmarks, main_bm)++        val feat_bm: mut ref view.Bookmark = @alloc(@sizeof(view.Bookmark)) as ref view.Bookmark+        feat_bm.name = bytes.Bytes.dup(bytes.bytes(c"feat", 4))+        feat_bm.targets = view.empty_target_set()+        @append(feat_bm.targets.adds, copy_id(high))+        @append(v.bookmarks, feat_bm)++        val rr_main: mut ref view.RemoteRef = @alloc(@sizeof(view.RemoteRef)) as ref view.RemoteRef+        rr_main.remote = bytes.Bytes.dup(bytes.bytes(c"origin", 6))+        rr_main.name = bytes.Bytes.dup(bytes.bytes(c"main", 4))+        rr_main.target = copy_id(low)+        @append(v.remote_refs, rr_main)++        val rr_feat: mut ref view.RemoteRef = @alloc(@sizeof(view.RemoteRef)) as ref view.RemoteRef+        rr_feat.remote = bytes.Bytes.dup(bytes.bytes(c"origin", 6))+        rr_feat.name = bytes.Bytes.dup(bytes.bytes(c"feat", 4))+        rr_feat.target = copy_id(high)+        @append(v.remote_refs, rr_feat)++        val body: bytes.Bytes = encode_canonical_view(v)+        val decoded = view.decode(body)+        match decoded {+            ok out => {+                assert @len(out.heads) == 2+                assert @len(out.bookmarks) == 2+                val first = @get(out.bookmarks, 0)+                if first is some bm {+                    assert bytes.Bytes.eql(bm.name, bytes.bytes(c"feat", 4))+                } else {+                    assert false+                }+                view.free_view(out)+            }+            err _ => {+                assert false+            }+        }+        bytes.free_owned(body)+        view.free_view(v)+    } }--- a/veins/src/worktree/checkout.sx+++ b/veins/src/worktree/checkout.sx@@ -23,7 +23,7 @@ val state      = use("../store/state.sx") val txn        = use("../store/txn.sx") val viewops    = use("../store/viewops.sx")-val promisor = use("../protocol/promisor.sx")+val promisor   = use("../protocol/promisor.sx") val snapshot   = use("../worktree/snapshot.sx") val files      = use("../io/files.sx") val native     = use("../io/native.sx")@@ -1366,7 +1366,11 @@         job.has_git = git_usable         @append(jobs, job)         if use_threads {-            val tr = thread.Thread.new[allocators.HeapAllocator](ac, checkout_worker, job as ref void)+            val tr = thread.Thread.new[allocators.HeapAllocator](+                ac,+                checkout_worker,+                job as ref void+            )             match tr {                 ok t => {                     @append(thread_refs, t)--- a/veins/src/worktree/snapshot.sx+++ b/veins/src/worktree/snapshot.sx@@ -853,7 +853,8 @@     }      val handles: list[ref store.Handle] = txn.handles(tx)-    val wc_opt = viewops.working_copy(tx.view)    val wc: mut objid.Id = objid.id_none()+    val wc_opt = viewops.working_copy(tx.view)+    val wc: mut objid.Id = objid.id_none()     val have_wc: mut bool = false     if wc_opt is some id {         wc = id