navid/veins / commit

fddc5b75699f

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

parents: 31d8486273aa

Browse files at this commit · Download source

all: fixes to messaging
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -53,6 +53,8 @@ The key words MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY are used as described in RFC 2119. Byte order is little-endian unless stated. Sections marked _informative_ do not impose requirements.  Command-line options use Plan 9 style: a long option is a single dash followed by its name (for example `-message`, `-rev`, and `-verbose`). Short aliases MAY also be accepted. An unrecognized option MUST be reported as an error and MUST NOT be treated as an operand. `--` terminates option parsing; every argument after it is an operand.++User-facing diagnostics use level prefixes: `error:` for failures, `warning:` for non-fatal problems, and `info:` for informational results. Prefixes are colored when standard output/stderr is a terminal and `NO_COLOR` is unset.  === Terminology --- a/src/src/cli/bench_cmd.sx+++ b/src/src/cli/bench_cmd.sx@@ -2,6 +2,7 @@  val str   = use("std/string") val stdio = use("std/stdio")+val msg   = use("../core/msg.sx") val time  = use("std/time") val bytes = use("../core/bytes.sx") val buf   = use("../core/buf.sx")@@ -73,7 +74,8 @@  pub fn run(args: list[ref u8], start: usize) i32 = trust {     if start >= @len(args) {-        stdio.eprint("vn: bench-import requires a git directory\n", {})+        msg.error_prefix()+        stdio.eprint("bench-import requires a git directory\n", {})         return 1     }     val repo_arg = @get(args, start)@@ -93,7 +95,8 @@     @free(list_cmd as ref void)     if !listed {         buf.Buf.free(listing)-        stdio.eprint("vn: cannot run git rev-list\n", {})+        msg.error_prefix()+        stdio.eprint("cannot run git rev-list\n", {})         return 1     } @@ -118,7 +121,8 @@     buf.Buf.free(meta_buf)     if !meta_written {         @free(meta_path as ref void)-        stdio.eprint("vn: cannot write temporary commit/tree list\n", {})+        msg.error_prefix()+        stdio.eprint("cannot write temporary commit/tree list\n", {})         return 1     } @@ -133,7 +137,8 @@         buf.Buf.free(data)         files.delete(meta_view)         @free(meta_path as ref void)-        stdio.eprint("vn: cannot run git cat-file --batch\n", {})+        msg.error_prefix()+        stdio.eprint("cannot run git cat-file --batch\n", {})         return 1     } --- a/src/src/cli/checkout_cmd.sx+++ b/src/src/cli/checkout_cmd.sx@@ -2,6 +2,7 @@  val str      = use("std/string") val stdio    = use("std/stdio")+val msg      = use("../core/msg.sx") val bytes    = use("../core/bytes.sx") val layout   = use("../store/layout.sx") val checkout = use("../worktree/checkout.sx")@@ -22,7 +23,8 @@             return status         }         none => {-            stdio.eprint("vn: not a veins repository\n", {})+            msg.error_prefix()+            stdio.eprint("not a veins repository\n", {})             return 1         }     }--- a/src/src/cli/diff_cmd.sx+++ b/src/src/cli/diff_cmd.sx@@ -1,23 +1,24 @@ /// `vn diff [-r <rev>]`: show a unified diff. -val str       = use("std/string")-val stdio     = use("std/stdio")-val bytes     = use("../core/bytes.sx")-val lists     = use("../core/lists.sx")-val objid     = use("../object/id.sx")-val tree      = use("../object/tree.sx")-val view      = use("../object/view.sx")-val graph     = use("../object/graph.sx")-val treediff  = use("../object/treediff.sx")-val treewalk  = use("../object/treewalk.sx")-val content   = use("../object/content.sx")-val store     = use("../store/store.sx")-val state     = use("../store/state.sx")-val layout    = use("../store/layout.sx")-val viewops   = use("../store/viewops.sx")-val files     = use("../io/files.sx")-val object    = use("../git/object.sx")-val snapshot  = use("../worktree/snapshot.sx")+val str      = use("std/string")+val stdio    = use("std/stdio")+val msg      = use("../core/msg.sx")+val bytes    = use("../core/bytes.sx")+val lists    = use("../core/lists.sx")+val objid    = use("../object/id.sx")+val tree     = use("../object/tree.sx")+val view     = use("../object/view.sx")+val graph    = use("../object/graph.sx")+val treediff = use("../object/treediff.sx")+val treewalk = use("../object/treewalk.sx")+val content  = use("../object/content.sx")+val store    = use("../store/store.sx")+val state    = use("../store/state.sx")+val layout   = use("../store/layout.sx")+val viewops  = use("../store/viewops.sx")+val files    = use("../io/files.sx")+val object   = use("../git/object.sx")+val snapshot = use("../worktree/snapshot.sx")  type DiffOp = {     tag: mut u8@@ -190,13 +191,9 @@ fn tree_of(handles: list[ref store.Handle], id: objid.Id) option[objid.Id] = trust {     val lc_opt = graph.load_commit(handles, id)     val out: mut option[objid.Id] = none-    match lc_opt {-        some lc => {-            out = some(graph.copy_id(lc.c.root_tree))-            graph.free_loaded(lc)-        }-        none => {-        }+    if lc_opt is some lc {+        out = some(graph.copy_id(lc.c.root_tree))+        graph.free_loaded(lc)     }     return out }@@ -204,25 +201,17 @@ fn parent_tree_of(handles: list[ref store.Handle], id: objid.Id) option[objid.Id] = trust {     val lc_opt = graph.load_commit(handles, id)     val out: mut option[objid.Id] = none-    match lc_opt {-        some lc => {-            if @len(lc.c.parents) > 0 {-                val p = @get(lc.c.parents, 0)-                if p is some pid {-                    val t = tree_of(handles, pid)-                    match t {-                        some tid => {-                            out = some(tid)-                        }-                        none => {-                        }-                    }+    if lc_opt is some lc {+        if @len(lc.c.parents) > 0 {+            val p = @get(lc.c.parents, 0)+            if p is some pid {+                val t = tree_of(handles, pid)+                if t is some tid {+                    out = some(tid)                 }             }-            graph.free_loaded(lc)-        }-        none => {         }+        graph.free_loaded(lc)     }     return out }@@ -250,7 +239,8 @@         }         none => {             store.close(st)-            stdio.eprint("vn: no operation state\n", {})+            msg.error_prefix()+            stdio.eprint("no operation state\n", {})             return 1         }     }@@ -289,7 +279,8 @@         }     }     if status != 0 {-        stdio.eprint("vn: unknown revision\n", {})+        msg.error_prefix()+        stdio.eprint("unknown revision\n", {})     } else {         val git: mut GitSource = open_git(repo)         render(st.handles, git, old_tree, new_tree)--- a/src/src/cli/fsck_cmd.sx+++ b/src/src/cli/fsck_cmd.sx@@ -2,6 +2,7 @@  val str    = use("std/string") val stdio  = use("std/stdio")+val msg    = use("../core/msg.sx") val layout = use("../store/layout.sx") val fsck   = use("../store/fsck.sx") @@ -14,7 +15,8 @@             layout.free_repo(repo)         }         none => {-            stdio.eprint("vn: not a veins repository: {s}\n", {path})+            msg.error_prefix()+            stdio.eprint("not a veins repository: {s}\n", {path})         }     }     return status--- a/src/src/cli/git_cmd.sx+++ b/src/src/cli/git_cmd.sx@@ -3,6 +3,7 @@ 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")@@ -16,7 +17,8 @@             sub = s         }         none => {-            stdio.eprint("vn: expected a git subcommand (import)\n", {})+            msg.error_prefix()+            stdio.eprint("expected a git subcommand (import)\n", {})             return 1         }     }@@ -26,7 +28,8 @@     if @strcmp(sub, c"export") == 0 {         return run_export(args, start + 1)     }-    stdio.eprint("vn: unknown git subcommand: {s}\n", {str.from_cstr(sub)})+    msg.error_prefix()+    stdio.eprint("unknown git subcommand: {s}\n", {str.from_cstr(sub)})     return 1 } @@ -41,13 +44,15 @@             val prefix: bytes.Bytes = bytes.bytes(c"-source:", 8)             if bytes.Bytes.starts_with(av, prefix) {                 if av.len == 8 {-                    stdio.eprint("vn: -source: requires a path\n", {})+                    msg.error_prefix()+                    stdio.eprint("-source: requires a path\n", {})                     return 1                 }                 val value: bytes.Bytes = bytes.Bytes.slice(av, 8, av.len)                 source = some str.view(value.ptr, value.len as i64)             } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 return 1             } else {                 repo_path = str.from_cstr(a)@@ -64,7 +69,8 @@             repo = r         }         none => {-            stdio.eprint("vn: not a veins repository: {s}\n", {repo_path})+            msg.error_prefix()+            stdio.eprint("not a veins repository: {s}\n", {repo_path})             return 1         }     }@@ -71,7 +77,8 @@     if source is some src {         val prepared = mirror.prepare(repo, src)         if prepared != 0 {-            stdio.eprint("vn: cannot prepare git mirror (code {d})\n", {prepared})+            msg.error_prefix()+            stdio.eprint("cannot prepare git mirror (code {d})\n", {prepared})             layout.free_repo(repo)             return 1         }@@ -90,7 +97,8 @@         if arg_opt is some a {             val av: bytes.Bytes = bytes.from_cstr(a)             if av.len > 0 && bytes.Bytes.at(av, 0) == 45 {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 return 1             }             repo_path = str.from_cstr(a)@@ -104,7 +112,8 @@             repo = r         }         none => {-            stdio.eprint("vn: not a veins repository: {s}\n", {repo_path})+            msg.error_prefix()+            stdio.eprint("not a veins repository: {s}\n", {repo_path})             return 1         }     }--- a/src/src/cli/help_cmd.sx+++ b/src/src/cli/help_cmd.sx@@ -2,6 +2,7 @@  val str   = use("std/string") val stdio = use("std/stdio")+val msg   = use("../core/msg.sx")  fn cmd_is(a: ref u8, text: ref u8, len: usize) bool = trust {     return str.eql(str.from_cstr(a), str.view(text, len as i64))@@ -238,7 +239,8 @@                     show_git_export()                     return 0                 }-                stdio.eprint("vn: unknown git subcommand: {s}\n", {str.from_cstr(sub)})+                msg.error_prefix()+                stdio.eprint("unknown git subcommand: {s}\n", {str.from_cstr(sub)})                 return 1             }         }@@ -270,7 +272,8 @@         return 0     } -    stdio.eprint("vn: unknown command: {s}\n", {str.from_cstr(cmd)})+    msg.error_prefix()+    stdio.eprint("unknown command: {s}\n", {str.from_cstr(cmd)})     usage()     return 1 }--- a/src/src/cli/init_cmd.sx+++ b/src/src/cli/init_cmd.sx@@ -2,6 +2,7 @@  val str    = use("std/string") 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")@@ -10,12 +11,14 @@     val result = layout.init(path)     match result {         ok repo => {+            msg.info_prefix()             stdio.print("initialized veins repository at {s}\n", {layout.root_view(repo)})             val mut_source = source             if mut_source is some src {                 val prepared: i32 = mirror.prepare(repo, src)                 if prepared != 0 {-                    stdio.eprint("vn: cannot prepare git mirror (code {d})\n", {prepared})+                    msg.error_prefix()+                    stdio.eprint("cannot prepare git mirror (code {d})\n", {prepared})                     layout.free_repo(repo)                     return 1                 }@@ -27,7 +30,8 @@             return 0         }         err code => {-            stdio.eprint("vn: init failed with code {d}\n", {code})+            msg.error_prefix()+            stdio.eprint("init failed with code {d}\n", {code})             return 1         }     }--- a/src/src/cli/log_cmd.sx+++ b/src/src/cli/log_cmd.sx@@ -1,21 +1,22 @@ /// `vn log [-rev <revset>]`: show commit history, newest first. -val str       = use("std/string")-val stdio     = use("std/stdio")-val terminal  = use("std/terminal")-val bytes     = use("../core/bytes.sx")-val lists     = use("../core/lists.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 treewalk  = use("../object/treewalk.sx")-val datetime  = use("../core/datetime.sx")-val store     = use("../store/store.sx")-val state     = use("../store/state.sx")-val layout    = use("../store/layout.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 lists    = use("../core/lists.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 treewalk = use("../object/treewalk.sx")+val datetime = use("../core/datetime.sx")+val store    = use("../store/store.sx")+val state    = use("../store/state.sx")+val layout   = use("../store/layout.sx")+val viewops  = use("../store/viewops.sx")+val snapshot = use("../worktree/snapshot.sx")  type LogRec = {     id: mut objid.Id@@ -191,7 +192,8 @@         }         none => {             store.close(st)-            stdio.eprint("vn: no operation state\n", {})+            msg.error_prefix()+            stdio.eprint("no operation state\n", {})             return 1         }     }@@ -206,28 +208,24 @@     val recs: mut list[ref LogRec] = lists.new[ref LogRec]()     for id in ids {         val lc_opt = graph.load_commit(st.handles, id)-        match lc_opt {-            some lc => {-                val cid_full: bytes.Bytes = changeid.encode(lc.c.change_id)-                val msg: bytes.Bytes = first_line(lc.c.message)-                val rec: mut ref LogRec = new_rec(-                    id,-                    cid_full,-                    lc.c.committer.seconds,-                    lc.c.root_tree,-                    msg,-                    lc.c.author.name-                )-                rec.conflicted = treewalk.conflicted(st.handles, lc.c.root_tree)-                if objid.Id.eql(id, wc) {-                    rec.has_changes = graph.has_changes(st.handles, lc)-                }-                changeid.free(cid_full)-                graph.free_loaded(lc)-                @append(recs, rec)-            }-            none => {+        if lc_opt is some lc {+            val cid_full: bytes.Bytes = changeid.encode(lc.c.change_id)+            val msg: bytes.Bytes = first_line(lc.c.message)+            val rec: mut ref LogRec = new_rec(+                id,+                cid_full,+                lc.c.committer.seconds,+                lc.c.root_tree,+                msg,+                lc.c.author.name+            )+            rec.conflicted = treewalk.conflicted(st.handles, lc.c.root_tree)+            if objid.Id.eql(id, wc) {+                rec.has_changes = graph.has_changes(st.handles, lc)             }+            changeid.free(cid_full)+            graph.free_loaded(lc)+            @append(recs, rec)         }     }     sort_recs(recs)--- a/src/src/cli/new_cmd.sx+++ b/src/src/cli/new_cmd.sx@@ -1,23 +1,24 @@ /// `vn describe`, `vn new`, and `vn commit`. -val stdio     = use("std/stdio")-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 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 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 NOTHING_TO_COMMIT: i32 = 2 @@ -114,7 +115,8 @@             tx = t         }         none => {-            stdio.eprint("vn: cannot load repository state\n", {})+            msg.error_prefix()+            stdio.eprint("cannot load repository state\n", {})             val mp: mut ref void = message.ptr as ref void             @free(mp)             return 1@@ -128,7 +130,8 @@         have_wc = true     }     if !have_wc {-        stdio.eprint("vn: no working-copy commit\n", {})+        msg.error_prefix()+        stdio.eprint("no working-copy commit\n", {})         txn.abort(tx)         val mp2: mut ref void = message.ptr as ref void         @free(mp2)@@ -137,7 +140,8 @@     val st: store.Store = store.open_all(repo)     val lc_opt = graph.load_commit(st.handles, wc)     if lc_opt is none {-        stdio.eprint("vn: cannot read working-copy commit\n", {})+        msg.error_prefix()+        stdio.eprint("cannot read working-copy commit\n", {})         store.close(st)         txn.abort(tx)         val mp2: mut ref void = message.ptr as ref void@@ -145,18 +149,15 @@         return 1     }     val lc: mut ref graph.LoadedCommit = none-    match lc_opt {-        some x => {-            lc = x-        }-        none => {-        }+    if lc_opt is some x {+        lc = x     }     val changed: bool = graph.has_changes(st.handles, lc)     val same_message: bool = bytes.Bytes.eql(message, lc.c.message)     if !changed && (require_changes || same_message) {         if require_changes {-            stdio.puts("nothing to commit, working copy clean")+            msg.info_prefix()+            stdio.print("nothing to commit, working copy clean\n", {})         }         store.close(st)         txn.abort(tx)@@ -248,7 +249,8 @@             tx = t         }         none => {-            stdio.eprint("vn: cannot load repository state\n", {})+            msg.error_prefix()+            stdio.eprint("cannot load repository state\n", {})             return 1         }     }@@ -264,7 +266,8 @@     val root_tree: mut objid.Id = objid.id_none()     if @len(revs) == 0 {         if !have_wc {-            stdio.eprint("vn: no working-copy commit\n", {})+            msg.error_prefix()+            stdio.eprint("no working-copy commit\n", {})             store.close(st)             txn.abort(tx)             return 1@@ -277,7 +280,8 @@                 graph.free_loaded(lc)             }             none => {-                stdio.eprint("vn: cannot read working-copy commit\n", {})+                msg.error_prefix()+                stdio.eprint("cannot read working-copy commit\n", {})                 store.close(st)                 txn.abort(tx)                 return 1@@ -316,7 +320,8 @@             i++         }         if mut_failed {-            stdio.eprint("vn: unknown revision\n", {})+            msg.error_prefix()+            stdio.eprint("unknown revision\n", {})             store.close(st)             txn.abort(tx)             graph.free_ids(parents)--- a/src/src/cli/op_cmd.sx+++ b/src/src/cli/op_cmd.sx@@ -2,6 +2,7 @@  val str       = use("std/string") val stdio     = use("std/stdio")+val msg       = use("../core/msg.sx") val bytes     = use("../core/bytes.sx") val lists     = use("../core/lists.sx") val objid     = use("../object/id.sx")@@ -62,20 +63,16 @@         }         @append(seen, copy_id(id))         val op_opt = state.read_operation(handles, id)-        match op_opt {-            some op => {-                for p in op.parents {-                    if !contains(seen, p) {-                        @append(stack, copy_id(p))-                    }+        if op_opt is some op {+            for p in op.parents {+                if !contains(seen, p) {+                    @append(stack, copy_id(p))                 }-                val rec: mut ref OpRec = @alloc(@sizeof(OpRec)) as ref OpRec-                rec.id = id-                rec.op = op-                @append(out, rec)-            }-            none => {             }+            val rec: mut ref OpRec = @alloc(@sizeof(OpRec)) as ref OpRec+            rec.id = id+            rec.op = op+            @append(out, rec)         }     }     @listfree(stack)@@ -138,7 +135,10 @@         val r = rec_at(recs, i)         val hex: ref u8 = objid.Id.hex(r.id)         val full: bytes.Bytes = bytes.bytes(hex, 64)-        val matched: bool = full.len >= text.len && bytes.Bytes.eql(bytes.Bytes.slice(full, 0, text.len), text)+        val matched: bool = full.len >= text.len && bytes.Bytes.eql(+            bytes.Bytes.slice(full, 0, text.len),+            text+        )         @free(hex as ref void)         if matched {             @append(matches, copy_id(r.id))@@ -210,7 +210,8 @@             tx = t         }         none => {-            stdio.eprint("vn: cannot load repository state\n", {})+            msg.error_prefix()+            stdio.eprint("cannot load repository state\n", {})             return 1         }     }@@ -233,11 +234,13 @@             if target_view is some tv {                 status = write_view(repo, tv, bytes.bytes(c"op restore", 10))             } else {-                stdio.eprint("vn: cannot read operation view\n", {})+                msg.error_prefix()+                stdio.eprint("cannot read operation view\n", {})             }         }     } else {-        stdio.eprint("vn: unknown operation\n", {})+        msg.error_prefix()+        stdio.eprint("unknown operation\n", {})     }     free_recs(recs)     free_ids(heads)@@ -274,7 +277,8 @@             }         }     } else {-        stdio.eprint("vn: unknown operation\n", {})+        msg.error_prefix()+        stdio.eprint("unknown operation\n", {})     }     free_recs(recs)     free_ids(heads)@@ -286,7 +290,8 @@     val st: store.Store = store.open_all(repo)     val heads: list[objid.Id] = state.heads(repo)     if @len(heads) == 0 {-        stdio.eprint("vn: no operations to undo\n", {})+        msg.error_prefix()+        stdio.eprint("no operations to undo\n", {})         store.close(st)         return 1     }@@ -313,7 +318,8 @@                 status = write_view(repo, tv, bytes.bytes(c"undo", 4))             }             none => {-                stdio.eprint("vn: cannot resolve undo target\n", {})+                msg.error_prefix()+                stdio.eprint("cannot resolve undo target\n", {})             }         }     }--- a/src/src/cli/selftest_cmd.sx+++ b/src/src/cli/selftest_cmd.sx@@ -4,6 +4,7 @@  val stdio     = use("std/stdio") val str       = use("std/string")+val msg       = use("../core/msg.sx") val time      = use("std/time") val bytes     = use("../core/bytes.sx") val buf       = use("../core/buf.sx")@@ -531,6 +532,7 @@             repo = r         }         err e => {+            msg.error_prefix()             stdio.eprint("self-test: cannot create repo ({d})\n", {e})             @free(path as ref void)             return 1@@ -541,9 +543,11 @@     layout.free_repo(repo)     @free(path as ref void)     if status != 0 {+        msg.error_prefix()         stdio.eprint("self-test: fsck failed\n", {})         return 1     }-    stdio.puts("self-test: OK")+    msg.info_prefix()+    stdio.print("self-test: OK\n", {})     return 0 }--- a/src/src/cli/status_cmd.sx+++ b/src/src/cli/status_cmd.sx@@ -1,6 +1,7 @@ /// `vn status`: show working-copy changes relative to the parent commit.  val stdio    = use("std/stdio")+val msg      = use("../core/msg.sx") val str      = use("std/string") val objid    = use("../object/id.sx") val tree     = use("../object/tree.sx")@@ -17,22 +18,18 @@ fn first_parent_tree(handles: list[ref store.Handle], id: objid.Id) option[objid.Id] = trust {     val lc_opt = graph.load_commit(handles, id)     val out: mut option[objid.Id] = none-    match lc_opt {-        some lc => {-            if @len(lc.c.parents) > 0 {-                val p = @get(lc.c.parents, 0)-                if p is some pid {-                    val pl = graph.load_commit(handles, pid)-                    if pl is some parent {-                        out = some(graph.copy_id(parent.c.root_tree))-                        graph.free_loaded(parent)-                    }+    if lc_opt is some lc {+        if @len(lc.c.parents) > 0 {+            val p = @get(lc.c.parents, 0)+            if p is some pid {+                val pl = graph.load_commit(handles, pid)+                if pl is some parent {+                    out = some(graph.copy_id(parent.c.root_tree))+                    graph.free_loaded(parent)                 }             }-            graph.free_loaded(lc)-        }-        none => {         }+        graph.free_loaded(lc)     }     return out }@@ -40,13 +37,9 @@ fn working_tree(handles: list[ref store.Handle], id: objid.Id) option[objid.Id] = trust {     val lc_opt = graph.load_commit(handles, id)     val out: mut option[objid.Id] = none-    match lc_opt {-        some lc => {-            out = some(graph.copy_id(lc.c.root_tree))-            graph.free_loaded(lc)-        }-        none => {-        }+    if lc_opt is some lc {+        out = some(graph.copy_id(lc.c.root_tree))+        graph.free_loaded(lc)     }     return out }@@ -65,7 +58,8 @@         }         none => {             store.close(st)-            stdio.eprint("vn: no operation state\n", {})+            msg.error_prefix()+            stdio.eprint("no operation state\n", {})             return 1         }     }@@ -76,7 +70,8 @@             wc = id         }         none => {-            stdio.puts("working copy clean")+            msg.info_prefix()+            stdio.print("working copy clean\n", {})             view.free_view(v)             store.close(st)             return 0@@ -100,7 +95,8 @@         }     }     if @len(changes) == 0 {-        stdio.puts("working copy clean")+        msg.info_prefix()+        stdio.print("working copy clean\n", {})     }     if conflicted_count > 0 {         stdio.print("{d} conflict(s)\n", {conflicted_count})--- a/src/src/core/identity.sx+++ b/src/src/core/identity.sx@@ -1,12 +1,12 @@ /// Author/committer identity from the local config or environment. -val str     = use("std/string")-val os      = use("std/os")-val time    = use("std/time")-val bytes   = use("../core/bytes.sx")-val prim    = use("../core/primitives.sx")-val layout  = use("../store/layout.sx")-val files   = use("../io/files.sx")+val str    = use("std/string")+val os     = use("std/os")+val time   = use("std/time")+val bytes  = use("../core/bytes.sx")+val prim   = use("../core/primitives.sx")+val layout = use("../store/layout.sx")+val files  = use("../io/files.sx")  fn trim(b: bytes.Bytes) bytes.Bytes = trust {     val start: mut usize = 0@@ -32,45 +32,41 @@     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 {-                                if eq < 0 {-                                    eq = i as i64-                                }+    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 {+                            if eq < 0 {+                                eq = i as i64                             }-                            i++                         }-                        if eq >= 0 {-                            val k: bytes.Bytes = trim(bytes.Bytes.slice(line, 0, eq as usize))-                            if bytes.Bytes.eql(k, key) {-                                val v: bytes.Bytes = trim(-                                    bytes.Bytes.slice(line, eq as usize + 1, line.len)-                                )-                                val out: bytes.Bytes = bytes.Bytes.dup(v)-                                files.free_buffer(data)-                                return some out-                            }+                        i+++                    }+                    if eq >= 0 {+                        val k: bytes.Bytes = trim(bytes.Bytes.slice(line, 0, eq as usize))+                        if bytes.Bytes.eql(k, key) {+                            val v: bytes.Bytes = trim(+                                bytes.Bytes.slice(line, eq as usize + 1, line.len)+                            )+                            val out: bytes.Bytes = bytes.Bytes.dup(v)+                            files.free_buffer(data)+                            return some out                         }                     }-                    start = pos + 1                 }-                pos+++                start = pos + 1             }-            files.free_buffer(data)-        }-        none => {+            pos++         }+        files.free_buffer(data)     }     return none }@@ -87,30 +83,23 @@     } } -fn first_config(repo: layout.Repo, key: bytes.Bytes, env1: ref u8, env2: ref u8) bytes.Bytes = trust {+fn first_config(+    repo: layout.Repo,+    key: bytes.Bytes,+    env1: ref u8,+    env2: ref u8+) bytes.Bytes = trust {     val c = config_value(repo, key)-    match c {-        some v => {-            return v-        }-        none => {-        }+    if c is some v {+        return v     }     val e1 = env_dup(env1)-    match e1 {-        some v => {-            return v-        }-        none => {-        }+    if e1 is some v {+        return v     }     val e2 = env_dup(env2)-    match e2 {-        some v => {-            return v-        }-        none => {-        }+    if e2 is some v {+        return v     }     return bytes.Bytes.dup(bytes.bytes(c"unknown", 7)) }--- /dev/null+++ b/src/src/core/msg.sx@@ -0,0 +1,27 @@+/// User-facing log messages with consistent level prefixes and colors.++val stdio    = use("std/stdio")+val terminal = use("std/terminal")++/// Print a red, bold `error:` prefix to stderr.+pub fn error_prefix() void = trust {+    terminal.eprint_styled("error", terminal.Color.Red, terminal.Color.Default, terminal.Style.Bold)+    stdio.eprint(": ", {})+}++/// Print a yellow, bold `warning:` prefix to stderr.+pub fn warning_prefix() void = trust {+    terminal.eprint_styled(+        "warning",+        terminal.Color.Yellow,+        terminal.Color.Default,+        terminal.Style.Bold+    )+    stdio.eprint(": ", {})+}++/// Print a cyan `info:` prefix to stdout.+pub fn info_prefix() void = trust {+    terminal.print_styled("info", terminal.Color.Cyan, terminal.Color.Default, terminal.Style.Plain)+    stdio.print(": ", {})+}--- a/src/src/git/export.sx+++ b/src/src/git/export.sx@@ -8,6 +8,7 @@  val str      = use("std/string") 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")@@ -384,7 +385,11 @@         if e.kind == tree.KIND_SUBTREE {             child = export_tree(ctx, e.target)         } elif e.kind == tree.KIND_SUBMODULE {-            val oid20: bytes.Bytes = bytes.Bytes.dup(bytes.Bytes.slice(bytes.bytes(e.target.ptr, 32), 0, 20))+            val oid20: bytes.Bytes = bytes.Bytes.dup(bytes.Bytes.slice(+                    bytes.bytes(e.target.ptr, 32),+                    0,+                    20+                ))             child = some(oid20)         } elif e.kind == tree.KIND_CONFLICT {             ctx.failed = true@@ -706,25 +711,21 @@             m.expanded = true             @append(stack, m)             val lc_opt = graph.load_commit(handles, m.id)-            match lc_opt {-                some lc => {-                    val pi: mut usize = @len(lc.c.parents)-                    for pi > 0 {-                        pi---                        val p = @get(lc.c.parents, pi)-                        if p is some pid {-                            if !contains(visited, pid) {-                                val pm: mut ref Mark = @alloc(@sizeof(Mark)) as ref Mark-                                pm.id = copy_id(pid)-                                pm.expanded = false-                                @append(stack, pm)-                            }+            if lc_opt is some lc {+                val pi: mut usize = @len(lc.c.parents)+                for pi > 0 {+                    pi--+                    val p = @get(lc.c.parents, pi)+                    if p is some pid {+                        if !contains(visited, pid) {+                            val pm: mut ref Mark = @alloc(@sizeof(Mark)) as ref Mark+                            pm.id = copy_id(pid)+                            pm.expanded = false+                            @append(stack, pm)                         }                     }-                    graph.free_loaded(lc)-                }-                none => {                 }+                graph.free_loaded(lc)             }         } else {             @append(visited, copy_id(m.id))@@ -750,12 +751,8 @@             return none         }         val lc: mut ref graph.LoadedCommit = none-        match lc_opt {-            some x => {-                lc = x-            }-            none => {-            }+        if lc_opt is some x {+            lc = x         }         val conflicted: bool = treewalk.conflicted(handles, lc.c.root_tree)         if !conflicted {@@ -831,7 +828,8 @@ pub fn run(repo: layout.Repo) i32 = trust {     val gitp: str.StringView = layout.git_dir(repo)     if !files.exists_dir(gitp) {-        stdio.eprint("vn: no git mirror; run `vn git import` first\n", {})+        msg.error_prefix()+        stdio.eprint("no git mirror; run `vn git import` first\n", {})         files.free_path(gitp)         return 1     }@@ -900,7 +898,8 @@             oidmap.free(trees)             oidmap.free(blobs)             free_ids(native_ids)-            stdio.eprint("vn: no operation state\n", {})+            msg.error_prefix()+            stdio.eprint("no operation state\n", {})             return 1         }     }@@ -971,7 +970,8 @@     }     val status: mut i32 = 0     if ctx.failed {-        stdio.eprint("vn: git export failed\n", {})+        msg.error_prefix()+        stdio.eprint("git export failed\n", {})         status = 1     } else {         for bm in resolved_bookmarks {@@ -1008,7 +1008,8 @@             }         }         if mut_skipped > 0 {-            stdio.eprint("vn: skipped {d} conflicted ref(s)\n", {mut_skipped})+            msg.warning_prefix()+            stdio.eprint("skipped {d} conflicted ref(s)\n", {mut_skipped})         }     }     if status == 0 {@@ -1016,11 +1017,13 @@         val stree = gitmap.save_map(repo, str.from_cstr(c"trees"), trees)         val sblob = gitmap.save_map(repo, str.from_cstr(c"blobs"), blobs)         if !sc || !stree || !sblob {-            stdio.eprint("vn: failed to write git mapping tables\n", {})+            msg.error_prefix()+            stdio.eprint("failed to write git mapping tables\n", {})             status = 1         }     }-    stdio.eprint("vn: exported {d} commits\n", {exported})+    msg.info_prefix()+    stdio.print("exported {d} commits\n", {exported})     view.free_view(v)     free_ids(roots)     free_ids(ordered)--- a/src/src/git/import.sx+++ b/src/src/git/import.sx@@ -4,6 +4,7 @@  val str       = use("std/string") val stdio     = use("std/stdio")+val msg       = use("../core/msg.sx") val os        = use("std/os") val time      = use("std/time") val bytes     = use("../core/bytes.sx")@@ -563,7 +564,8 @@         }         err _ => {             files.free_path(git_path)-            stdio.eprint("vn: cannot open git mirror: {s}\n", {git_path})+            msg.error_prefix()+            stdio.eprint("cannot open git mirror: {s}\n", {git_path})             return 1         }     }@@ -600,7 +602,8 @@         }     }     if !maps_ok {-        stdio.eprint("vn: corrupt git mapping table\n", {})+        msg.error_prefix()+        stdio.eprint("corrupt git mapping table\n", {})         object.free(git)         return 1     }@@ -613,7 +616,8 @@             wref = w         }         none => {-            stdio.eprint("vn: cannot create import pack\n", {})+            msg.error_prefix()+            stdio.eprint("cannot create import pack\n", {})             refs.free(refset)             oidmap.free(commits_map)             oidmap.free(trees_map)@@ -814,7 +818,8 @@     }     @listfree(queue)     if topo_failed || @len(order) != n {-        stdio.eprint("vn: git commit graph is incomplete or cyclic\n", {})+        msg.error_prefix()+        stdio.eprint("git commit graph is incomplete or cyclic\n", {})         for cl3 in children {             @listfree(cl3)         }@@ -952,7 +957,8 @@     oidmap.free(index_map)      if build_failed {-        stdio.eprint("vn: referenced git object is missing\n", {})+        msg.error_prefix()+        stdio.eprint("referenced git object is missing\n", {})         free_commit_records(records)         free_named_targets(branches)         free_named_targets(tags)@@ -970,7 +976,8 @@     }      if build_failed {-        stdio.eprint("vn: failed to import a tree or blob\n", {})+        msg.error_prefix()+        stdio.eprint("failed to import a tree or blob\n", {})         free_commit_records(records)         free_named_targets(branches)         free_named_targets(tags)@@ -1081,7 +1088,8 @@         oidmap.free(ctx.blobs_map)         store.close(store_handle)         object.free(ctx.git)-        stdio.eprint("vn: already up to date\n", {})+        msg.info_prefix()+        stdio.print("already up to date\n", {})         return 0     } @@ -1125,7 +1133,8 @@      val wrote: bool = writer.finish(ctx.writer)     if !wrote {-        stdio.eprint("vn: failed to write object pack\n", {})+        msg.error_prefix()+        stdio.eprint("failed to write object pack\n", {})         if old_encoded.ptr != none {             val op2: mut ref void = old_encoded.ptr as ref void             @free(op2)@@ -1162,7 +1171,8 @@     val saved_trees: bool = gitmap.save_map(repo, str.from_cstr(c"trees"), ctx.trees_map)     val saved_blobs: bool = gitmap.save_map(repo, str.from_cstr(c"blobs"), ctx.blobs_map)     if !saved_commits || !saved_trees || !saved_blobs {-        stdio.eprint("vn: failed to write git mapping tables\n", {})+        msg.error_prefix()+        stdio.eprint("failed to write git mapping tables\n", {})     }     val head_ok: bool = state.write_head(repo, op_id)     if head_ok {@@ -1173,8 +1183,9 @@         }     } -    stdio.eprint(-        "vn: imported {d} commits, {d} trees, {d} blobs\n",+    msg.info_prefix()+    stdio.print(+        "imported {d} commits, {d} trees, {d} blobs\n",         {ctx.new_commits, ctx.new_trees, ctx.new_blobs}     ) --- a/src/src/git/map.sx+++ b/src/src/git/map.sx@@ -174,29 +174,25 @@     val p: str.StringView = native_path(repo)     val data_opt = files.read_all(p)     files.free_path(p)-    match data_opt {-        some data => {-            val start: mut usize = 0-            val i: mut usize = 0-            for i <= data.len {-                if i == data.len || bytes.Bytes.at(data, i) == 10 {-                    val line: bytes.Bytes = bytes.Bytes.slice(data, start, i)-                    if line.len >= 64 {-                        val raw: ref u8 = @alloc(32) as ref u8-                        if objid.hex_decode(line.ptr, 32, raw) {-                            @append(out, objid.id(raw))-                        } else {-                            @free(raw as ref void)-                        }+    if data_opt is some data {+        val start: mut usize = 0+        val i: mut usize = 0+        for i <= data.len {+            if i == data.len || bytes.Bytes.at(data, i) == 10 {+                val line: bytes.Bytes = bytes.Bytes.slice(data, start, i)+                if line.len >= 64 {+                    val raw: ref u8 = @alloc(32) as ref u8+                    if objid.hex_decode(line.ptr, 32, raw) {+                        @append(out, objid.id(raw))+                    } else {+                        @free(raw as ref void)                     }-                    start = i + 1                 }-                i+++                start = i + 1             }-            files.free_buffer(data)-        }-        none => {+            i++         }+        files.free_buffer(data)     }     return out }--- a/src/src/main.sx+++ b/src/src/main.sx@@ -3,6 +3,7 @@  val stdio        = use("std/stdio") val str          = use("std/string")+val msg          = use("core/msg.sx") val bytes        = use("core/bytes.sx") val init_cmd     = use("cli/init_cmd.sx") val fsck_cmd     = use("cli/fsck_cmd.sx")@@ -47,13 +48,15 @@             val prefix: bytes.Bytes = bytes.bytes(c"-git-import:", 12)             if bytes.Bytes.starts_with(av, prefix) {                 if av.len == 12 {-                    stdio.eprint("vn: -git-import: requires a path\n", {})+                    msg.error_prefix()+                    stdio.eprint("-git-import: requires a path\n", {})                     return 1                 }                 val value: bytes.Bytes = bytes.Bytes.slice(av, 12, av.len)                 source = some str.view(value.ptr, value.len as i64)             } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 return 1             } else {                 mut_path = str.from_cstr(a)@@ -79,7 +82,8 @@             } elif !end_flags && (cmd_is(a, c"-v", 2) || cmd_is(a, c"-verbose", 8)) {                 verbose = true             } elif !end_flags && is_flag(a) {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 return 1             } else {                 mut_path = str.from_cstr(a)@@ -98,7 +102,8 @@             return some repo         }         none => {-            stdio.eprint("vn: not a veins repository\n", {})+            msg.error_prefix()+            stdio.eprint("not a veins repository\n", {})             return none         }     }@@ -136,13 +141,15 @@                         i++                     }                 } else {-                    stdio.eprint("vn: {s} requires a revision\n", {str.from_cstr(a)})+                    msg.error_prefix()+                    stdio.eprint("{s} requires a revision\n", {str.from_cstr(a)})                     return 1                 }             } elif !end_flags && cmd_is(a, c"-no-col-titles", 14) {                 col_titles = false             } elif !end_flags && is_flag(a) {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 return 1             } else {                 rev = bytes.from_cstr(a)@@ -180,12 +187,14 @@                         i++                     }                 } else {-                    stdio.eprint("vn: {s} requires a revision\n", {str.from_cstr(a)})+                    msg.error_prefix()+                    stdio.eprint("{s} requires a revision\n", {str.from_cstr(a)})                     @listfree(revs)                     return 1                 }             } elif !end_flags && is_flag(a) {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 @listfree(revs)                 return 1             } else {@@ -219,7 +228,8 @@             if !end_flags && cmd_is(a, c"--", 2) {                 end_flags = true             } elif !end_flags && is_flag(a) {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 @listfree(revs)                 return 1             } else {@@ -260,12 +270,14 @@                         i++                     }                 } else {-                    stdio.eprint("vn: {s} requires a message\n", {str.from_cstr(a)})+                    msg.error_prefix()+                    stdio.eprint("{s} requires a message\n", {str.from_cstr(a)})                     @listfree(parts)                     return err 1                 }             } elif !end_flags && is_flag(a) {-                stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})                 @listfree(parts)                 return err 1             } else {@@ -351,7 +363,8 @@             sub = s         }         none => {-            stdio.eprint("vn: expected an op subcommand (log, restore, revert)\n", {})+            msg.error_prefix()+            stdio.eprint("expected an op subcommand (log, restore, revert)\n", {})             return 1         }     }@@ -373,7 +386,8 @@         if o is some t {             status = op_cmd.restore(repo, bytes.from_cstr(t))         } else {-            stdio.eprint("vn: op restore requires an operation id\n", {})+            msg.error_prefix()+            stdio.eprint("op restore requires an operation id\n", {})         }     } elif cmd_is(sub, c"revert", 6) {         val o = @get(args, start + 1)@@ -380,10 +394,12 @@         if o is some t {             status = op_cmd.revert(repo, bytes.from_cstr(t))         } else {-            stdio.eprint("vn: op revert requires an operation id\n", {})+            msg.error_prefix()+            stdio.eprint("op revert requires an operation id\n", {})         }     } else {-        stdio.eprint("vn: unknown op subcommand: {s}\n", {str.from_cstr(sub)})+        msg.error_prefix()+        stdio.eprint("unknown op subcommand: {s}\n", {str.from_cstr(sub)})     }     layout.free_repo(repo)     return status@@ -457,7 +473,8 @@         return help_cmd.run(args, 2)     } -    stdio.eprint("vn: unknown command: {s}\n", {str.from_cstr(cmd)})+    msg.error_prefix()+    stdio.eprint("unknown command: {s}\n", {str.from_cstr(cmd)})     help_cmd.usage()     return 1 }--- a/src/src/object/graph.sx+++ b/src/src/object/graph.sx@@ -1,18 +1,18 @@ /// Commit graph traversal and revision resolution. -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 commit    = use("../object/commit.sx")-val tree      = use("../object/tree.sx")-val treewalk  = use("../object/treewalk.sx")-val view      = use("../object/view.sx")-val changeid  = use("changeid.sx")-val state     = use("../store/state.sx")-val store     = use("../store/store.sx")-val files     = use("../io/files.sx")-val viewops   = use("../store/viewops.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 commit   = use("../object/commit.sx")+val tree     = use("../object/tree.sx")+val treewalk = use("../object/treewalk.sx")+val view     = use("../object/view.sx")+val changeid = use("changeid.sx")+val state    = use("../store/state.sx")+val store    = use("../store/store.sx")+val files    = use("../io/files.sx")+val viewops  = use("../store/viewops.sx")  pub fn copy_id(id: objid.Id) objid.Id = trust {     val out: ref u8 = @alloc(32) as ref u8@@ -116,25 +116,17 @@         }         val pl_opt = load_commit(handles, pid)         val changed: mut bool = true-        match pl_opt {-            some parent => {-                changed = !objid.Id.eql(parent.c.root_tree, lc.c.root_tree)-                free_loaded(parent)-            }-            none => {-            }+        if pl_opt is some parent {+            changed = !objid.Id.eql(parent.c.root_tree, lc.c.root_tree)+            free_loaded(parent)         }         return changed     }     val t_opt = treewalk.read_tree(handles, lc.c.root_tree)     val changed: mut bool = true-    match t_opt {-        some t => {-            changed = @len(t.entries) > 0-            tree.free_tree(t)-        }-        none => {-        }+    if t_opt is some t {+        changed = @len(t.entries) > 0+        tree.free_tree(t)     }     return changed }@@ -157,17 +149,13 @@         }         @append(out, id)         val c_opt = load_commit(handles, id)-        match c_opt {-            some lc => {-                for p in lc.c.parents {-                    if !contains(out, p) && !contains(stack, p) {-                        @append(stack, copy_id(p))-                    }+        if c_opt is some lc {+            for p in lc.c.parents {+                if !contains(out, p) && !contains(stack, p) {+                    @append(stack, copy_id(p))                 }-                free_loaded(lc)-            }-            none => {             }+            free_loaded(lc)         }     }     @listfree(stack)--- a/src/src/object/treewalk.sx+++ b/src/src/object/treewalk.sx@@ -1,13 +1,13 @@ /// Helpers for reading, flattening, and comparing tree objects. -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 read   = use("../store/state.sx")-val store  = use("../store/store.sx")-val files  = use("../io/files.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 read  = use("../store/state.sx")+val store = use("../store/store.sx")+val files = use("../io/files.sx")  pub val KIND_MISSING: u8 = 0 @@ -139,7 +139,12 @@     return none } -fn merge_sort(xs: mut list[ref FlatEntry], lo: usize, hi: usize, tmp: mut list[ref FlatEntry]) void = trust {+fn merge_sort(+    xs: mut list[ref FlatEntry],+    lo: usize,+    hi: usize,+    tmp: mut list[ref FlatEntry]+) void = trust {     if hi - lo <= 1 {         return     }--- a/src/src/store/fsck.sx+++ b/src/src/store/fsck.sx@@ -2,6 +2,7 @@  val str       = use("std/string") val stdio     = use("std/stdio")+val msg       = use("../core/msg.sx") val bytes     = use("../core/bytes.sx") val lists     = use("../core/lists.sx") val derr      = use("../core/error.sx")@@ -29,23 +30,26 @@     warnings: mut usize } -fn report(ctx: mut Ctx, path: str.StringView, msg: str.StringView) void = {+fn report(ctx: mut Ctx, path: str.StringView, text: str.StringView) void = {     ctx.errors++-    trust stdio.eprint("fsck: {s}: {s}\n", {path, msg})+    trust msg.error_prefix()+    trust stdio.eprint("fsck: {s}: {s}\n", {path, text}) } -fn report_id(ctx: mut Ctx, path: str.StringView, msg: str.StringView, id: objid.Id) void = {+fn report_id(ctx: mut Ctx, path: str.StringView, text: str.StringView, id: objid.Id) void = {     ctx.errors++     val hx: ref u8 = objid.Id.hex(id)-    trust stdio.eprint("fsck: {s}: {s} {s}\n", {path, msg, str.from_cstr(hx)})+    trust msg.error_prefix()+    trust stdio.eprint("fsck: {s}: {s} {s}\n", {path, text, str.from_cstr(hx)})     val p: mut ref void = hx as ref void     trust @free(p) } -fn warn(ctx: mut Ctx, path: str.StringView, msg: str.StringView) void = {+fn warn(ctx: mut Ctx, path: str.StringView, text: str.StringView) void = {     ctx.warnings++     if ctx.verbose {-        trust stdio.eprint("fsck: warning: {s}: {s}\n", {path, msg})+        trust msg.warning_prefix()+        trust stdio.eprint("fsck: {s}: {s}\n", {path, text})     } } @@ -675,12 +679,15 @@     }     store.close_handles(handles)     if ctx.warnings > 0 && verbose {-        stdio.eprint("fsck: {d} warning(s)\n", {ctx.warnings})+        msg.warning_prefix()+        stdio.eprint("{d} warning(s)\n", {ctx.warnings})     }     if ctx.errors == 0 {-        stdio.eprint("fsck: clean\n", {})+        msg.info_prefix()+        stdio.print("fsck: clean\n", {})         return 0     }-    stdio.eprint("fsck: {d} error(s)\n", {ctx.errors})+    msg.error_prefix()+    stdio.eprint("{d} error(s)\n", {ctx.errors})     return 1 }--- a/src/src/store/txn.sx+++ b/src/src/store/txn.sx@@ -2,6 +2,7 @@ /// operation to a single pack, then advance the operation heads.  val stdio     = use("std/stdio")+val msg       = use("../core/msg.sx") val os        = use("std/os") val time      = use("std/time") val bytes     = use("../core/bytes.sx")@@ -337,13 +338,9 @@                 hid = x             }             val extra = load_view_for_head(st.handles, hid)-            match extra {-                some ev => {-                    merge_view_into(base_view, ev)-                    view.free_view(ev)-                }-                none => {-                }+            if extra is some ev {+                merge_view_into(base_view, ev)+                view.free_view(ev)             }             i++         }@@ -450,7 +447,8 @@      val wrote: bool = writer.finish(tx.writer)     if !wrote {-        stdio.eprint("vn: failed to write object pack\n", {})+        msg.error_prefix()+        stdio.eprint("failed to write object pack\n", {})         free_txn(tx)         return 1     }--- a/src/src/worktree/checkout.sx+++ b/src/src/worktree/checkout.sx@@ -2,6 +2,7 @@  val str        = use("std/string") val stdio      = use("std/stdio")+val msg        = use("../core/msg.sx") val allocators = use("std/allocators") val thread     = use("std/thread") val bytes      = use("../core/bytes.sx")@@ -699,7 +700,8 @@             v = x         }         none => {-            stdio.eprint("vn: no operation state; import a repository first\n", {})+            msg.error_prefix()+            stdio.eprint("no operation state; import a repository first\n", {})             store.close(store_handle)             return 1         }@@ -711,7 +713,8 @@             commit_id = id         }         none => {-            stdio.eprint("vn: unknown revision: {s}\n", {str.view(rev.ptr, rev.len as i64)})+            msg.error_prefix()+            stdio.eprint("unknown revision: {s}\n", {str.view(rev.ptr, rev.len as i64)})             view.free_view(v)             store.close(store_handle)             return 1@@ -724,7 +727,8 @@             cbody = b         }         none => {-            stdio.eprint("vn: cannot read commit\n", {})+            msg.error_prefix()+            stdio.eprint("cannot read commit\n", {})             view.free_view(v)             store.close(store_handle)             return 1@@ -738,7 +742,8 @@         }         err _ => {             files.free_buffer(cbody)-            stdio.eprint("vn: corrupt commit\n", {})+            msg.error_prefix()+            stdio.eprint("corrupt commit\n", {})             view.free_view(v)             store.close(store_handle)             return 1@@ -754,7 +759,8 @@     val root_fd: i32 = openat(-100, root_c, o_directory() | o_cloexec(), 0)     @free(root_c as ref void)     if root_fd < 0 {-        stdio.eprint("vn: cannot open working directory\n", {})+        msg.error_prefix()+        stdio.eprint("cannot open working directory\n", {})         store.close(store_handle)         return 1     }@@ -770,7 +776,8 @@     }     walk_tree(walk, root_tree, bytes.empty(), 0)     if walk.failed {-        stdio.eprint("vn: checkout tree validation failed\n", {})+        msg.error_prefix()+        stdio.eprint("checkout tree validation failed\n", {})         close(root_fd)         store.close(store_handle)         return 1@@ -780,7 +787,8 @@     for d in dirs {         if !ensure_dir(root_fd, d) {             dir_failed = true-            stdio.eprint("vn: cannot create directory: {s}\n", {str.view(d.ptr, d.len as i64)})+            msg.error_prefix()+            stdio.eprint("cannot create directory: {s}\n", {str.view(d.ptr, d.len as i64)})             break         }     }@@ -891,18 +899,21 @@     close(root_fd)     if had_failure {         if failed_path.len > 0 {+            msg.error_prefix()             stdio.eprint(-                "vn: checkout failed at: {s}\n",+                "checkout failed at: {s}\n",                 {str.view(failed_path.ptr, failed_path.len as i64)}             )         } else {-            stdio.eprint("vn: checkout failed\n", {})+            msg.error_prefix()+            stdio.eprint("checkout failed\n", {})         }         store.close(store_handle)         return 1     } -    stdio.eprint("vn: checked out {d} files\n", {n})+    msg.info_prefix()+    stdio.print("checked out {d} files\n", {n})     store.close(store_handle)     return 0 }--- a/src/src/worktree/ignore.sx+++ b/src/src/worktree/ignore.sx@@ -4,10 +4,10 @@ /// deciding which new files enter a snapshot: comments, negation, directory /// patterns, anchored patterns, `*`, `?`, and `**`. -val str    = use("std/string")-val bytes  = use("../core/bytes.sx")-val lists  = use("../core/lists.sx")-val files  = use("../io/files.sx")+val str   = use("std/string")+val bytes = use("../core/bytes.sx")+val lists = use("../core/lists.sx")+val files = use("../io/files.sx")  pub type Rule = {     pattern: mut bytes.Bytes@@ -113,7 +113,12 @@     ) } -pub fn load_file(rules: mut Rules, repo_root: str.StringView, base: bytes.Bytes, name: str.StringView) void = trust {+pub fn load_file(+    rules: mut Rules,+    repo_root: str.StringView,+    base: bytes.Bytes,+    name: str.StringView+) void = trust {     val base_view: str.StringView = files.to_view(base)     val dir: str.StringView = files.join(repo_root, base_view)     val path: str.StringView = files.join(dir, name)@@ -120,22 +125,18 @@     val data_opt = files.read_all(path)     files.free_path(dir)     files.free_path(path)-    match data_opt {-        some data => {-            val pos: mut usize = 0-            val line_start: mut usize = 0-            for pos <= data.len {-                val at_end: bool = pos == data.len-                if at_end || bytes.Bytes.at(data, pos) == 10 {-                    add_line(rules, base, bytes.Bytes.slice(data, line_start, pos))-                    line_start = pos + 1-                }-                pos+++    if data_opt is some data {+        val pos: mut usize = 0+        val line_start: mut usize = 0+        for pos <= data.len {+            val at_end: bool = pos == data.len+            if at_end || bytes.Bytes.at(data, pos) == 10 {+                add_line(rules, base, bytes.Bytes.slice(data, line_start, pos))+                line_start = pos + 1             }-            files.free_buffer(data)-        }-        none => {+            pos++         }+        files.free_buffer(data)     } } --- a/src/src/worktree/snapshot.sx+++ b/src/src/worktree/snapshot.sx@@ -5,34 +5,35 @@ /// message and is amended in place. A snapshot that produces the same tree as /// the existing commit does not create an operation. -val str        = use("std/string")-val stdio      = use("std/stdio")-val time       = use("std/time")-val bytes      = use("../core/bytes.sx")-val buf        = use("../core/buf.sx")-val reader     = use("../core/reader.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 tree       = use("../object/tree.sx")-val commit     = use("../object/commit.sx")-val blob       = use("../object/blob.sx")-val treewalk   = use("../object/treewalk.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 identity   = use("../core/identity.sx")-val gitmap    = use("../git/map.sx")-val view       = use("../object/view.sx")-val files      = use("../io/files.sx")-val native     = use("../io/native.sx")-val stat       = use("../io/stat.sx")-val raw        = use("../object/raw.sx")-val ignore     = use("ignore.sx")+val str      = use("std/string")+val stdio    = use("std/stdio")+val msg      = use("../core/msg.sx")+val time     = use("std/time")+val bytes    = use("../core/bytes.sx")+val buf      = use("../core/buf.sx")+val reader   = use("../core/reader.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 tree     = use("../object/tree.sx")+val commit   = use("../object/commit.sx")+val blob     = use("../object/blob.sx")+val treewalk = use("../object/treewalk.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 identity = use("../core/identity.sx")+val gitmap   = use("../git/map.sx")+val view     = use("../object/view.sx")+val files    = use("../io/files.sx")+val native   = use("../io/native.sx")+val stat     = use("../io/stat.sx")+val raw      = use("../object/raw.sx")+val ignore   = use("ignore.sx")  type CacheEntry = {     path: mut bytes.Bytes@@ -321,47 +322,23 @@         val kind: mut u8 = 0         val ex: mut u8 = 0         val idp: mut ref u8 = none-        match sz_o {-            some v => {-                sz = v-            }-            none => {-            }+        if sz_o is some v {+            sz = v         }-        match mt_o {-            some v => {-                mt = v-            }-            none => {-            }+        if mt_o is some v {+            mt = v         }-        match ino_o {-            some v => {-                ino = v-            }-            none => {-            }+        if ino_o is some v {+            ino = v         }-        match kind_o {-            some v => {-                kind = v-            }-            none => {-            }+        if kind_o is some v {+            kind = v         }-        match ex_o {-            some v => {-                ex = v-            }-            none => {-            }+        if ex_o is some v {+            ex = v         }-        match idp_o {-            some v => {-                idp = v-            }-            none => {-            }+        if idp_o is some v {+            idp = v         }         val e: mut ref CacheEntry = @alloc(@sizeof(CacheEntry)) as ref CacheEntry         e.path = bytes.Bytes.dup(p)@@ -429,7 +406,13 @@     return id } -fn cache_matches(e: ref CacheEntry, info: stat.StatInfo, executable: bool, now_ms: i64, written_ms: i64) bool = trust {+fn cache_matches(+    e: ref CacheEntry,+    info: stat.StatInfo,+    executable: bool,+    now_ms: i64,+    written_ms: i64+) bool = trust {     if e.size != info.size || e.mtime_ns != info.mtime_ns || e.inode != info.inode {         return false     }@@ -574,7 +557,13 @@             files.free_buffer(path)             continue         }-        val info: mut stat.StatInfo = stat.StatInfo{kind: 0, executable: false, size: 0, mtime_ns: 0, inode: 0}+        val info: mut stat.StatInfo = stat.StatInfo{+            kind: 0,+            executable: false,+            size: 0,+            mtime_ns: 0,+            inode: 0+        }         match stat_opt {             some si => {                 info = si@@ -625,12 +614,8 @@                     @free(cp)                 }             }-            match child_opt {-                some cid => {-                    @append(entries, tree.entry(bytes.Bytes.dup(name), tree.KIND_SUBTREE, cid))-                }-                none => {-                }+            if child_opt is some cid {+                @append(entries, tree.entry(bytes.Bytes.dup(name), tree.KIND_SUBTREE, cid))             }             files.free_buffer(path)         } elif info.kind == stat.KIND_LINK {@@ -637,16 +622,12 @@             val fs2: str.StringView = files.join(dir, str.from_cstr(name_c))             val target_opt = stat.link_target(fs2)             files.free_path(fs2)-            match target_opt {-                some target => {-                    val bid: objid.Id = add_blob_data(tx, target.ptr, target.len)-                    val kind: u8 = tree.KIND_SYMLINK-                    @append(entries, tree.entry(bytes.Bytes.dup(name), kind, bid))-                    @append(new_cache, new_entry(bytes.Bytes.dup(path), info, false, bid))-                    files.free_buffer(target)-                }-                none => {-                }+            if target_opt is some target {+                val bid: objid.Id = add_blob_data(tx, target.ptr, target.len)+                val kind: u8 = tree.KIND_SYMLINK+                @append(entries, tree.entry(bytes.Bytes.dup(name), kind, bid))+                @append(new_cache, new_entry(bytes.Bytes.dup(path), info, false, bid))+                files.free_buffer(target)             }             files.free_buffer(path)         } else {@@ -760,7 +741,8 @@             tx = t         }         none => {-            stdio.eprint("vn: cannot load repository state\n", {})+            msg.error_prefix()+            stdio.eprint("cannot load repository state\n", {})             return 1         }     }@@ -789,7 +771,8 @@                         old_tree = some(copy_id(c.root_tree))                     }                     err _ => {-                        stdio.eprint("vn: corrupt working-copy commit\n", {})+                        msg.error_prefix()+                        stdio.eprint("corrupt working-copy commit\n", {})                         store.close(st)                         txn.abort(tx)                         if wc.ptr != none {@@ -801,7 +784,8 @@                 }             }             none => {-                stdio.eprint("vn: missing working-copy commit\n", {})+                msg.error_prefix()+                stdio.eprint("missing working-copy commit\n", {})                 store.close(st)                 txn.abort(tx)                 if wc.ptr != none {@@ -846,7 +830,8 @@         }     }     if objid.Id.is_none(new_root) && !build_failed {-        stdio.eprint("vn: failed to build working-copy tree\n", {})+        msg.error_prefix()+        stdio.eprint("failed to build working-copy tree\n", {})         build_failed = true     }     if build_failed {