navid/veins / commit

fde8e8d3b6db

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

parents: d4cdcb663b3b

Browse files at this commit · Download source

all: materialize subcommand
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -726,6 +726,8 @@ Reading a lazy blob reads the corresponding git object from the mirror. `vn checkout` uses this path, so an imported repository checks out to the same bytes as git. `vn fsck` treats lazy blob references as promised objects; they are not errors merely because they are absent from `.veins/store`.  Lazy IDs are deterministic for a given git blob. The `blobs` mapping table records them so that a later materialization pass can replace lazy references with canonical chunked veins blobs. Materialization is a separate operation and will rewrite the affected tree, commit, and view IDs. Deleting `.veins/git` while lazy references remain makes those blobs unavailable.++`vn git materialize [path]` performs this pass. It reads every lazy blob reachable from the current view, chunks and stores it canonically, rewrites affected trees and conflict values, rewrites commits parents-first while preserving change IDs and metadata, updates view refs, and records one operation. Objects with no lazy descendants keep their existing IDs. The `commits`, `trees`, and `blobs` mapping tables are updated to the new veins IDs. If no lazy references remain, the command reports `already materialized` and creates no operation.  Lazy import is an importer fast path. Repositories created by a native veins clone use canonical chunked blobs and do not depend on a git mirror. @@ -1093,7 +1095,7 @@ | `vn undo`, `vn op log`, `vn op restore <op>`, `vn op revert <op>` | Operation log commands. | `vn bookmark set\|list\|delete`, `vn tag set\|ls\|rm\|latest` | Manage named pointers. | `vn fetch`, `vn push` | Native protocol.-| `vn git import [-source:<gitdir>] [path]`, `vn git export`, `vn git fetch`, `vn git push`, `vn git remote` | Git bridge.+| `vn git import [-source:<gitdir>] [path]`, `vn git export`, `vn git materialize [path]`, `vn git fetch`, `vn git push`, `vn git remote` | Git bridge. | `vn serve -stdio <repo>`, `vn serve -listen <addr:port> -root <dir> ...` | Run the native server over stdio or TLS. | `vn key generate\|list\|show\|import` | Manage client keys. | `vn access add\|list\|remove\|anonymous` | Manage a served repository's access file (server side, local only).--- a/docs/SPECIFICATION_V1.html+++ b/docs/SPECIFICATION_V1.html@@ -2233,6 +2233,9 @@ <p>Lazy IDs are deterministic for a given git blob. The <code>blobs</code> mapping table records them so that a later materialization pass can replace lazy references with canonical chunked veins blobs. Materialization is a separate operation and will rewrite the affected tree, commit, and view IDs. Deleting <code>.veins/git</code> while lazy references remain makes those blobs unavailable.</p> </div> <div class="paragraph">+<p><code>vn git materialize [path]</code> performs this pass. It reads every lazy blob reachable from the current view, chunks and stores it canonically, rewrites affected trees and conflict values, rewrites commits parents-first while preserving change IDs and metadata, updates view refs, and records one operation. Objects with no lazy descendants keep their existing IDs. The <code>commits</code>, <code>trees</code>, and <code>blobs</code> mapping tables are updated to the new veins IDs. If no lazy references remain, the command reports <code>already materialized</code> and creates no operation.</p>+</div>+<div class="paragraph"> <p>Lazy import is an importer fast path. Repositories created by a native veins clone use canonical chunked blobs and do not depend on a git mirror.</p> </div> </div>@@ -3111,7 +3114,7 @@ <td class="tableblock halign-left valign-top"><p class="tableblock">Native protocol.</p></td> </tr> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn git import [-source:&lt;gitdir&gt;] [path]</code>, <code>vn git export</code>, <code>vn git fetch</code>, <code>vn git push</code>, <code>vn git remote</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn git import [-source:&lt;gitdir&gt;] [path]</code>, <code>vn git export</code>, <code>vn git materialize [path]</code>, <code>vn git fetch</code>, <code>vn git push</code>, <code>vn git remote</code></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Git bridge.</p></td> </tr> <tr>--- a/veins/src/cli/git_cmd.sx+++ b/veins/src/cli/git_cmd.sx@@ -8,6 +8,7 @@ val mirror = use("../git/mirror.sx") val import = use("../git/import.sx") val export = use("../git/export.sx")+val materialize = use("../git/materialize.sx") val remote = use("../git/remote.sx") val config = use("../core/repoconfig.sx") @@ -20,7 +21,10 @@         }         none => {             msg.error_prefix()-            stdio.eprint("expected a git subcommand (import)\n", {})+            stdio.eprint(+                "expected a git subcommand (import, export, materialize, fetch, push, remote)\n",+                {}+            )             return 1         }     }@@ -29,6 +33,9 @@     }     if @strcmp(sub, c"export") == 0 {         return run_export(args, start + 1)+    }+    if @strcmp(sub, c"materialize") == 0 {+        return run_materialize(args, start + 1)     }     if @strcmp(sub, c"fetch") == 0 {         return run_fetch(args, start + 1)@@ -136,6 +143,39 @@         }     }     val status: i32 = export.run(repo)+    layout.free_repo(repo)+    return status+}++fn run_materialize(args: list[ref u8], start: usize) i32 = trust {+    val repo_path: mut str.StringView = str.from_cstr(c".")+    val i: mut usize = start+    for i < @len(args) {+        val arg_opt = @get(args, i)+        if arg_opt is some a {+            val av: bytes.Bytes = bytes.from_cstr(a)+            if av.len > 0 && bytes.Bytes.at(av, 0) == 45 {+                msg.error_prefix()+                stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})+                return 1+            }+            repo_path = str.from_cstr(a)+        }+        i+++    }+    val repo_opt = layout.discover(repo_path)+    val repo: mut layout.Repo = layout.Repo{root: @zeroed}+    match repo_opt {+        some r => {+            repo = r+        }+        none => {+            msg.error_prefix()+            stdio.eprint("not a veins repository: {s}\n", {repo_path})+            return 1+        }+    }+    val status: i32 = materialize.run(repo)     layout.free_repo(repo)     return status }--- a/veins/src/cli/help_cmd.sx+++ b/veins/src/cli/help_cmd.sx@@ -94,6 +94,7 @@     stdio.puts("  import [-source:<gitdir>] [path]")     stdio.puts("                            import reachable git commits and refs")     stdio.puts("  export [path]             export commits into the git mirror")+    stdio.puts("  materialize [path]        replace lazy git blobs with stored blobs")     stdio.puts("  fetch [<remote>] [path]   git fetch into the mirror, then import")     stdio.puts("  push [<remote>] <bookmark> [path]")     stdio.puts("                            export and git push a bookmark")@@ -375,6 +376,14 @@     stdio.puts("usage: vn git export [path]")     stdio.puts("")     stdio.puts("export commits reachable from bookmarks and tags into .veins/git")+}++fn show_git_materialize() void = trust {+    stdio.puts("usage: vn git materialize [path]")+    stdio.puts("")+    stdio.puts("replace lazy git-backed blobs with canonical stored blobs")+    stdio.puts("")+    stdio.puts("rewrites affected trees, commits, and refs and records one operation") }  fn show_help() void = trust {@@ -601,6 +610,10 @@                 }                 if cmd_is(sub, c"export", 6) {                     show_git_export()+                    return 0+                }+                if cmd_is(sub, c"materialize", 11) {+                    show_git_materialize()                     return 0                 }                 if cmd_is(sub, c"fetch", 5) {--- /dev/null+++ b/veins/src/git/materialize.sx@@ -0,0 +1,812 @@+/// Replace lazy git-backed blobs with canonical chunked veins blobs.+///+/// Materialization rewrites the trees, conflict objects, commits, and view+/// reachable from the current view. Objects without lazy descendants keep+/// their existing IDs.++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 types    = use("../object/types.sx")+val raw      = use("../object/raw.sx")+val blob     = use("../object/blob.sx")+val tree     = use("../object/tree.sx")+val commit   = use("../object/commit.sx")+val conflict = use("../object/conflict.sx")+val view     = use("../object/view.sx")+val graph    = use("../object/graph.sx")+val content  = use("../object/content.sx")+val store    = use("../store/store.sx")+val state    = use("../store/state.sx")+val txn      = use("../store/txn.sx")+val layout   = use("../store/layout.sx")+val idmap    = use("../store/idmap.sx")+val files    = use("../io/files.sx")+val object   = use("object.sx")+val lazy     = use("lazy.sx")+val gitmap   = use("map.sx")+val oidmap   = use("oidmap.sx")+val refmap   = use("refmap.sx")+val checkout = use("../worktree/checkout.sx")++type RawSave = {+    id: mut objid.Id+    body: mut bytes.Bytes+}++type MatCtx = {+    repo: layout.Repo+    tx: mut ref txn.Txn+    handles: list[ref store.Handle]+    git: mut object.GitRepo+    has_git: mut bool+    trees: mut refmap.RefMap+    blobs: mut refmap.RefMap+    commits: mut refmap.RefMap+    conflicts: mut refmap.RefMap+    raw_saves: mut list[ref RawSave]+    new_commits: mut usize+    new_trees: mut usize+    new_blobs: mut usize+    changed: mut bool+}++type Mark = {+    id: mut objid.Id+    expanded: mut bool+}++fn copy_id(id: objid.Id) objid.Id = trust {+    val out: ref u8 = @alloc(32) as ref u8+    @memcpy(out as ref void, id.ptr as ref void, 32)+    return objid.id(out)+}++fn free_id(id: objid.Id) void = trust {+    if id.ptr != none {+        val p: mut ref void = id.ptr as ref void+        @free(p)+    }+}++fn free_ids(ids: list[objid.Id]) void = trust {+    for id in ids {+        free_id(id)+    }+    @listfree(ids)+}++fn map_get(map: refmap.RefMap, id: objid.Id) option[objid.Id] = trust {+    val got = refmap.get(map, bytes.bytes(id.ptr, 32))+    match got {+        some v => {+            // Copy the value: growing the map later must not invalidate IDs+            // already handed to tree entries, commits, or the view.+            val out: ref u8 = @alloc(32) as ref u8+            @memcpy(out as ref void, v.ptr as ref void, 32)+            return some objid.id(out)+        }+        none => {+            return none+        }+    }+}++fn map_put(map: mut refmap.RefMap, old_id: objid.Id, new_id: objid.Id) void = trust {+    refmap.put(map, bytes.bytes(old_id.ptr, 32), bytes.bytes(new_id.ptr, 32))+}++fn mapped_commit(ctx: MatCtx, id: objid.Id) objid.Id = trust {+    val got = map_get(ctx.commits, id)+    if got is some mapped {+        return mapped+    }+    return id+}++fn record_raw(ctx: mut MatCtx, old_id: objid.Id, new_id: objid.Id) void = trust {+    val raw_opt = gitmap.load_raw(ctx.repo, old_id)+    match raw_opt {+        some body => {+            val rs: mut ref RawSave = @alloc(@sizeof(RawSave)) as ref RawSave+            rs.id = copy_id(new_id)+            rs.body = body+            @append(ctx.raw_saves, rs)+        }+        none => {+        }+    }+}++fn free_raw_saves(xs: list[ref RawSave]) void = trust {+    for rs in xs {+        if rs.body.ptr != none {+            val bp: mut ref void = rs.body.ptr as ref void+            @free(bp)+        }+        if rs.id.ptr != none {+            val ip: mut ref void = rs.id.ptr as ref void+            @free(ip)+        }+        val rp: mut ref void = rs as ref void+        @free(rp)+    }+    @listfree(xs)+}++fn ordered_commits(+    handles: list[ref store.Handle],+    roots: list[objid.Id]+) list[objid.Id] = trust {+    val stack: mut list[ref Mark] = lists.new[ref Mark]()+    for r in roots {+        val m: mut ref Mark = @alloc(@sizeof(Mark)) as ref Mark+        m.id = copy_id(r)+        m.expanded = false+        @append(stack, m)+    }+    val visited: mut idmap.IdSet = idmap.new(64)+    val out: mut list[objid.Id] = lists.new[objid.Id]()+    for @len(stack) > 0 {+        val m: mut ref Mark = @remove(stack, @len(stack) - 1)+        if idmap.contains(visited, bytes.bytes(m.id.ptr, 32)) {+            free_id(m.id)+            @free(m as ref void)+            continue+        }+        if !m.expanded {+            m.expanded = true+            @append(stack, m)+            val lc_opt = graph.load_commit(handles, m.id)+            if lc_opt is some lc {+                for p in lc.c.parents {+                    if !idmap.contains(visited, bytes.bytes(p.ptr, 32)) {+                        val pm: mut ref Mark = @alloc(@sizeof(Mark)) as ref Mark+                        pm.id = copy_id(p)+                        pm.expanded = false+                        @append(stack, pm)+                    }+                }+                graph.free_loaded(lc)+            }+        } else {+            val _ = idmap.put(visited, bytes.bytes(m.id.ptr, 32))+            @append(out, copy_id(m.id))+            free_id(m.id)+            @free(m as ref void)+        }+    }+    idmap.free(visited)+    @listfree(stack)+    return out+}++fn materialize_blob(ctx: mut MatCtx, old_id: objid.Id) objid.Id = trust {+    val existing = map_get(ctx.blobs, old_id)+    if existing is some id {+        return id+    }+    if !lazy.is_lazy(old_id) {+        map_put(ctx.blobs, old_id, old_id)+        return old_id+    }+    val data_opt = content.read_blob(ctx.handles, old_id, ctx.git, ctx.has_git)+    val data: mut bytes.Bytes = bytes.empty()+    match data_opt {+        some d => {+            data = d+        }+        none => {+            return objid.id_none()+        }+    }+    val built: ref blob.BlobBuild = blob.build(data.ptr, data.len)+    val root: objid.Id = copy_id(blob.root_id(built))+    val i: mut usize = 0+    for i < @len(built.objects) {+        val o = @get(built.objects, i)+        if o is some obj {+            val orf: mut ref raw.RawObject = obj+            val oid: objid.Id = objid.id(orf.id)+            val _ = txn.add_known(ctx.tx, orf.type_byte, oid, orf.body)+            orf.body = bytes.empty()+        }+        i+++    }+    blob.free_build(built)+    files.free_buffer(data)+    map_put(ctx.blobs, old_id, root)+    ctx.new_blobs+++    ctx.changed = true+    return root+}++/// Materialize one object. Kind 0 is a blob, 1 a tree, and 2 a conflict.+fn materialize_node(+    ctx: mut MatCtx,+    old_id: objid.Id,+    kind: u8,+    depth: usize+) objid.Id = trust {+    if depth > 4096 {+        return objid.id_none()+    }+    if kind == 0 {+        return materialize_blob(ctx, old_id)+    }+    if kind == 1 {+        val existing = map_get(ctx.trees, old_id)+        if existing is some id {+            return id+        }+        val body_opt = state.read_body(ctx.handles, old_id, types.TREE)+        val body: mut bytes.Bytes = bytes.empty()+        match body_opt {+            some b => {+                body = b+            }+            none => {+                return objid.id_none()+            }+        }+        val decoded = tree.decode(body)+        val t: mut ref tree.Tree = @zeroed+        match decoded {+            ok v => {+                t = v+            }+            err _ => {+                files.free_buffer(body)+                return objid.id_none()+            }+        }+        val changed: mut bool = false+        val ei: mut usize = 0+        for ei < @len(t.entries) {+            val eo = @get(t.entries, ei)+            if eo is some e {+                if e.kind == tree.KIND_FILE || e.kind == tree.KIND_EXECUTABLE+                || e.kind == tree.KIND_SYMLINK {+                    if lazy.is_lazy(e.target) {+                        val mapped: objid.Id = materialize_node(+                            ctx,+                            e.target,+                            0,+                            depth + 1+                        )+                        if objid.Id.is_none(mapped) {+                            tree.free_tree(t)+                            files.free_buffer(body)+                            return objid.id_none()+                        }+                        if !objid.Id.eql(mapped, e.target) {+                            e.target = mapped+                            changed = true+                        }+                    }+                } elif e.kind == tree.KIND_SUBTREE {+                    val mapped: objid.Id = materialize_node(+                        ctx,+                        e.target,+                        1,+                        depth + 1+                    )+                    if objid.Id.is_none(mapped) {+                        tree.free_tree(t)+                        files.free_buffer(body)+                        return objid.id_none()+                    }+                    if !objid.Id.eql(mapped, e.target) {+                        e.target = mapped+                        changed = true+                    }+                } elif e.kind == tree.KIND_CONFLICT {+                    val mapped: objid.Id = materialize_node(+                        ctx,+                        e.target,+                        2,+                        depth + 1+                    )+                    if objid.Id.is_none(mapped) {+                        tree.free_tree(t)+                        files.free_buffer(body)+                        return objid.id_none()+                    }+                    if !objid.Id.eql(mapped, e.target) {+                        e.target = mapped+                        changed = true+                    }+                } elif e.kind == tree.KIND_SUBMODULE {+                } else {+                    tree.free_tree(t)+                    files.free_buffer(body)+                    return objid.id_none()+                }+            }+            ei+++        }+        val result: mut objid.Id = objid.id_none()+        if changed {+            val encoded = tree.encode(t.entries)+            match encoded {+                ok new_body => {+                    result = txn.add_object(ctx.tx, types.TREE, new_body)+                    map_put(ctx.trees, old_id, result)+                    ctx.new_trees+++                    ctx.changed = true+                    record_raw(ctx, old_id, result)+                }+                err _ => {+                    tree.free_tree(t)+                    files.free_buffer(body)+                    return objid.id_none()+                }+            }+        } else {+            result = old_id+            map_put(ctx.trees, old_id, old_id)+        }+        tree.free_tree(t)+        files.free_buffer(body)+        return result+    }+    if kind == 2 {+        val existing = map_get(ctx.conflicts, old_id)+        if existing is some id {+            return id+        }+        val body_opt = state.read_body(ctx.handles, old_id, types.CONFLICT)+        val body: mut bytes.Bytes = bytes.empty()+        match body_opt {+            some b => {+                body = b+            }+            none => {+                return objid.id_none()+            }+        }+        val decoded = conflict.decode(body)+        val c: mut ref conflict.Conflict = @zeroed+        match decoded {+            ok v => {+                c = v+            }+            err _ => {+                files.free_buffer(body)+                return objid.id_none()+            }+        }+        val changed: mut bool = false+        val vi: mut usize = 0+        for vi < @len(c.adds) {+            val vo = @get(c.adds, vi)+            if vo is some v {+                if !objid.Id.is_none(v.target) {+                    val target_kind: mut u8 = 0+                    val skip: mut bool = false+                    if v.kind == tree.KIND_SUBTREE {+                        target_kind = 1+                    } elif v.kind == tree.KIND_CONFLICT {+                        target_kind = 2+                    } elif v.kind == tree.KIND_SUBMODULE {+                        skip = true+                    }+                    if !skip {+                        val before: objid.Id = v.target+                        val mapped: objid.Id = materialize_node(+                            ctx,+                            v.target,+                            target_kind,+                            depth + 1+                        )+                        if objid.Id.is_none(mapped) {+                            conflict.free_conflict(c)+                            files.free_buffer(body)+                            return objid.id_none()+                        }+                        if !objid.Id.eql(before, mapped) {+                            v.target = mapped+                            changed = true+                        }+                    }+                }+            }+            vi+++        }+        val ri: mut usize = 0+        for ri < @len(c.removes) {+            val ro = @get(c.removes, ri)+            if ro is some v {+                if !objid.Id.is_none(v.target) {+                    val target_kind: mut u8 = 0+                    val skip: mut bool = false+                    if v.kind == tree.KIND_SUBTREE {+                        target_kind = 1+                    } elif v.kind == tree.KIND_CONFLICT {+                        target_kind = 2+                    } elif v.kind == tree.KIND_SUBMODULE {+                        skip = true+                    }+                    if !skip {+                        val before: objid.Id = v.target+                        val mapped: objid.Id = materialize_node(+                            ctx,+                            v.target,+                            target_kind,+                            depth + 1+                        )+                        if objid.Id.is_none(mapped) {+                            conflict.free_conflict(c)+                            files.free_buffer(body)+                            return objid.id_none()+                        }+                        if !objid.Id.eql(before, mapped) {+                            v.target = mapped+                            changed = true+                        }+                    }+                }+            }+            ri+++        }+        val result: mut objid.Id = objid.id_none()+        if changed {+            val encoded: bytes.Bytes = conflict.encode(c.adds, c.removes)+            result = txn.add_object(ctx.tx, types.CONFLICT, encoded)+            map_put(ctx.conflicts, old_id, result)+            ctx.changed = true+        } else {+            result = old_id+            map_put(ctx.conflicts, old_id, old_id)+        }+        conflict.free_conflict(c)+        files.free_buffer(body)+        return result+    }+    return objid.id_none()+}++fn remap_table(old_map: oidmap.OidMap, mappings: refmap.RefMap) oidmap.OidMap = trust {+    val out: mut oidmap.OidMap = oidmap.new(old_map.len + 16)+    val i: mut usize = 0+    for i < old_map.cap {+        if oidmap.slot_used(old_map, i) {+            val key: bytes.Bytes = oidmap.slot_oid(old_map, i)+            val value: bytes.Bytes = oidmap.slot_value(old_map, i)+            val mapped = refmap.get(mappings, value)+            if mapped is some new_value {+                oidmap.put(out, key, new_value)+            } else {+                oidmap.put(out, key, value)+            }+        }+        i+++    }+    return out+}++fn free_maps(ctx: mut MatCtx) void = trust {+    refmap.free(ctx.trees)+    refmap.free(ctx.blobs)+    refmap.free(ctx.commits)+    refmap.free(ctx.conflicts)+}++pub fn run(repo: layout.Repo) i32 = trust {+    val git_path = layout.git_dir(repo)+    val git_opt = object.open(git_path)+    val git_repo: mut object.GitRepo = @zeroed+    val has_git: mut bool = false+    match git_opt {+        ok g => {+            git_repo = g+            has_git = true+        }+        err _ => {+            files.free_path(git_path)+        }+    }++    val commits_map_opt = gitmap.load_map(repo, str.from_cstr(c"commits"))+    val trees_map_opt = gitmap.load_map(repo, str.from_cstr(c"trees"))+    val blobs_map_opt = gitmap.load_map(repo, str.from_cstr(c"blobs"))+    val commits_map: mut oidmap.OidMap = oidmap.new(64)+    val trees_map: mut oidmap.OidMap = oidmap.new(64)+    val blobs_map: mut oidmap.OidMap = oidmap.new(64)+    val maps_ok: mut bool = true+    match commits_map_opt {+        ok m => {+            oidmap.free(commits_map)+            commits_map = m+        }+        err _ => {+            maps_ok = false+        }+    }+    match trees_map_opt {+        ok m => {+            oidmap.free(trees_map)+            trees_map = m+        }+        err _ => {+            maps_ok = false+        }+    }+    match blobs_map_opt {+        ok m => {+            oidmap.free(blobs_map)+            blobs_map = m+        }+        err _ => {+            maps_ok = false+        }+    }+    if !maps_ok {+        msg.error_prefix()+        stdio.eprint("corrupt git mapping table\n", {})+        oidmap.free(commits_map)+        oidmap.free(trees_map)+        oidmap.free(blobs_map)+        if has_git {+            object.free(git_repo)+        }+        return 1+    }++    val tx_opt = txn.begin(repo)+    val tx: mut ref txn.Txn = none+    match tx_opt {+        some t => {+            tx = t+        }+        none => {+            msg.error_prefix()+            stdio.eprint("cannot load repository state\n", {})+            oidmap.free(commits_map)+            oidmap.free(trees_map)+            oidmap.free(blobs_map)+            if has_git {+                object.free(git_repo)+            }+            return 1+        }+    }+    val handles: list[ref store.Handle] = txn.handles(tx)+    val ctx: mut MatCtx = MatCtx{+        repo: repo,+        tx: tx,+        handles: handles,+        git: git_repo,+        has_git: has_git,+        trees: refmap.new(64),+        blobs: refmap.new(64),+        commits: refmap.new(64),+        conflicts: refmap.new(64),+        raw_saves: lists.new[ref RawSave](),+        new_commits: 0,+        new_trees: 0,+        new_blobs: 0,+        changed: false+    }++    val roots: list[objid.Id] = graph.roots(tx.view)+    val ordered: list[objid.Id] = ordered_commits(handles, roots)+    free_ids(roots)++    val failed: mut bool = false+    for old_id in ordered {+        val body_opt = state.read_body(handles, old_id, types.COMMIT)+        val body: mut bytes.Bytes = bytes.empty()+        match body_opt {+            some b => {+                body = b+            }+            none => {+                failed = true+            }+        }+        if failed {+            break+        }+        val decoded = commit.decode(body)+        val c: mut ref commit.Commit = @zeroed+        match decoded {+            ok v => {+                c = v+            }+            err _ => {+                failed = true+            }+        }+        if failed {+            files.free_buffer(body)+            break+        }+        val new_root: objid.Id = materialize_node(ctx, c.root_tree, 1, 0)+        if objid.Id.is_none(new_root) {+            failed = true+            commit.free_commit(c)+            files.free_buffer(body)+            break+        }+        val new_parents: mut list[objid.Id] = lists.new[objid.Id]()+        val changed: mut bool = !objid.Id.eql(new_root, c.root_tree)+        for p in c.parents {+            val mapped = map_get(ctx.commits, p)+            if mapped is some m {+                @append(new_parents, m)+                if !objid.Id.eql(m, p) {+                    changed = true+                }+            } else {+                failed = true+                break+            }+        }+        if failed {+            @listfree(new_parents)+            commit.free_commit(c)+            files.free_buffer(body)+            break+        }+        if !changed {+            map_put(ctx.commits, old_id, old_id)+            @listfree(new_parents)+            commit.free_commit(c)+            files.free_buffer(body)+            continue+        }+        @listfree(c.parents)+        c.parents = new_parents+        c.root_tree = new_root+        val new_body: bytes.Bytes = commit.encode(c)+        val new_id: objid.Id = txn.add_object(tx, types.COMMIT, new_body)+        map_put(ctx.commits, old_id, new_id)+        ctx.new_commits+++        ctx.changed = true+        record_raw(ctx, old_id, new_id)+        commit.free_commit(c)+        files.free_buffer(body)+    }++    if failed {+        msg.error_prefix()+        stdio.eprint("git materialize failed (missing or corrupt object)\n", {})+        free_ids(ordered)+        free_raw_saves(ctx.raw_saves)+        free_maps(ctx)+        txn.abort(tx)+        oidmap.free(commits_map)+        oidmap.free(trees_map)+        oidmap.free(blobs_map)+        if has_git {+            object.free(git_repo)+        }+        return 1+    }++    if !ctx.changed {+        msg.info_prefix()+        stdio.print("already materialized\n", {})+        free_ids(ordered)+        free_raw_saves(ctx.raw_saves)+        free_maps(ctx)+        txn.abort(tx)+        oidmap.free(commits_map)+        oidmap.free(trees_map)+        oidmap.free(blobs_map)+        if has_git {+            object.free(git_repo)+        }+        return 0+    }++    val v: mut ref view.View = tx.view+    val new_heads: mut list[objid.Id] = lists.new[objid.Id]()+    for h in v.heads {+        @append(new_heads, mapped_commit(ctx, h))+    }+    @listfree(v.heads)+    v.heads = new_heads+    val bi: mut usize = 0+    for bi < @len(v.bookmarks) {+        val bo = @get(v.bookmarks, bi)+        if bo is some bm {+            val i: mut usize = 0+            for i < @len(bm.targets.adds) {+                val o = @get(bm.targets.adds, i)+                if o is some id {+                    @set(bm.targets.adds, i, mapped_commit(ctx, id))+                }+                i+++            }+            val j: mut usize = 0+            for j < @len(bm.targets.removes) {+                val o = @get(bm.targets.removes, j)+                if o is some id {+                    @set(bm.targets.removes, j, mapped_commit(ctx, id))+                }+                j+++            }+        }+        bi+++    }+    val ti: mut usize = 0+    for ti < @len(v.tags) {+        val to = @get(v.tags, ti)+        if to is some t {+            t.target = mapped_commit(ctx, t.target)+        }+        ti+++    }+    val ri: mut usize = 0+    for ri < @len(v.remote_refs) {+        val ro = @get(v.remote_refs, ri)+        if ro is some rr {+            rr.target = mapped_commit(ctx, rr.target)+        }+        ri+++    }+    val wi: mut usize = 0+    for wi < @len(v.working_copies) {+        val wo = @get(v.working_copies, wi)+        if wo is some w {+            w.target = mapped_commit(ctx, w.target)+        }+        wi+++    }++    val status: i32 = txn.finish(tx, bytes.bytes(c"git materialize", 15))+    if status != 0 {+        free_ids(ordered)+        free_raw_saves(ctx.raw_saves)+        free_maps(ctx)+        oidmap.free(commits_map)+        oidmap.free(trees_map)+        oidmap.free(blobs_map)+        if has_git {+            object.free(git_repo)+        }+        return status+    }++    for rs in ctx.raw_saves {+        val _ = gitmap.save_raw(repo, rs.id, rs.body)+    }+    free_raw_saves(ctx.raw_saves)++    val new_commits_map: oidmap.OidMap = remap_table(commits_map, ctx.commits)+    oidmap.free(commits_map)+    commits_map = new_commits_map+    val new_trees_map: oidmap.OidMap = remap_table(trees_map, ctx.trees)+    oidmap.free(trees_map)+    trees_map = new_trees_map+    val new_blobs_map: oidmap.OidMap = remap_table(blobs_map, ctx.blobs)+    oidmap.free(blobs_map)+    blobs_map = new_blobs_map+    if !gitmap.save_map(repo, str.from_cstr(c"commits"), commits_map)+    || !gitmap.save_map(repo, str.from_cstr(c"trees"), trees_map)+    || !gitmap.save_map(repo, str.from_cstr(c"blobs"), blobs_map) {+        msg.error_prefix()+        stdio.eprint("failed to write git mapping tables\n", {})+    }+    checkout.clear_stat_cache(repo)+    msg.info_prefix()+    stdio.print(+        "materialized {d} commits, {d} trees, {d} blobs\n",+        {ctx.new_commits, ctx.new_trees, ctx.new_blobs}+    )++    free_ids(ordered)+    free_maps(ctx)+    oidmap.free(commits_map)+    oidmap.free(trees_map)+    oidmap.free(blobs_map)+    if has_git {+        object.free(git_repo)+    }+    return 0+}--- /dev/null+++ b/veins/src/git/refmap.sx@@ -0,0 +1,165 @@+/// Open-addressed map from 32-byte veins object IDs to 32-byte veins IDs.+///+/// Used while rewriting lazy git-backed objects into canonical stored objects.++val bytes = use("../core/bytes.sx")++pub val ID_LEN: usize = 32+pub val SLOT_LEN: usize = 65++pub type RefMap = {+    slots: mut ref u8+    cap: mut usize+    len: mut usize+}++fn round_cap(n: usize) usize = {+    val c: mut usize = 16+    for c < n {+        c = c * 2+    }+    return c+}++fn hash_id(id: bytes.Bytes) u64 = {+    val h: mut u64 = 1469598103934665603+    val i: mut usize = 0+    for i < ID_LEN {+        h = (h ^ (bytes.Bytes.at(id, i) as u64)) * 1099511628211+        i+++    }+    return h+}++fn key_ptr(map: RefMap, i: usize) ref u8 = trust {+    return @ptradd(map.slots, (i * SLOT_LEN + 1) as i64)+}++fn value_ptr(map: RefMap, i: usize) ref u8 = trust {+    return @ptradd(map.slots, (i * SLOT_LEN + 1 + ID_LEN) as i64)+}++fn used_at(map: RefMap, i: usize) bool = trust {+    return @load8(@ptradd(map.slots, (i * SLOT_LEN) as i64)) != 0+}++fn set_used(map: RefMap, i: usize) void = trust {+    @store8(@ptradd(map.slots, (i * SLOT_LEN) as i64), 1)+}++fn slot_eql(map: RefMap, i: usize, key: bytes.Bytes) bool = trust {+    return bytes.Bytes.eql(bytes.bytes(key_ptr(map, i), ID_LEN), key)+}++fn copy_key(map: RefMap, i: usize, key: bytes.Bytes) void = trust {+    @memcpy(key_ptr(map, i) as ref void, key.ptr as ref void, ID_LEN)+}++fn copy_value(map: RefMap, i: usize, value: bytes.Bytes) void = trust {+    @memcpy(value_ptr(map, i) as ref void, value.ptr as ref void, ID_LEN)+}++pub fn new(initial: usize) RefMap = trust {+    val cap: usize = round_cap(initial)+    val p: ref u8 = @alloc(cap * SLOT_LEN) as ref u8+    @memset(p as ref void, 0, cap * SLOT_LEN)+    return RefMap{slots: p, cap: cap, len: 0}+}++pub fn free(map: mut RefMap) void = trust {+    if map.slots != none {+        @free(map.slots as ref void)+    }+    map.slots = none+    map.cap = 0+    map.len = 0+}++fn insert_existing(+    map: mut RefMap,+    key: bytes.Bytes,+    value: bytes.Bytes+) void = trust {+    val mask: usize = map.cap - 1+    val start: usize = (hash_id(key) as usize) & mask+    val idx: mut usize = start+    for {+        if !used_at(map, idx) {+            set_used(map, idx)+            copy_key(map, idx, key)+            copy_value(map, idx, value)+            map.len+++            return+        }+        if slot_eql(map, idx, key) {+            copy_value(map, idx, value)+            return+        }+        idx = (idx + 1) & mask+    }+}++fn grow(map: mut RefMap) void = trust {+    val old_slots: mut ref u8 = map.slots+    val old_cap: usize = map.cap+    val new_cap: usize = old_cap * 2+    val p: ref u8 = @alloc(new_cap * SLOT_LEN) as ref u8+    @memset(p as ref void, 0, new_cap * SLOT_LEN)+    map.slots = p+    map.cap = new_cap+    map.len = 0+    val i: mut usize = 0+    for i < old_cap {+        if @load8(@ptradd(old_slots, (i * SLOT_LEN) as i64)) != 0 {+            val key: bytes.Bytes = bytes.bytes(+                @ptradd(old_slots, (i * SLOT_LEN + 1) as i64),+                ID_LEN+            )+            val value: bytes.Bytes = bytes.bytes(+                @ptradd(old_slots, (i * SLOT_LEN + 1 + ID_LEN) as i64),+                ID_LEN+            )+            insert_existing(map, key, value)+        }+        i+++    }+    @free(old_slots as ref void)+}++/// Insert or replace `key` with `value`.+pub fn put(map: mut RefMap, key: bytes.Bytes, value: bytes.Bytes) void = trust {+    pre {+        key_len: key.len == ID_LEN+        value_len: value.len == ID_LEN+    }+    if (map.len + 1) * 10 >= map.cap * 7 {+        grow(map)+    }+    insert_existing(map, key, value)+}++/// The stored value for `key`, borrowed from the map.+pub fn get(map: RefMap, key: bytes.Bytes) option[bytes.Bytes] = trust {+    pre {+        key_len: key.len == ID_LEN+    }+    if map.cap == 0 {+        return none+    }+    val mask: usize = map.cap - 1+    val start: usize = (hash_id(key) as usize) & mask+    val idx: mut usize = start+    for {+        if !used_at(map, idx) {+            return none+        }+        if slot_eql(map, idx, key) {+            return some bytes.bytes(value_ptr(map, idx), ID_LEN)+        }+        idx = (idx + 1) & mask+        if idx == start {+            return none+        }+    }+    return none+}--- a/xveins/src/cli.cpp+++ b/xveins/src/cli.cpp@@ -2177,6 +2177,7 @@   std::cout << "  import [-source:<gitdir>] [path]\n";   std::cout << "                            import reachable git commits and refs\n";   std::cout << "  export [path]             export commits into the git mirror\n";+  std::cout << "  materialize [path]        replace lazy git blobs with stored blobs\n";   std::cout << "  fetch [<remote>] [path]   git fetch into the mirror, then import\n";   std::cout << "  push [<remote>] <bookmark> [path]\n";   std::cout << "                            export and git push a bookmark\n";@@ -2200,6 +2201,13 @@   std::cout << "export commits reachable from bookmarks and tags into .veins/git\n"; } +void show_git_materialize() {+  std::cout << "usage: vn git materialize [path]\n\n";+  std::cout << "replace lazy git-backed blobs with canonical stored blobs.\n";+  std::cout << "rewrites affected trees, commits, and refs and records one "+               "operation\n";+}+ void show_unimplemented(std::string_view command) {   std::cout << "usage: vn " << command << "\n\n";   std::cout << "this command is planned for a later stage of the C++ rewrite\n";@@ -2276,6 +2284,8 @@         show_git_import();       else if (sub == "export")         show_git_export();+      else if (sub == "materialize")+        show_git_materialize();       else if (sub == "fetch")         std::cout << "usage: vn git fetch [<remote>] [path]\n";       else if (sub == "push")--- a/xveins/src/git.cpp+++ b/xveins/src/git.cpp@@ -227,6 +227,182 @@     current = loaded->commit.parents.front();   }   return std::nullopt;+}++struct MaterializeCtx {+  const fs::path &root;+  Store &store;+  Writer &writer;+  std::map<Id, Id> trees;+  std::map<Id, Id> blobs;+  std::map<Id, Id> commits;+  std::map<Id, Id> conflicts;+  std::vector<std::pair<Id, std::vector<std::uint8_t>>> raw_saves;+  std::size_t new_commits = 0;+  std::size_t new_trees = 0;+  std::size_t new_blobs = 0;+  bool changed = false;+};++std::optional<Id> materialize_blob(MaterializeCtx &ctx, const Id &old_id) {+  auto existing = ctx.blobs.find(old_id);+  if (existing != ctx.blobs.end())+    return existing->second;+  const auto oid = git::lazy_blob_oid(old_id);+  if (!oid) {+    ctx.blobs[old_id] = old_id;+    return old_id;+  }+  auto data = git_read_lazy_blob(ctx.root, old_id);+  if (!data)+    return std::nullopt;+  BlobBuild build = build_blob(bytes_of(*data));+  if (build.root == Id{})+    return std::nullopt;+  for (auto &object : build.objects) {+    const Id id = object.id ? *object.id+                            : object_id(object.type, bytes_of(object.body));+    (void)ctx.writer.add_known(object.type, id, std::move(object.body));+  }+  ctx.blobs[old_id] = build.root;+  ++ctx.new_blobs;+  ctx.changed = true;+  return build.root;+}++std::optional<Id> materialize_tree(MaterializeCtx &ctx, const Id &old_id,+                                   std::size_t depth);++std::optional<Id> materialize_conflict(MaterializeCtx &ctx, const Id &old_id,+                                       std::size_t depth) {+  if (depth > 4096)+    return std::nullopt;+  auto existing = ctx.conflicts.find(old_id);+  if (existing != ctx.conflicts.end())+    return existing->second;+  auto body = ctx.store.read_body(old_id, TYPE_CONFLICT);+  if (!body)+    return std::nullopt;+  auto conflict = decode_conflict(bytes_of(*body));+  if (!conflict)+    return std::nullopt;+  bool changed = false;+  auto rewire = [&](ConflictValue &value) -> bool {+    if (!value.target)+      return true;+    if (value.kind == KIND_FILE || value.kind == KIND_EXECUTABLE ||+        value.kind == KIND_SYMLINK) {+      if (!is_lazy_blob(*value.target))+        return true;+      auto mapped = materialize_blob(ctx, *value.target);+      if (!mapped)+        return false;+      if (std::memcmp(mapped->data(), value.target->data(), ID_LEN) != 0) {+        value.target = *mapped;+        changed = true;+      }+      return true;+    }+    if (value.kind == KIND_SUBTREE) {+      auto mapped = materialize_tree(ctx, *value.target, depth + 1);+      if (!mapped)+        return false;+      if (std::memcmp(mapped->data(), value.target->data(), ID_LEN) != 0) {+        value.target = *mapped;+        changed = true;+      }+      return true;+    }+    if (value.kind == KIND_CONFLICT) {+      auto mapped = materialize_conflict(ctx, *value.target, depth + 1);+      if (!mapped)+        return false;+      if (std::memcmp(mapped->data(), value.target->data(), ID_LEN) != 0) {+        value.target = *mapped;+        changed = true;+      }+      return true;+    }+    return true;+  };+  for (auto &value : conflict->adds) {+    if (!rewire(value))+      return std::nullopt;+  }+  for (auto &value : conflict->removes) {+    if (!rewire(value))+      return std::nullopt;+  }+  if (!changed) {+    ctx.conflicts[old_id] = old_id;+    return old_id;+  }+  const Id new_id =+      ctx.writer.add(TYPE_CONFLICT, encode_conflict(*conflict));+  ctx.conflicts[old_id] = new_id;+  ctx.changed = true;+  return new_id;+}++std::optional<Id> materialize_tree(MaterializeCtx &ctx, const Id &old_id,+                                   std::size_t depth) {+  if (depth > 4096)+    return std::nullopt;+  auto existing = ctx.trees.find(old_id);+  if (existing != ctx.trees.end())+    return existing->second;+  auto body = ctx.store.read_body(old_id, TYPE_TREE);+  if (!body)+    return std::nullopt;+  auto tree = decode_tree(bytes_of(*body));+  if (!tree)+    return std::nullopt;+  bool changed = false;+  std::vector<TreeEntry> entries = tree->entries;+  for (auto &entry : entries) {+    std::optional<Id> mapped;+    if (entry.kind == KIND_FILE || entry.kind == KIND_EXECUTABLE ||+        entry.kind == KIND_SYMLINK) {+      if (!is_lazy_blob(entry.target))+        continue;+      mapped = materialize_blob(ctx, entry.target);+    } else if (entry.kind == KIND_SUBTREE) {+      mapped = materialize_tree(ctx, entry.target, depth + 1);+    } else if (entry.kind == KIND_CONFLICT) {+      mapped = materialize_conflict(ctx, entry.target, depth + 1);+    } else if (entry.kind == KIND_SUBMODULE) {+      continue;+    } else {+      return std::nullopt;+    }+    if (!mapped)+      return std::nullopt;+    if (std::memcmp(mapped->data(), entry.target.data(), ID_LEN) != 0) {+      entry.target = *mapped;+      changed = true;+    }+  }+  if (!changed) {+    ctx.trees[old_id] = old_id;+    return old_id;+  }+  auto new_body = encode_tree(entries);+  if (!new_body)+    return std::nullopt;+  const Id new_id = ctx.writer.add(TYPE_TREE, *new_body);+  ctx.trees[old_id] = new_id;+  ++ctx.new_trees;+  ctx.changed = true;+  if (auto raw = git::load_raw(ctx.root, old_id))+    ctx.raw_saves.emplace_back(new_id, std::move(*raw));+  return new_id;+}++std::map<Id, git::Oid> reverse_git_map(const git::IdMap &map) {+  std::map<Id, git::Oid> out;+  for (const auto &item : map.items)+    out[item.second] = item.first;+  return out; }  std::string shell_quote(std::string_view value) {@@ -796,8 +972,157 @@       std::cout << "imported history; checkout failed (code "                 << checkout_status << ")\n";       return 1;+    }+  }+  return 0;+}++int git_materialize(const fs::path &root) {+  git::IdMap commits_map;+  git::IdMap trees_map;+  git::IdMap blobs_map;+  if (!git::load_map(root, "commits", commits_map) ||+      !git::load_map(root, "trees", trees_map) ||+      !git::load_map(root, "blobs", blobs_map)) {+    error_prefix();+    std::cout << "corrupt git mapping table\n";+    return 1;+  }+  const auto reverse_commits = reverse_git_map(commits_map);+  const auto reverse_trees = reverse_git_map(trees_map);++  Store store = Store::open_all(root);+  auto view = current_view(root, store);+  if (!view) {+    error_prefix();+    std::cout << "no operation state\n";+    return 1;+  }+  auto tx = Txn::begin(root, store);+  if (!tx) {+    error_prefix();+    std::cout << "cannot load repository state\n";+    return 1;+  }+  MaterializeCtx ctx{root, store, tx->writer(), {}, {}, {}, {}, {}, 0, 0, 0,+                     false};+  const auto roots = view_roots(*view);+  const auto ordered = ordered_commits(store, roots);+  for (const auto &old_id : ordered) {+    auto body = store.read_body(old_id, TYPE_COMMIT);+    if (!body)+      break;+    auto commit = decode_commit(bytes_of(*body));+    if (!commit)+      break;+    auto mapped_root = materialize_tree(ctx, commit->root_tree, 0);+    if (!mapped_root)+      break;+    bool changed =+        std::memcmp(mapped_root->data(), commit->root_tree.data(), ID_LEN) != 0;+    std::vector<Id> parents;+    parents.reserve(commit->parents.size());+    bool parents_ok = true;+    for (const auto &parent : commit->parents) {+      auto it = ctx.commits.find(parent);+      if (it == ctx.commits.end()) {+        parents_ok = false;+        break;+      }+      parents.push_back(it->second);+      if (std::memcmp(it->second.data(), parent.data(), ID_LEN) != 0)+        changed = true;+    }+    if (!parents_ok)+      break;+    if (!changed) {+      ctx.commits[old_id] = old_id;+      continue;+    }+    commit->root_tree = *mapped_root;+    commit->parents = std::move(parents);+    const Id new_id = ctx.writer.add(TYPE_COMMIT, encode_commit(*commit));+    ctx.commits[old_id] = new_id;+    ++ctx.new_commits;+    ctx.changed = true;+    if (auto raw = git::load_raw(root, old_id))+      ctx.raw_saves.emplace_back(new_id, std::move(*raw));+  }+  if (ctx.commits.size() != ordered.size()) {+    error_prefix();+    std::cout << "git materialize failed (missing or corrupt object)\n";+    return 1;+  }++  View &updated = tx->view();+  auto remap = [&](const Id &id) -> Id {+    auto it = ctx.commits.find(id);+    return it == ctx.commits.end() ? id : it->second;+  };+  for (auto &head : updated.heads)+    head = remap(head);+  for (auto &bookmark : updated.bookmarks) {+    for (auto &target : bookmark.targets.adds) {+      if (target)+        target = remap(*target);+    }+    for (auto &target : bookmark.targets.removes) {+      if (target)+        target = remap(*target);     }+  }+  for (auto &tag : updated.tags)+    tag.target = remap(tag.target);+  for (auto &ref : updated.remote_refs)+    ref.target = remap(ref.target);+  for (auto &workspace : updated.working_copies)+    workspace.target = remap(workspace.target);+  sort_ids(updated.heads);++  if (!ctx.changed) {+    info_prefix();+    std::cout << "already materialized\n";+    return 0;+  }+  auto status = tx->finish("git materialize");+  if (!status) {+    error_prefix();+    std::cout << "failed to write object pack\n";+    return 1;+  }+  for (const auto &raw : ctx.raw_saves)+    (void)git::save_raw(root, raw.first,+                        Bytes(raw.second.data(), raw.second.size()));+  for (const auto &item : ctx.commits) {+    if (std::memcmp(item.first.data(), item.second.data(), ID_LEN) == 0)+      continue;+    auto it = reverse_commits.find(item.first);+    if (it != reverse_commits.end())+      commits_map.put(it->second, item.second);+  }+  for (const auto &item : ctx.trees) {+    if (std::memcmp(item.first.data(), item.second.data(), ID_LEN) == 0)+      continue;+    auto it = reverse_trees.find(item.first);+    if (it != reverse_trees.end())+      trees_map.put(it->second, item.second);+  }+  for (const auto &item : ctx.blobs) {+    if (std::memcmp(item.first.data(), item.second.data(), ID_LEN) == 0)+      continue;+    if (auto oid = git::lazy_blob_oid(item.first))+      blobs_map.put(*oid, item.second);+  }+  if (!git::save_map(root, "commits", commits_map) ||+      !git::save_map(root, "trees", trees_map) ||+      !git::save_map(root, "blobs", blobs_map)) {+    error_prefix();+    std::cout << "failed to write git mapping tables\n";   }+  clear_stat_cache(root);+  info_prefix();+  std::cout << "materialized " << ctx.new_commits << " commits, "+            << ctx.new_trees << " trees, " << ctx.new_blobs << " blobs\n";   return 0; } @@ -1040,6 +1365,26 @@     return 1;   }   return git_export(*root);+}++int git_materialize_cli(const std::vector<std::string> &args) {+  std::string repo_path = ".";+  for (std::size_t i = 3; i < args.size(); ++i) {+    const std::string &arg = args[i];+    if (!arg.empty() && arg.front() == '-') {+      error_prefix();+      std::cout << "unknown flag: " << arg << "\n";+      return 1;+    }+    repo_path = arg;+  }+  const auto root = discover_repo(path_from_bytes(repo_path));+  if (!root) {+    error_prefix();+    std::cout << "not a veins repository: " << repo_path << "\n";+    return 1;+  }+  return git_materialize(*root); }  int git_fetch_cli(const std::vector<std::string> &args) {@@ -1159,7 +1504,8 @@ int git_cli_run(const std::vector<std::string> &args) {   if (args.size() < 3) {     error_prefix();-    std::cout << "expected a git subcommand (import)\n";+    std::cout << "expected a git subcommand (import, export, materialize, "+                 "fetch, push, remote)\n";     return 1;   }   const std::string &sub = args[2];@@ -1167,6 +1513,8 @@     return git_import_cli(args);   if (sub == "export")     return git_export_cli(args);+  if (sub == "materialize")+    return git_materialize_cli(args);   if (sub == "fetch")     return git_fetch_cli(args);   if (sub == "push")--- a/xveins/src/git.h+++ b/xveins/src/git.h@@ -11,6 +11,7 @@  int git_import(const fs::path &root); int git_export(const fs::path &root);+int git_materialize(const fs::path &root); int git_fetch(const fs::path &root, std::string_view remote); int git_push(const fs::path &root, std::string_view remote,              std::string_view bookmark);