code wiki / _hdl_build / nx_sovgit_repo_gate.nx

nx_sovgit_repo_gate.nx source

↩ module page · 81 lines · 4864 B

1// nx_sovgit_repo_gate.nx -- ★SOVGIT rung X1a: assemble a REAL bare git repo from the X0 object store (loose 2// blob/tree/commit + refs/heads/master + HEAD + config with object-format=sha256), so a STOCK `git clone` round-trips 3// it. This is REPO-level interop (a full clone: HEAD->master->commit->tree->blob->checkout), beyond X0's single-object 4// read. GREEN => the bare repo is assembled + self-consistent; the out-of-gate `git clone` proves stock-git interop. 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_sovgit_obj.nx" 7 8func hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 9func show64(g: *u8) -> i64 { var i: i64 = 0; while i < 64 { sys_write(1, (g as i64 + i) as *u8, 1); i = i + 1 } return 0 } 10func hexeq(got: *u8, exp: *u8) -> i64 { 11 var i: i64 = 0 12 while i < 64 { if exp[i] == (0 as u8) { return 0 } if got[i] != exp[i] { return 0 } i = i + 1 } 13 return 1 14} 15// write a whole file (create/trunc, 0644) with n bytes 16func wfile(path: *u8, buf: *u8, n: i64) -> i64 { 17 let fd: i64 = sys_openat_wr(path, 0x1a4) 18 if fd < 0 { return 0 - 1 } 19 sys_write(fd, buf, n) 20 sys_close(fd) 21 return 0 22} 23func wstr(path: *u8, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return wfile(path, s, n) } 24 25func main() -> i64 { 26 hw("=== nx_sovgit_repo_gate -- X1a: bare git repo (object-format=sha256) clonable by STOCK git ===\n" as *u8) 27 var fails: *i64 = sys_mmap(16) as *i64 28 fails[0] = 0 29 30 // ---- repo skeleton dirs ---- 31 sys_mkdir("knowledge/_sovgit_repo" as *u8, 0x1ed) 32 sys_mkdir("knowledge/_sovgit_repo/refs" as *u8, 0x1ed) 33 sys_mkdir("knowledge/_sovgit_repo/refs/heads" as *u8, 0x1ed) 34 let objroot: *u8 = "knowledge/_sovgit_repo/objects" as *u8 35 36 // ---- objects (reuse X0 loose-object writer) ---- 37 let bhex: *u8 = sys_mmap(80) 38 sg_write_loose(objroot, "blob" as *u8, "hello" as *u8, 5, bhex) 39 let raw: *u8 = sys_mmap(32) 40 sg_oid_raw("blob" as *u8, "hello" as *u8, 5, raw) 41 let tree: *u8 = sys_mmap(128) 42 let tlen: i64 = sg_tree_entry(tree, 0, "100644" as *u8, "hello.txt" as *u8, raw) 43 let thex: *u8 = sys_mmap(80) 44 sg_write_loose(objroot, "tree" as *u8, tree, tlen, thex) 45 let cbody: *u8 = "tree 06d48a30caf6b4263876dbc71cec3bedfa08df79a4a59d55fbb9ea106a1ecc9c\nauthor t <t@t> 1700000000 +0000\ncommitter t <t@t> 1700000000 +0000\n\nmsg\n" as *u8 46 let clen: i64 = sg_slen(cbody) 47 let chex: *u8 = sys_mmap(80) 48 sg_write_loose(objroot, "commit" as *u8, cbody, clen, chex) 49 50 // ---- refs/heads/master = <commit-hex>\n ---- 51 let mref: *u8 = sys_mmap(80) 52 var mo: i64 = sg_cpy(mref, 0, chex, 0, 64) 53 mref[mo] = 10 as u8; mo = mo + 1 54 wfile("knowledge/_sovgit_repo/refs/heads/master" as *u8, mref, mo) 55 56 // ---- HEAD symbolic ref ---- 57 wstr("knowledge/_sovgit_repo/HEAD" as *u8, "ref: refs/heads/master\n" as *u8) 58 59 // ---- config: version 1 + bare + object-format sha256 (git needs this to read our sha256 objects) ---- 60 wstr("knowledge/_sovgit_repo/config" as *u8, "[core]\n repositoryformatversion = 1\n bare = true\n[extensions]\n objectformat = sha256\n" as *u8) 61 62 // ---- self-checks ---- 63 hw("repo -> knowledge/_sovgit_repo (bare, object-format=sha256)\n" as *u8) 64 hw(" HEAD commit = " as *u8); show64(chex); hw("\n" as *u8) 65 if hexeq(chex, "02acc3e80a9f6c427e5013d38a788218a59adaba62eaa221ee570a4df963407e" as *u8) == 1 { hw(" T1 commit id matches stock-git oracle OK\n" as *u8) } 66 if hexeq(chex, "02acc3e80a9f6c427e5013d38a788218a59adaba62eaa221ee570a4df963407e" as *u8) != 1 { hw(" T1 FAIL commit id mismatch\n" as *u8); fails[0] = fails[0] + 1 } 67 if hexeq(bhex, "8aec4e4876f854f688d0ebfc8f37598f38e5fd6903cccc850ca36591175aeb60" as *u8) != 1 { hw(" T2 FAIL blob id\n" as *u8); fails[0] = fails[0] + 1 } 68 if hexeq(thex, "06d48a30caf6b4263876dbc71cec3bedfa08df79a4a59d55fbb9ea106a1ecc9c" as *u8) != 1 { hw(" T3 FAIL tree id\n" as *u8); fails[0] = fails[0] + 1 } 69 // verify HEAD + config + master ref landed on disk (>0 bytes) 70 let szp: *i64 = sys_mmap(16) as *i64 71 let hb: *u8 = sys_read_file("knowledge/_sovgit_repo/HEAD" as *u8, szp) 72 if (hb as i64) == 0 { hw(" T4 FAIL HEAD missing\n" as *u8); fails[0] = fails[0] + 1 } 73 let cb: *u8 = sys_read_file("knowledge/_sovgit_repo/config" as *u8, szp) 74 if (cb as i64) == 0 { hw(" T5 FAIL config missing\n" as *u8); fails[0] = fails[0] + 1 } 75 76 hw("\n" as *u8) 77 if fails[0] == 0 { hw("SOVGIT-X1a GREEN -- bare git repo assembled from X0 objects; run stock `git clone` to prove interop\n" as *u8); sys_exit(0); return 0 } 78 hw("SOVGIT-X1a RED fails=" as *u8); var d: i64 = fails[0]; if d == 0 { hw("0" as *u8) } while d > 0 { let ch: *u8 = sys_mmap(2); ch[0] = (48 + d % 10) as u8; sys_write(1, ch, 1); d = d / 10 } hw("\n" as *u8) 79 sys_exit(1) 80 return 1 81}