navid/veins / commit

1ac61b269383

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

parents: e8982561e073

Browse files at this commit · Download source

all: inf subcommand and aliases
--- a/veins/src/cli/checkout_cmd.sx+++ b/veins/src/cli/checkout_cmd.sx@@ -1,4 +1,5 @@-/// `vn checkout [rev]`: materialize a revision into the working directory.+/// `vn co [rev]` (alias `vn checkout`): materialize a revision into the+/// working directory.  val str      = use("std/string") val stdio    = use("std/stdio")--- a/veins/src/cli/diff_cmd.sx+++ b/veins/src/cli/diff_cmd.sx@@ -39,14 +39,15 @@ pub fn open_git(repo: layout.Repo) GitSource = trust {     val p: str.StringView = layout.git_dir(repo)     val r = object.open(p)-    files.free_path(p)     val g: mut GitSource = GitSource{repo: @zeroed, open: false}     match r {         ok x => {+            // object.open takes ownership of the path on success.             g.repo = x             g.open = true         }         err _ => {+            files.free_path(p)         }     }     return g--- a/veins/src/cli/help_cmd.sx+++ b/veins/src/cli/help_cmd.sx@@ -14,13 +14,14 @@     stdio.puts("commands:")     stdio.puts("  init         create a repository")     stdio.puts("  git          import from or export to git")-    stdio.puts("  checkout     write a revision into the working directory")-    stdio.puts("  status       show working-copy changes")+    stdio.puts("  co           write a revision into the working directory; alias: checkout")+    stdio.puts("  stat         show working-copy changes; alias: status")+    stdio.puts("  inf          show a repository breakdown")     stdio.puts("  log          show commit history")     stdio.puts("  diff         show a unified diff")     stdio.puts("  new          start a new change")-    stdio.puts("  describe     set the working-copy commit message")-    stdio.puts("  commit       describe and start a new change")+    stdio.puts("  desc         set the working-copy commit messag; alias: describe")+    stdio.puts("  go           describe and start a new change; alias: commit")     stdio.puts("  undo         restore the previous operation view")     stdio.puts("  op           operation log commands")     stdio.puts("  fsck         verify repository integrity")@@ -68,9 +69,11 @@ }  fn show_checkout() void = trust {-    stdio.puts("usage: vn checkout [rev]")+    stdio.puts("usage: vn co [rev]")     stdio.puts("")     stdio.puts("write a revision into the working directory")+    stdio.puts("")+    stdio.puts("aliases: checkout")     stdio.puts("")     stdio.puts("arguments:")     stdio.puts("  [rev]                     revision to check out")@@ -108,9 +111,18 @@ }  fn show_status() void = trust {-    stdio.puts("usage: vn status")+    stdio.puts("usage: vn stat")     stdio.puts("")     stdio.puts("show working-copy changes relative to the parent commit")+    stdio.puts("")+    stdio.puts("aliases: status")+}++fn show_inf() void = trust {+    stdio.puts("usage: vn inf")+    stdio.puts("")+    stdio.puts("show a repository overview with a language breakdown by file extension,")+    stdio.puts("line-of-code shares, author commit shares, and repository metadata") }  fn show_log() void = trust {@@ -136,15 +148,19 @@ }  fn show_describe() void = trust {-    stdio.puts("usage: vn describe [-message <message>] [<message>]")+    stdio.puts("usage: vn desc [-message <message>] [<message>]")     stdio.puts("")     stdio.puts("set the working-copy commit message")+    stdio.puts("")+    stdio.puts("aliases: describe") }  fn show_commit() void = trust {-    stdio.puts("usage: vn commit -message <message>")+    stdio.puts("usage: vn go -message <message>")     stdio.puts("")     stdio.puts("set the message and start a new change")+    stdio.puts("")+    stdio.puts("aliases: commit") }  fn show_undo() void = trust {@@ -195,8 +211,12 @@         show_init()         return 0     }-    if cmd_is(cmd, c"status", 6) {+    if cmd_is(cmd, c"stat", 4) || cmd_is(cmd, c"status", 6) {         show_status()+        return 0+    }+    if cmd_is(cmd, c"inf", 3) {+        show_inf()         return 0     }     if cmd_is(cmd, c"log", 3) {@@ -211,11 +231,11 @@         show_new()         return 0     }-    if cmd_is(cmd, c"describe", 8) {+    if cmd_is(cmd, c"desc", 4) || cmd_is(cmd, c"describe", 8) {         show_describe()         return 0     }-    if cmd_is(cmd, c"commit", 6) {+    if cmd_is(cmd, c"go", 2) || cmd_is(cmd, c"commit", 6) {         show_commit()         return 0     }@@ -247,7 +267,7 @@         show_git()         return 0     }-    if cmd_is(cmd, c"checkout", 8) {+    if cmd_is(cmd, c"co", 2) || cmd_is(cmd, c"checkout", 8) {         show_checkout()         return 0     }--- /dev/null+++ b/veins/src/cli/inf_cmd.sx@@ -0,0 +1,709 @@+/// `vn inf`: show a onefetch-style breakdown of the repository.+///+/// File statistics come from the recorded working-copy commit (no implicit+/// snapshot is created). Author statistics cover every commit reachable from+/// the current operation view. All work is done with the portable Spectre+/// standard library; no external tools are invoked.++val str      = use("std/string")+val stdio    = use("std/stdio")+val terminal = use("std/terminal")+val fs       = use("std/fs")+val bytes    = use("../core/bytes.sx")+val lists    = use("../core/lists.sx")+val datetime = use("../core/datetime.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 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 BAR_WIDTH: u64 = 24++type GitSource = {+    repo: mut object.GitRepo+    open: mut bool+}++type ExtStat = {+    ext: mut bytes.Bytes+    files: mut u64+    lines: mut u64+    bytes: mut u64+}++type AuthorStat = {+    name: mut bytes.Bytes+    commits: mut u64+}++type Totals = {+    files: mut u64+    lines: mut u64+    bytes: mut u64+}++type History = {+    commits: mut u64+    created: mut i64+    last: mut i64+    has_time: mut bool+}++fn open_git(repo: layout.Repo) GitSource = trust {+    val p: str.StringView = layout.git_dir(repo)+    val r = object.open(p)+    val g: mut GitSource = GitSource{repo: @zeroed, open: false}+    match r {+        ok x => {+            // object.open takes ownership of the path on success.+            g.repo = x+            g.open = true+        }+        err _ => {+            files.free_path(p)+        }+    }+    return g+}++fn close_git(g: mut GitSource) void = trust {+    if g.open {+        object.free(g.repo)+        g.open = false+    }+}++fn new_ext(ext: bytes.Bytes) ref ExtStat = trust {+    val e: mut ref ExtStat = @alloc(@sizeof(ExtStat)) as ref ExtStat+    e.ext = ext+    e.files = 0+    e.lines = 0+    e.bytes = 0+    return e+}++fn free_exts(xs: list[ref ExtStat]) void = trust {+    for e in xs {+        if e.ext.ptr != none {+            val p: mut ref void = e.ext.ptr as ref void+            @free(p)+        }+        val ep: mut ref void = e as ref void+        @free(ep)+    }+    @listfree(xs)+}++fn new_author(name: bytes.Bytes) ref AuthorStat = trust {+    val a: mut ref AuthorStat = @alloc(@sizeof(AuthorStat)) as ref AuthorStat+    a.name = bytes.Bytes.dup(name)+    a.commits = 0+    return a+}++fn free_authors(xs: list[ref AuthorStat]) void = trust {+    for a in xs {+        if a.name.ptr != none {+            val p: mut ref void = a.name.ptr as ref void+            @free(p)+        }+        val ap: mut ref void = a as ref void+        @free(ap)+    }+    @listfree(xs)+}++fn find_ext(xs: list[ref ExtStat], ext: bytes.Bytes) option[ref ExtStat] = trust {+    for e in xs {+        if bytes.Bytes.eql(e.ext, ext) {+            return some e+        }+    }+    return none+}++fn find_author(xs: list[ref AuthorStat], name: bytes.Bytes) option[ref AuthorStat] = trust {+    for a in xs {+        if bytes.Bytes.eql(a.name, name) {+            return some a+        }+    }+    return none+}++fn ascii_lower(c: u8) u8 = trust {+    if c >= 65 && c <= 90 {+        return (c + 32) as u8+    }+    return c+}++/// Return the lowercased extension of a path, including the leading dot.+fn ext_of(path: bytes.Bytes) bytes.Bytes = trust {+    val base_start: mut usize = 0+    val i: mut usize = 0+    for i < path.len {+        if bytes.Bytes.at(path, i) == 47 {+            base_start = i + 1+        }+        i+++    }+    val dot: mut i64 = -1+    val j: mut usize = base_start+    for j < path.len {+        if bytes.Bytes.at(path, j) == 46 {+            dot = j as i64+        }+        j+++    }+    if dot < 0 || (dot as usize) <= base_start || (dot as usize) + 1 >= path.len {+        return bytes.Bytes.dup(bytes.bytes(c"(none)", 6))+    }+    val raw: bytes.Bytes = bytes.Bytes.slice(path, dot as usize, path.len)+    val out: ref u8 = @alloc(raw.len) as ref u8+    val k: mut usize = 0+    for k < raw.len {+        @store8(@ptradd(out, k as i64), ascii_lower(bytes.Bytes.at(raw, k)))+        k+++    }+    return bytes.bytes(out, raw.len)+}++fn is_blank_char(c: u8) bool = trust {+    return c == 32 || c == 9 || c == 13+}++fn looks_binary(data: bytes.Bytes) bool = trust {+    val limit: usize = 8192+    val n: mut usize = limit+    if data.len < limit {+        n = data.len+    }+    val i: mut usize = 0+    for i < n {+        if bytes.Bytes.at(data, i) == 0 {+            return true+        }+        i+++    }+    return false+}++/// Count newline-separated lines that contain a non-whitespace byte.+fn count_nonblank(data: bytes.Bytes) u64 = trust {+    val count: mut u64 = 0+    val i: mut usize = 0+    for i < data.len {+        val line_end: mut usize = i+        for line_end < data.len && bytes.Bytes.at(data, line_end) != 10 {+            line_end+++        }+        val blank: mut bool = true+        val j: mut usize = i+        for j < line_end {+            if !is_blank_char(bytes.Bytes.at(data, j)) {+                blank = false+                break+            }+            j+++        }+        if !blank {+            count+++        }+        if line_end >= data.len {+            i = data.len+        } else {+            i = line_end + 1+        }+    }+    return count+}++fn add_file(stats: mut list[ref ExtStat], path: bytes.Bytes, lines: u64, size: u64) void = trust {+    val ext: bytes.Bytes = ext_of(path)+    val found = find_ext(stats, ext)+    if found is some e {+        e.files+++        e.lines += lines+        e.bytes += size+        if ext.ptr != none {+            val p: mut ref void = ext.ptr as ref void+            @free(p)+        }+        return+    }+    val e2: mut ref ExtStat = new_ext(ext)+    e2.files = 1+    e2.lines = lines+    e2.bytes = size+    @append(stats, e2)+}++fn analyze_files(+    handles: list[ref store.Handle],+    root_tree: objid.Id,+    git: object.GitRepo,+    has_git: bool,+    stats: mut list[ref ExtStat]+) Totals = trust {+    val totals: mut Totals = Totals{files: 0, lines: 0, bytes: 0}+    val entries: list[ref treewalk.FlatEntry] = treewalk.flatten(handles, root_tree)+    for e in entries {+        if e.kind == tree.KIND_FILE || e.kind == tree.KIND_EXECUTABLE {+            totals.files+++            val data_opt = content.read_blob(handles, e.target, git, has_git)+            val lines: mut u64 = 0+            val size: mut u64 = 0+            if data_opt is some data {+                size = data.len as u64+                totals.bytes += size+                if !looks_binary(data) {+                    lines = count_nonblank(data)+                }+                totals.lines += lines+                add_file(stats, e.path, lines, size)+                files.free_buffer(data)+            } else {+                add_file(stats, e.path, 0, 0)+            }+        }+    }+    treewalk.free_flat(entries)+    return totals+}++fn collect_history(+    handles: list[ref store.Handle],+    v: ref view.View,+    authors: mut list[ref AuthorStat]+) History = trust {+    val hist: mut History = History{commits: 0, created: 0, last: 0, has_time: false}+    val roots: list[objid.Id] = graph.roots(v)+    val ids: list[objid.Id] = graph.collect(handles, roots)+    graph.free_ids(roots)+    for id in ids {+        val lc_opt = graph.load_commit(handles, id)+        if lc_opt is some lc {+            hist.commits+++            val secs: i64 = lc.c.committer.seconds+            if !hist.has_time {+                hist.created = secs+                hist.last = secs+                hist.has_time = true+            } else {+                if secs < hist.created {+                    hist.created = secs+                }+                if secs > hist.last {+                    hist.last = secs+                }+            }+            val found = find_author(authors, lc.c.author.name)+            if found is some a {+                a.commits+++            } else {+                val name: mut bytes.Bytes = lc.c.author.name+                if name.len == 0 {+                    name = bytes.bytes(c"(unknown)", 9)+                }+                val a2: mut ref AuthorStat = new_author(name)+                a2.commits = 1+                @append(authors, a2)+            }+            graph.free_loaded(lc)+        }+    }+    graph.free_ids(ids)+    return hist+}++fn sort_exts(xs: mut list[ref ExtStat]) void = trust {+    val i: mut usize = 1+    for i < @len(xs) {+        val cur_opt = @get(xs, i)+        val cur: mut ref ExtStat = none+        if cur_opt is some c {+            cur = c+        }+        val j: mut usize = i+        for j > 0 {+            val prev_opt = @get(xs, j - 1)+            val prev: mut ref ExtStat = none+            if prev_opt is some p {+                prev = p+            }+            val keep: bool = prev.lines > cur.lines+                || (prev.lines == cur.lines && bytes.Bytes.cmp(prev.ext, cur.ext) <= 0)+            if keep {+                break+            }+            @set(xs, j, prev)+            j--+        }+        @set(xs, j, cur)+        i+++    }+}++fn sort_authors(xs: mut list[ref AuthorStat]) void = trust {+    val i: mut usize = 1+    for i < @len(xs) {+        val cur_opt = @get(xs, i)+        val cur: mut ref AuthorStat = none+        if cur_opt is some c {+            cur = c+        }+        val j: mut usize = i+        for j > 0 {+            val prev_opt = @get(xs, j - 1)+            val prev: mut ref AuthorStat = none+            if prev_opt is some p {+                prev = p+            }+            val keep: bool = prev.commits > cur.commits+                || (prev.commits == cur.commits && bytes.Bytes.cmp(prev.name, cur.name) <= 0)+            if keep {+                break+            }+            @set(xs, j, prev)+            j--+        }+        @set(xs, j, cur)+        i+++    }+}++fn print_left(+    text: str.StringView,+    width: usize,+    color: terminal.Color,+    dim: bool+) void = trust {+    if dim {+        terminal.print_styled(text, color, terminal.Color.Default, terminal.Style.Dim)+    } elif color == terminal.Color.Default {+        stdio.print("{s}", {text})+    } else {+        terminal.print(text, color)+    }+    val pad: mut i64 = width as i64 - text.len+    for pad > 0 {+        stdio.print(" ", {})+        pad--+    }+}++fn color_for(i: usize) terminal.Color = trust {+    val n: usize = i % 8+    if n == 0 {+        return terminal.Color.BrightCyan+    }+    if n == 1 {+        return terminal.Color.BrightGreen+    }+    if n == 2 {+        return terminal.Color.BrightYellow+    }+    if n == 3 {+        return terminal.Color.BrightMagenta+    }+    if n == 4 {+        return terminal.Color.BrightBlue+    }+    if n == 5 {+        return terminal.Color.BrightRed+    }+    if n == 6 {+        return terminal.Color.Cyan+    }+    return terminal.Color.Green+}++fn percent(num: u64, total: u64) u64 = trust {+    if total == 0 {+        return 0+    }+    return (num * 100 + total / 2) / total+}++fn print_percent(pct: u64) void = trust {+    if pct < 10 {+        stdio.print("  {d}", {pct})+    } elif pct < 100 {+        stdio.print(" {d}", {pct})+    } else {+        stdio.print("{d}", {pct})+    }+}++fn print_bar(num: u64, total: u64, color: terminal.Color) void = trust {+    val filled: mut u64 = 0+    if total > 0 && num > 0 {+        filled = (num * BAR_WIDTH + total / 2) / total+        if filled == 0 {+            filled = 1+        }+        if filled > BAR_WIDTH {+            filled = BAR_WIDTH+        }+    }+    terminal.print_repeat(str.from_cstr(c"█"), filled as i64, color)+    terminal.print_repeat(+        str.from_cstr(c"░"),+        (BAR_WIDTH - filled) as i64,+        terminal.Color.BrightBlack+    )+}++fn row_value(label: str.StringView, value: str.StringView) void = trust {+    print_left(label, 14, terminal.Color.Default, true)+    stdio.print("{s}\n", {value})+}++fn row_number(label: str.StringView, value: u64) void = trust {+    print_left(label, 14, terminal.Color.Default, true)+    stdio.print("{d}\n", {value})+}++fn dir_size(path: str.StringView, depth: usize) u64 = trust {+    if depth > 64 {+        return 0+    }+    val names: list[ref u8] = files.list_dir(path)+    val total: mut u64 = 0+    for n in names {+        val child: str.StringView = files.join(path, str.from_cstr(n))+        if fs.is_directory(child) {+            total += dir_size(child, depth + 1)+        } else {+            val sz = fs.file_size(child)+            if sz is some size {+                if size > 0 {+                    total += size as u64+                }+            }+        }+        files.free_path(child)+    }+    files.free_names(names)+    return total+}++fn print_size(n: u64) void = trust {+    if n >= 1073741824 {+        val whole: u64 = n / 1073741824+        val frac: u64 = ((n % 1073741824) * 10) / 1073741824+        stdio.print("{d}.{d} GiB\n", {whole, frac})+    } elif n >= 1048576 {+        val whole: u64 = n / 1048576+        val frac: u64 = ((n % 1048576) * 10) / 1048576+        stdio.print("{d}.{d} MiB\n", {whole, frac})+    } elif n >= 1024 {+        val whole: u64 = n / 1024+        val frac: u64 = ((n % 1024) * 10) / 1024+        stdio.print("{d}.{d} KiB\n", {whole, frac})+    } else {+        stdio.print("{d} B\n", {n})+    }+}++fn show_date(label: str.StringView, seconds: i64) void = trust {+    val stamp: bytes.Bytes = datetime.format_utc(seconds)+    val view_len: mut usize = stamp.len+    if view_len > 10 {+        view_len = 10+    }+    print_left(label, 14, terminal.Color.Default, true)+    stdio.print("{s}\n", {str.view(stamp.ptr, view_len as i64)})+    files.free_buffer(stamp)+}++fn print_languages(exts: mut list[ref ExtStat], totals: Totals) void = trust {+    terminal.puts_styled(+        "Languages (by lines of code)",+        terminal.Color.BrightCyan,+        terminal.Color.Default,+        terminal.Style.Bold+    )+    stdio.print("\n", {})+    if @len(exts) == 0 {+        stdio.print("  no tracked files\n", {})+        return+    }+    sort_exts(exts)+    val w_ext: mut usize = 6+    val i: mut usize = 0+    for i < @len(exts) {+        val o = @get(exts, i)+        if o is some e {+            if e.ext.len > w_ext {+                w_ext = e.ext.len+            }+        }+        i+++    }+    val k: mut usize = 0+    for k < @len(exts) {+        val o = @get(exts, k)+        if o is some e {+            val ext_view: str.StringView = str.view(e.ext.ptr, e.ext.len as i64)+            print_left(ext_view, w_ext, terminal.Color.Default, false)+            stdio.print("  ", {})+            print_bar(e.lines, totals.lines, color_for(k))+            stdio.print("  ", {})+            print_percent(percent(e.lines, totals.lines))+            stdio.print(+                "{s}  {d} lines  {d} files\n",+                {str.from_cstr(c"%"), e.lines, e.files}+            )+        }+        k+++    }+}++fn print_authors(authors: mut list[ref AuthorStat], commits: u64) void = trust {+    terminal.puts_styled(+        "Authors (by commits)",+        terminal.Color.BrightCyan,+        terminal.Color.Default,+        terminal.Style.Bold+    )+    stdio.print("\n", {})+    if @len(authors) == 0 {+        stdio.print("  no commits\n", {})+        return+    }+    sort_authors(authors)+    val w_name: mut usize = 6+    val i: mut usize = 0+    for i < @len(authors) {+        val o = @get(authors, i)+        if o is some a {+            if a.name.len > w_name {+                w_name = a.name.len+            }+        }+        i+++    }+    val k: mut usize = 0+    for k < @len(authors) {+        val o = @get(authors, k)+        if o is some a {+            val name_view: str.StringView = str.view(a.name.ptr, a.name.len as i64)+            print_left(name_view, w_name, terminal.Color.Cyan, false)+            stdio.print("  ", {})+            print_bar(a.commits, commits, color_for(k))+            stdio.print("  ", {})+            print_percent(percent(a.commits, commits))+            stdio.print("{s}  {d} commits\n", {str.from_cstr(c"%"), a.commits})+        }+        k+++    }+}++pub fn run(repo: layout.Repo) i32 = trust {+    val st: store.Store = store.open_all(repo)+    val v_opt = state.current_view(repo, st.handles)+    val v: mut ref view.View = none+    match v_opt {+        some x => {+            v = x+        }+        none => {+            v = state.empty_view()+        }+    }++    val wc_opt = viewops.working_copy(v)+    val wc: mut objid.Id = objid.id_none()+    val have_wc: mut bool = false+    if wc_opt is some id {+        wc = id+        have_wc = true+    }++    val wc_tree: mut option[objid.Id] = none+    if have_wc {+        val lc_opt = graph.load_commit(st.handles, wc)+        if lc_opt is some lc {+            wc_tree = some(graph.copy_id(lc.c.root_tree))+            graph.free_loaded(lc)+        }+    }++    val git: mut GitSource = open_git(repo)+    val exts: mut list[ref ExtStat] = lists.new[ref ExtStat]()+    val authors: mut list[ref AuthorStat] = lists.new[ref AuthorStat]()++    val totals: mut Totals = Totals{files: 0, lines: 0, bytes: 0}+    if wc_tree is some tree_id {+        totals = analyze_files(st.handles, tree_id, git.repo, git.open, exts)+    }+    val hist: History = collect_history(st.handles, v, authors)++    stdio.print("\n", {})+    terminal.puts_styled(+        "veins repository overview",+        terminal.Color.BrightCyan,+        terminal.Color.Default,+        terminal.Style.Bold+    )+    stdio.print("\n", {})++    row_value(str.from_cstr(c"Project"), files.basename(layout.root_view(repo)))++    print_left(str.from_cstr(c"HEAD"), 14, terminal.Color.Default, true)+    if have_wc {+        val hex: ref u8 = objid.Id.hex(wc)+        stdio.print("{s}\n", {str.view(hex, 12)})+        @free(hex as ref void)+    } else {+        stdio.print("<none>\n", {})+    }++    row_number(str.from_cstr(c"Changes"), hist.commits)+    row_number(str.from_cstr(c"Bookmarks"), @len(v.bookmarks) as u64)+    row_number(str.from_cstr(c"Tags"), @len(v.tags) as u64)+    row_number(str.from_cstr(c"Files"), totals.files)+    row_number(str.from_cstr(c"Lines"), totals.lines)+    row_number(str.from_cstr(c"Authors"), @len(authors) as u64)+    if hist.has_time {+        show_date(str.from_cstr(c"Created"), hist.created)+        show_date(str.from_cstr(c"Last change"), hist.last)+    }+    print_left(str.from_cstr(c"Size"), 14, terminal.Color.Default, true)+    val veins_path: str.StringView = layout.veins_dir(repo)+    print_size(dir_size(veins_path, 0))+    files.free_path(veins_path)++    stdio.print("\n", {})+    print_languages(exts, totals)+    stdio.print("\n", {})+    print_authors(authors, hist.commits)+    stdio.print("\n", {})++    free_exts(exts)+    free_authors(authors)+    if wc_tree is some tree_id {+        if tree_id.ptr != none {+            val tp: mut ref void = tree_id.ptr as ref void+            @free(tp)+        }+    }+    if wc.ptr != none {+        val wp: mut ref void = wc.ptr as ref void+        @free(wp)+    }+    close_git(git)+    view.free_view(v)+    store.close(st)+    return 0+}--- a/veins/src/cli/new_cmd.sx+++ b/veins/src/cli/new_cmd.sx@@ -1,4 +1,4 @@-/// `vn describe`, `vn new`, and `vn commit`.+/// `vn desc` (alias `vn describe`), `vn new`, and `vn go` (alias `vn commit`).  val stdio    = use("std/stdio") val msg      = use("../core/msg.sx")--- a/veins/src/cli/status_cmd.sx+++ b/veins/src/cli/status_cmd.sx@@ -1,4 +1,5 @@-/// `vn status`: show working-copy changes relative to the parent commit.+/// `vn stat` (alias `vn status`): show working-copy changes relative to the+/// parent commit.  val stdio    = use("std/stdio") val msg      = use("../core/msg.sx")--- a/veins/src/core/identity.sx+++ b/veins/src/core/identity.sx@@ -1,12 +1,14 @@-/// Author/committer identity from the local config or environment.+/// Author/committer identity from repository config, the user config at+/// `~/.local/config/veins/veins.toml`, or the 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 bytes      = use("../core/bytes.sx")+val prim       = use("../core/primitives.sx")+val layout     = use("../store/layout.sx")+val files      = use("../io/files.sx")+val userconfig = use("userconfig.sx")  fn trim(b: bytes.Bytes) bytes.Bytes = trust {     val start: mut usize = 0@@ -86,11 +88,21 @@ fn first_config(     repo: layout.Repo,     key: bytes.Bytes,+    want_name: bool,     env1: ref u8,     env2: ref u8 ) bytes.Bytes = trust {     val c = config_value(repo, key)     if c is some v {+        return v+    }+    val u: mut option[bytes.Bytes] = none+    if want_name {+        u = userconfig.author_name()+    } else {+        u = userconfig.author_email()+    }+    if u is some v {         return v     }     val e1 = env_dup(env1)@@ -108,6 +120,7 @@     val name: bytes.Bytes = first_config(         repo,         bytes.bytes(c"user.name", 9),+        true,         c"GIT_AUTHOR_NAME",         c"USER"     )@@ -114,6 +127,7 @@     val email: bytes.Bytes = first_config(         repo,         bytes.bytes(c"user.email", 10),+        false,         c"GIT_AUTHOR_EMAIL",         c"EMAIL"     )--- /dev/null+++ b/veins/src/core/userconfig.sx@@ -0,0 +1,243 @@+/// User-level configuration from `~/.local/config/veins/veins.toml`.+///+/// The file is optional. The only table currently understood is `[user]`:+///+///     [user]+///     name = "Your Name"+///     email = "you@example.com"+///+/// Values are returned as owned byte spans so callers can hand them to the+/// same signature path used for repository configuration and environment+/// overrides.++val str   = use("std/string")+val fs    = use("std/fs")+val bytes = use("../core/bytes.sx")+val buf   = use("../core/buf.sx")+val files = use("../io/files.sx")++fn trim(b: bytes.Bytes) bytes.Bytes = trust {+    val start: mut usize = 0+    val end: mut usize = b.len+    for start < end {+        val c: u8 = bytes.Bytes.at(b, start)+        if c != 32 && c != 9 && c != 13 && c != 10 {+            break+        }+        start+++    }+    for end > start {+        val c2: u8 = bytes.Bytes.at(b, end - 1)+        if c2 != 32 && c2 != 9 && c2 != 13 && c2 != 10 {+            break+        }+        end--+    }+    return bytes.Bytes.slice(b, start, end)+}++fn config_path() option[str.StringView] = trust {+    val home = fs.home_dir_cstr()+    match home {+        some h => {+            return some files.join3(+                str.from_cstr(h),+                str.from_cstr(c".local/config/veins"),+                str.from_cstr(c"veins.toml")+            )+        }+        none => {+            return none+        }+    }+}++/// Remove a trailing TOML comment that is outside a quoted string.+fn strip_comment(v: bytes.Bytes) bytes.Bytes = trust {+    val i: mut usize = 0+    val in_double: mut bool = false+    val in_single: mut bool = false+    val escaped: mut bool = false+    for i < v.len {+        val c: u8 = bytes.Bytes.at(v, i)+        if in_double {+            if escaped {+                escaped = false+            } elif c == 92 {+                escaped = true+            } elif c == 34 {+                in_double = false+            }+        } elif in_single {+            if c == 39 {+                in_single = false+            }+        } elif c == 34 {+            in_double = true+        } elif c == 39 {+            in_single = true+        } elif c == 35 {+            return trim(bytes.Bytes.slice(v, 0, i))+        }+        i+++    }+    return trim(v)+}++/// Decode a TOML string value. Unquoted values are accepted as a convenience.+fn unquote(v: bytes.Bytes) option[bytes.Bytes] = trust {+    if v.len >= 2 {+        val first: u8 = bytes.Bytes.at(v, 0)+        val last: u8 = bytes.Bytes.at(v, v.len - 1)+        if first == 39 && last == 39 {+            return some(bytes.Bytes.dup(bytes.Bytes.slice(v, 1, v.len - 1)))+        }+        if first == 34 && last == 34 {+            val inner: bytes.Bytes = bytes.Bytes.slice(v, 1, v.len - 1)+            val out: mut buf.Buf = buf.new(inner.len + 1)+            val i: mut usize = 0+            for i < inner.len {+                val c: u8 = bytes.Bytes.at(inner, i)+                if c == 92 && i + 1 < inner.len {+                    val next: u8 = bytes.Bytes.at(inner, i + 1)+                    if next == 34 {+                        buf.Buf.put_u8(out, 34)+                    } elif next == 92 {+                        buf.Buf.put_u8(out, 92)+                    } elif next == 110 {+                        buf.Buf.put_u8(out, 10)+                    } elif next == 114 {+                        buf.Buf.put_u8(out, 13)+                    } elif next == 116 {+                        buf.Buf.put_u8(out, 9)+                    } else {+                        buf.Buf.put_u8(out, 92)+                        buf.Buf.put_u8(out, next)+                    }+                    i = i + 2+                } else {+                    buf.Buf.put_u8(out, c)+                    i+++                }+            }+            val result: bytes.Bytes = bytes.Bytes.dup(buf.Buf.view(out))+            buf.Buf.free(out)+            return some(result)+        }+    }+    if v.len == 0 {+        return none+    }+    return some(bytes.Bytes.dup(v))+}++fn key_matches(key: bytes.Bytes, in_user: bool, want_name: bool) bool = trust {+    if in_user {+        if want_name {+            return bytes.Bytes.eql(key, bytes.bytes(c"name", 4))+        }+        return bytes.Bytes.eql(key, bytes.bytes(c"email", 5))+    }+    if want_name {+        return bytes.Bytes.eql(key, bytes.bytes(c"user.name", 9))+    }+    return bytes.Bytes.eql(key, bytes.bytes(c"user.email", 10))+}++fn scan(data: bytes.Bytes, want_name: bool) option[bytes.Bytes] = trust {+    val in_user: mut bool = false+    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 raw: bytes.Bytes = bytes.Bytes.slice(data, start, pos)+            val line: bytes.Bytes = trim(raw)+            if line.len > 0 && bytes.Bytes.at(line, 0) != 35 {+                if bytes.Bytes.at(line, 0) == 91 {+                    val close: mut i64 = -1+                    val j: mut usize = 1+                    for j < line.len {+                        if bytes.Bytes.at(line, j) == 93 {+                            close = j as i64+                            break+                        }+                        j+++                    }+                    if close > 0 {+                        val table: bytes.Bytes = trim(+                            bytes.Bytes.slice(line, 1, close as usize)+                        )+                        in_user = bytes.Bytes.eql(table, bytes.bytes(c"user", 4))+                    }+                } else {+                    val eq: mut i64 = -1+                    val k: mut usize = 0+                    for k < line.len {+                        if bytes.Bytes.at(line, k) == 61 {+                            eq = k as i64+                            break+                        }+                        k+++                    }+                    if eq >= 0 {+                        val key: bytes.Bytes = trim(+                            bytes.Bytes.slice(line, 0, eq as usize)+                        )+                        if key_matches(key, in_user, want_name) {+                            val raw_value: bytes.Bytes = strip_comment(+                                trim(bytes.Bytes.slice(line, eq as usize + 1, line.len))+                            )+                            val decoded = unquote(raw_value)+                            if decoded is some value {+                                if value.len > 0 {+                                    return some value+                                }+                            }+                        }+                    }+                }+            }+            start = pos + 1+        }+        pos+++    }+    return none+}++fn read_value(want_name: bool) option[bytes.Bytes] = trust {+    val path_opt = config_path()+    val path: mut str.StringView = str.view(none, 0)+    match path_opt {+        some p => {+            path = p+        }+        none => {+            return none+        }+    }+    val data_opt = files.read_all(path)+    files.free_path(path)+    val data: mut bytes.Bytes = bytes.empty()+    match data_opt {+        some d => {+            data = d+        }+        none => {+            return none+        }+    }+    val out: option[bytes.Bytes] = scan(data, want_name)+    files.free_buffer(data)+    return out+}++/// The configured author name, if the user file exists and defines one.+pub fn author_name() option[bytes.Bytes] = trust {+    return read_value(true)+}++/// The configured author email, if the user file exists and defines one.+pub fn author_email() option[bytes.Bytes] = trust {+    return read_value(false)+}--- a/veins/src/git/export.sx+++ b/veins/src/git/export.sx@@ -834,15 +834,16 @@         return 1     }     val git_opt = object.open(gitp)-    files.free_path(gitp)     val git_repo: mut object.GitRepo = @zeroed     val git_open: mut bool = false     match git_opt {         ok g => {+            // object.open takes ownership of the path on success.             git_repo = g             git_open = true         }         err _ => {+            files.free_path(gitp)         }     } --- a/veins/src/git/object.sx+++ b/veins/src/git/object.sx@@ -1170,6 +1170,8 @@     return ok p } +/// Open the git mirror. On success the returned repository owns `git_dir`;+/// on error the caller retains ownership of `git_dir`. pub fn open(git_dir: str.StringView) result[GitRepo, GitError] = trust {     val packs: mut list[ref GitPack] = lists.new[ref GitPack]()     val pack_dir: str.StringView = files.join(git_dir, str.from_cstr(c"objects/pack"))--- a/veins/src/main.sx+++ b/veins/src/main.sx@@ -17,6 +17,7 @@ val diff_cmd     = use("cli/diff_cmd.sx") val new_cmd      = use("cli/new_cmd.sx") val op_cmd       = use("cli/op_cmd.sx")+val inf_cmd      = use("cli/inf_cmd.sx") val lists        = use("core/lists.sx") val layout       = use("store/layout.sx") @@ -114,6 +115,20 @@     match repo_opt {         some repo => {             val status: i32 = status_cmd.run(repo)+            layout.free_repo(repo)+            return status+        }+        none => {+            return 1+        }+    }+}++fn run_inf() i32 = trust {+    val repo_opt = open_repo_or_error(str.from_cstr(c"."))+    match repo_opt {+        some repo => {+            val status: i32 = inf_cmd.run(repo)             layout.free_repo(repo)             return status         }@@ -429,11 +444,14 @@     if cmd_is(cmd, c"git", 3) {         return git_cmd.run(args, 2)     }-    if cmd_is(cmd, c"checkout", 8) {+    if cmd_is(cmd, c"co", 2) || cmd_is(cmd, c"checkout", 8) {         return checkout_cmd.run(args, 2)     }-    if cmd_is(cmd, c"status", 6) || cmd_is(cmd, c"stat", 4) {+    if cmd_is(cmd, c"stat", 4) || cmd_is(cmd, c"status", 6) {         return run_status()+    }+    if cmd_is(cmd, c"inf", 3) {+        return run_inf()     }     if cmd_is(cmd, c"log", 3) {         return run_log(args, 2)@@ -444,10 +462,10 @@     if cmd_is(cmd, c"new", 3) {         return run_new(args, 2)     }-    if cmd_is(cmd, c"describe", 8) {+    if cmd_is(cmd, c"desc", 4) || cmd_is(cmd, c"describe", 8) {         return run_describe(args, 2)     }-    if cmd_is(cmd, c"commit", 6) {+    if cmd_is(cmd, c"go", 2) || cmd_is(cmd, c"commit", 6) {         return run_commit(args, 2)     }     if cmd_is(cmd, c"undo", 4) {