From 7f4b8bc803f0d343987d69004355438bdd594e6c Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 21 Sep 2025 12:51:03 +0800 Subject: [PATCH] Unify naming scheme --- cmd/show-object/main.ha | 16 ++++++++-------- git/ident.ha | 4 ++-- git/loose.ha | 22 +++++++++++----------- git/obj_blob.ha | 4 ++-- git/obj_commit.ha | 20 ++++++++++---------- git/obj_tag.ha | 12 ++++++------ git/obj_tree.ha | 14 +++++++------- git/object.ha | 10 +++++----- git/oid.ha | 4 ++-- git/packed.ha | 112 +++++++++++++++++++++++++++--------------------------- git/refs.ha | 12 ++++++------ git/repo.ha | 4 ++-- git/walk.ha | 4 ++-- diff --git a/cmd/show-object/main.ha b/cmd/show-object/main.ha index ddc7d0127ef1c7c6dcc806d866b4f73851d7cf6d..d4ac36a777ddbd4f175afe5e1a27703c3e5d44ff 100644 --- a/cmd/show-object/main.ha +++ b/cmd/show-object/main.ha @@ -19,7 +19,7 @@ fn print_tree(t: git::tree) void = { for (let i = 0z; i < len(t.entries); i += 1z) { const ent = t.entries[i]; - const hex = git::oid_string(ent.oid)!; + const hex = git::oid_stringify(ent.oid)!; defer free(hex); const name = strings::fromutf8_unsafe(ent.name); @@ -34,12 +34,12 @@ fmt::printfln("{} {} <{}> {} {}", label, name, email, id.when, id.ofs)!; }; fn print_commit(c: git::commit) void = { - const treehex = git::oid_string(c.tree)!; + const treehex = git::oid_stringify(c.tree)!; defer free(treehex); fmt::printfln("tree {}", treehex)!; for (let i = 0z; i < len(c.parents); i += 1z) { - const phex = git::oid_string(c.parents[i])!; + const phex = git::oid_stringify(c.parents[i])!; defer free(phex); fmt::printfln("parent {}", phex)!; }; @@ -54,7 +54,7 @@ fmt::println(msg)!; }; fn print_tag(t: git::tag) void = { - const tgt = git::oid_string(t.target)!; + const tgt = git::oid_stringify(t.target)!; defer free(tgt); let ty: str = ""; @@ -117,17 +117,17 @@ }; const rp = repo_path: str; - let r = match (git::open(rp)) { + let r = match (git::repo_open(rp)) { case let rr: git::repo => yield rr; case let fe: fs::error => fmt::errorfln("open repo: {}", fs::strerror(fe))!; os::exit(1); }; - defer git::close(r); + defer git::repo_close(r); const oidhex = cmd.args[0]; - let id = match (git::parse_oid(oidhex)) { + let id = match (git::oid_parse(oidhex)) { case let o: git::oid => yield o; case => @@ -135,7 +135,7 @@ fmt::errorfln("invalid oid: {}", oidhex)!; os::exit(1); }; - let obj = match (git::read_object(r, id)) { + let obj = match (git::object_read(r, id)) { case let o: git::object => yield o; case let fe: fs::error => diff --git a/git/ident.ha b/git/ident.ha index d6c038c6f807d2525953b703cf78d266fe7b91ed..11ca3f9a71820ed78d9ce1688ab38ce35072dd2d 100644 --- a/git/ident.ha +++ b/git/ident.ha @@ -20,7 +20,7 @@ free(p.email); }; // Parses an [[ident]] from its canonical byte-slice representation. -fn parse_ident( +fn ident_parse( line: []u8, ) (ident | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let mlt = bytes::index(line, '<'); @@ -76,7 +76,7 @@ return ident { name = name, email = email, when = when, ofs = ofs }; }; // Returns the canonical form for an ident. -export fn serialize_ident(p: ident) ([]u8 | nomem) = { +export fn ident_serialize(p: ident) ([]u8 | nomem) = { const whens = strconv::i64tos(p.when); const whenb = strings::toutf8(whens); diff --git a/git/loose.ha b/git/loose.ha index 9d633d34780d6be3a9fe6c2bd4bf7410d38b42cd..ddf6b2f7766ade91619242734fea14a666f02d42 100644 --- a/git/loose.ha +++ b/git/loose.ha @@ -11,8 +11,8 @@ use encoding::utf8; // Find the path to a loose object with the given ID, // relative to the repository root. -fn loose_relpath(id: oid) (str | nomem) = { - const hex = oid_string(id)?; +fn loose_path_resolve(id: oid) (str | nomem) = { + const hex = oid_stringify(id)?; defer free(hex); const dir = strings::bytesub(hex, 0z, 2z)!; @@ -22,11 +22,11 @@ return fmt::asprintf("objects/{}/{}", dir, file); }; // Reads a loose object from the repository by its ID. -export fn read_loose( +export fn loose_read( r: repo, id: oid, ) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem | utf8::invalid) = { - const rel = loose_relpath(id)?; + const rel = loose_path_resolve(id)?; defer free(rel); const fh = fs::open(r.root, rel)?; @@ -61,21 +61,21 @@ if (expect != len(body)) { return errors::invalid; }; - if (!verify_oid(buf, id)) { + if (!object_verify_oid(buf, id)) { return errors::invalid; }; if (ty == "blob") { - const b = parse_blob(body)?; + const b = blob_parse(body)?; return (b: object); } else if (ty == "tree") { - const t = parse_tree(body)?; + const t = tree_parse(body)?; return (t: object); } else if (ty == "commit") { - const c = parse_commit(body)?; + const c = commit_parse(body)?; return (c: object); } else if (ty == "tag") { - const g = parse_tag(body)?; + const g = tag_parse(body)?; return (g: object); }; @@ -84,11 +84,11 @@ }; // Reads a loose object from the repository by its ID, // returning its type and raw data. -export fn read_loose_typed( +export fn loose_read_typed( r: repo, id: oid, ) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | nomem) = { - const rel = loose_relpath(id)?; + const rel = loose_path_resolve(id)?; defer free(rel); let fh = fs::open(r.root, rel)?; diff --git a/git/obj_blob.ha b/git/obj_blob.ha index 4a94f87ecc20cdc445142daa1011c1198073cb46..09ee1948a591f8cbad72d307b6890a976af4fda4 100644 --- a/git/obj_blob.ha +++ b/git/obj_blob.ha @@ -14,14 +14,14 @@ // Parses a blob from its raw data. // The data is copied and the resulting blob // must be finished with [[blob_finish]]. -export fn parse_blob(body: []u8) (blob | nomem) = { +export fn blob_parse(body: []u8) (blob | nomem) = { let data = alloc(body...)?; return blob { data = data }; }; // Serializes a blob into the on-disk format. -export fn serialize_blob(b: blob) ([]u8 | nomem) = { +export fn blob_serialize(b: blob) ([]u8 | nomem) = { const sizes = strconv::ztos(len(b.data)); const ty = strings::toutf8("blob "); const sizesb = strings::toutf8(sizes); diff --git a/git/obj_commit.ha b/git/obj_commit.ha index f48a389ccea92bb2a8cffc890e350053b46b17a7..96b68d7c9093a3b0ecbdf58d25a9410fde2ef59e 100644 --- a/git/obj_commit.ha +++ b/git/obj_commit.ha @@ -23,7 +23,7 @@ free(c.message); }; // Parses a commit from its raw data and object ID. -export fn parse_commit( +export fn commit_parse( body: []u8, ) (commit | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let c = commit { @@ -51,7 +51,7 @@ }; if (bytes::hasprefix(line, strings::toutf8("tree "))) { const hex = strings::fromutf8(line[5..])?; - match (parse_oid(hex)) { + match (oid_parse(hex)) { case let o: oid => c.tree = o; case nomem => @@ -61,7 +61,7 @@ return errors::invalid; }; } else if (bytes::hasprefix(line, strings::toutf8("parent "))) { const hex = strings::fromutf8(line[7..])?; - match (parse_oid(hex)) { + match (oid_parse(hex)) { case let o: oid => append(c.parents, o)!; case nomem => @@ -70,11 +70,11 @@ case => return errors::invalid; }; } else if (bytes::hasprefix(line, strings::toutf8("author "))) { - const per = parse_ident(line[7..])?; + const per = ident_parse(line[7..])?; ident_finish(c.author); c.author = per; } else if (bytes::hasprefix(line, strings::toutf8("committer "))) { - const per = parse_ident(line[10..])?; + const per = ident_parse(line[10..])?; ident_finish(c.committer); c.committer = per; } else if ( @@ -107,20 +107,20 @@ return c; }; // Serializes a commit into its on-disk format. -export fn serialize_commit(c: commit) ([]u8 | nomem) = { - const treehex = oid_string(c.tree)?; +export fn commit_serialize(c: commit) ([]u8 | nomem) = { + const treehex = oid_stringify(c.tree)?; defer free(treehex); let parenthex: []const str = []; for (let i = 0z; i < len(c.parents); i += 1z) { - const hex = oid_string(c.parents[i])?; + const hex = oid_stringify(c.parents[i])?; append(parenthex, hex)!; }; - let authorb = serialize_ident(c.author)?; + let authorb = ident_serialize(c.author)?; defer free(authorb); - let committerb = serialize_ident(c.committer)?; + let committerb = ident_serialize(c.committer)?; defer free(committerb); let bodylen = 0z; diff --git a/git/obj_tag.ha b/git/obj_tag.ha index 5b72bb537b977adda471df6b92a329512d891bf4..db19c8237c55ab13b0bcdd4803843fcfe71ace74 100644 --- a/git/obj_tag.ha +++ b/git/obj_tag.ha @@ -26,7 +26,7 @@ free(t.message); }; // Parses a tag from its raw data. -export fn parse_tag( +export fn tag_parse( body: []u8, ) (tag | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let t = tag { @@ -56,7 +56,7 @@ }; if (bytes::hasprefix(line, strings::toutf8("object "))) { const hex = strings::fromutf8(line[7..])?; - match (parse_oid(hex)) { + match (oid_parse(hex)) { case let o: oid => t.target = o; have_target = true; @@ -83,7 +83,7 @@ let name = alloc(name_b...)?; free(t.name); t.name = name; } else if (bytes::hasprefix(line, strings::toutf8("tagger "))) { - const per = parse_ident(line[7..])?; + const per = ident_parse(line[7..])?; match (t.tagger) { case let old: ident => ident_finish(old); @@ -125,7 +125,7 @@ return t; }; // Serializes a tag into the on-disk format. -export fn serialize_tag(t: tag) ([]u8 | errors::invalid | nomem) = { +export fn tag_serialize(t: tag) ([]u8 | errors::invalid | nomem) = { let tyname: (const str | void) = void; switch (t.target_type) { case objtype::OBJ_COMMIT => tyname = "commit"; @@ -136,13 +136,13 @@ case => return errors::invalid; }; const tynameb = strings::toutf8((tyname: const str)); - const objhex = oid_string(t.target)?; + const objhex = oid_stringify(t.target)?; defer free(objhex); let taggerb: ([]u8 | void) = void; match (t.tagger) { case let id: ident => - taggerb = serialize_ident(id)?; + taggerb = ident_serialize(id)?; case void => void; }; diff --git a/git/obj_tree.ha b/git/obj_tree.ha index f1c9be7d567c4d35b3964f97054b5a0f7d930f3b..d44a2892f400f6e2a79f370ec90cfcede69c5c14 100644 --- a/git/obj_tree.ha +++ b/git/obj_tree.ha @@ -34,7 +34,7 @@ free(te.name); }; // Parses a tree from its raw data and object ID. -export fn parse_tree(body: []u8) (tree | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { +export fn tree_parse(body: []u8) (tree | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let entries: []tree_entry = []; let i = 0z; @@ -69,7 +69,7 @@ return tree { entries = entries }; }; // Looks up a tree entry by name. -fn tree_entry_by_name_raw(t: *const tree, name: []const u8) (*const tree_entry | void) = { +fn tree_entry_lookup_raw(t: *const tree, name: []const u8) (*const tree_entry | void) = { for (let i = 0z; i < len(t.entries); i += 1z) { if (bytes::equal(t.entries[i].name, name)) { return &t.entries[i]; @@ -79,7 +79,7 @@ return void; }; // Recursively looks up a tree or blob at the given path, -export fn tree_at_path( +export fn tree_resolve_path( r: repo, root: const tree, path: const []u8, @@ -104,7 +104,7 @@ return errors::invalid; }; let comp = path[i..j]; - let entp = tree_entry_by_name_raw(&root, comp); + let entp = tree_entry_lookup_raw(&root, comp); let ent: *const tree_entry = match (entp) { case let p: *const tree_entry => yield p; @@ -114,7 +114,7 @@ }; let last = (j == len(path)); if (last) { - match (read_object(r, ent.oid)) { + match (object_read(r, ent.oid)) { case let t: tree => if (owned_root) { tree_finish(root); @@ -132,7 +132,7 @@ }; return errors::invalid; }; } else { - match (read_object(r, ent.oid)) { + match (object_read(r, ent.oid)) { case let t: tree => if (owned_root) { tree_finish(root); @@ -156,7 +156,7 @@ return errors::invalid; }; // Serializes a tree into the on-disk format. -export fn serialize_tree(t: tree) ([]u8 | nomem) = { +export fn tree_serialize(t: tree) ([]u8 | nomem) = { let bodylen = 0z; for (let e .. t.entries) { const modes = strconv::u32tos(e.mode, strconv::base::OCT); diff --git a/git/object.ha b/git/object.ha index d1960aab8239c478dd03959c987b1e20c0c42448..270443ea9dbbdf6534f9a73bf34a4acc1d91505d 100644 --- a/git/object.ha +++ b/git/object.ha @@ -45,7 +45,7 @@ }; // Verifies that the given buffer (which must be the exact on-disk format // structured as "type size\0body") matches the given object ID. -export fn verify_oid(buf: []u8, want: oid) bool = { +export fn object_verify_oid(buf: []u8, want: oid) bool = { let st = sha256::sha256(); hash::write(&st, buf); @@ -57,7 +57,7 @@ return bytes::equal(got[..], want[..]); }; // Verifies that the given typed body matches the given object ID. -export fn verify_typed(ty: objtype, body: []u8, want: oid) bool = { +export fn object_verify_typed(ty: objtype, body: []u8, want: oid) bool = { let st = sha256::sha256(); defer hash::close(&st); @@ -88,11 +88,11 @@ return bytes::equal(got[..], want[..]); }; // Reads a Git object from the repository by its ID. -export fn read_object( +export fn object_read( r: repo, id: oid, ) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem) = { - match (read_loose(r, id)) { + match (loose_read(r, id)) { case let o: object => return o; case let fe: fs::error => @@ -105,7 +105,7 @@ case let e: (io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem) => return e; }; - match (read_packed(r, id)) { + match (pack_read(r, id)) { case let o: object => return o; case let fe: fs::error => diff --git a/git/oid.ha b/git/oid.ha index 7724d7288c8cbf66a2137eb2eb7bf76b23e3c34c..cd981771ed3fb323e98089f6cc4fd18724ebe41a 100644 --- a/git/oid.ha +++ b/git/oid.ha @@ -7,7 +7,7 @@ // A Git object ID. Currently, only SHA-256 is supported. export type oid = [sha256::SZ]u8; // Parses a hex-encoded string representation of an [[oid]]. -export fn parse_oid(s: const str) (oid | nomem | errors::invalid) = { +export fn oid_parse(s: const str) (oid | nomem | errors::invalid) = { if (len(s) != sha256::SZ * 2) { return errors::invalid; }; @@ -23,6 +23,6 @@ }; // Returns a hex-encoded string representation of the given [[oid]]. // The returned string is allocated on the heap and must be freed by the caller. -export fn oid_string(id: oid) (const str | nomem) = { +export fn oid_stringify(id: oid) (const str | nomem) = { return hex::encodestr(id)?; }; diff --git a/git/packed.ha b/git/packed.ha index 4b4eacd35e9c49b1ab783d779e2e122bf87db54a..344854117b779ad2a45e61bb6b2bcbe039274f71 100644 --- a/git/packed.ha +++ b/git/packed.ha @@ -20,7 +20,7 @@ pack_rel: str, ofs: u64, }; -fn cmp_oid(a: []u8, b: oid) i32 = { +fn pack_oid_cmp(a: []u8, b: oid) i32 = { for (let i = 0z; i < sha256::SZ; i += 1z) { let av = a[i]; let bv = b[i]; @@ -34,7 +34,7 @@ }; return 0; }; -fn count_large_before(off32: []u8, idx: size) size = { +fn pack_index_count_large_before(off32: []u8, idx: size) size = { let n = 0z; for (let i = 0z; i < idx; i += 1z) { let o32 = endian::begetu32(off32[i*4z .. i*4z + 4z]); @@ -46,15 +46,15 @@ return n; }; // Reads a packed object by its ID from the given repository. -export fn read_packed( +export fn pack_read( r: repo, id: oid, ) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | errors::noentry | utf8::invalid | nomem) = { - let loc = find_in_indexes(r, id)?; - return read_from_pack_at(r, loc, id); + let loc = pack_index_find(r, id)?; + return pack_read_at(r, loc, id); }; -fn find_in_indexes( +fn pack_index_find( r: repo, id: oid, ) (pack_loc | errors::noentry | fs::error | io::error | errors::invalid | nomem) = { @@ -71,7 +71,7 @@ }; { let rel = fmt::asprintf("{}/{}", dir, de.name)?; - match (idx_lookup(r, rel, id)) { + match (pack_index_lookup(r, rel, id)) { case let pl: pack_loc => free(rel); return pl; @@ -103,7 +103,7 @@ return errors::noentry; }; -fn idx_lookup( +fn pack_index_lookup( r: repo, idx_rel: const str, id: oid, @@ -177,7 +177,7 @@ for (l < h) { let m = l + (h - l) / 2z; let cand = buf[names_off + m*sha256::SZ .. names_off + (m+1z)*sha256::SZ]; - let c = cmp_oid(cand, id); + let c = pack_oid_cmp(cand, id); if (c == 0) { found = true; idx = m; @@ -198,7 +198,7 @@ let ofs: u64 = 0u64; if ((o32 & 0x8000_0000u32) == 0u32) { ofs = (o32: u64); } else { - let nlarge_before = count_large_before(buf[off32_off..], idx); + let nlarge_before = pack_index_count_large_before(buf[off32_off..], idx); let p = off64_off + nlarge_before * 8z; let o64be = endian::begetu64(buf[p .. p + 8z]); ofs = o64be; @@ -214,7 +214,7 @@ return pack_loc { pack_rel = packpath, ofs = ofs }; }; -fn read_from_pack_at( +fn pack_read_at( r: repo, loc: pack_loc, want: oid, @@ -242,7 +242,7 @@ io::seek(h, (loc.ofs: i64), io::whence::SET)?; let ty: objtype = objtype::OBJ_INVALID; - match (read_obj_header(h)) { + match (pack_header_read(h)) { case let t: (u8, size, size) => ty = (t.0: objtype); case let ioe: io::error => @@ -259,19 +259,19 @@ }; switch (ty) { case objtype::OBJ_COMMIT => - body = inflate_section(h)?; + body = pack_section_inflate(h)?; full_ty = objtype::OBJ_COMMIT; case objtype::OBJ_TREE => - body = inflate_section(h)?; + body = pack_section_inflate(h)?; full_ty = objtype::OBJ_TREE; case objtype::OBJ_BLOB => - body = inflate_section(h)?; + body = pack_section_inflate(h)?; full_ty = objtype::OBJ_BLOB; case objtype::OBJ_TAG => - body = inflate_section(h)?; + body = pack_section_inflate(h)?; full_ty = objtype::OBJ_TAG; case objtype::OBJ_REF_DELTA => - match (resolve_ref_delta(r, h)) { + match (pack_delta_resolve_ref(r, h)) { case let t2: (objtype, []u8) => full_ty = t2.0; body = t2.1; @@ -279,7 +279,7 @@ case let e: (fs::error | io::error | errors::invalid | errors::noentry | nomem) => return e; }; case objtype::OBJ_OFS_DELTA => - match (resolve_ofs_delta(r, h, loc)) { + match (pack_delta_resolve_ofs(r, h, loc)) { case let t2: (objtype, []u8) => full_ty = t2.0; body = t2.1; @@ -291,29 +291,29 @@ return errors::invalid; }; // Verify BEFORE parsing using objtype (not a string). - if (!verify_typed(full_ty, body, want)) { + if (!object_verify_typed(full_ty, body, want)) { return errors::invalid; }; // Parse into a structured object. if (full_ty == objtype::OBJ_BLOB) { - const b = parse_blob(body)?; + const b = blob_parse(body)?; return (b: object); } else if (full_ty == objtype::OBJ_TREE) { - const t = parse_tree(body)?; + const t = tree_parse(body)?; return (t: object); } else if (full_ty == objtype::OBJ_COMMIT) { - const c = parse_commit(body)?; + const c = commit_parse(body)?; return (c: object); } else if (full_ty == objtype::OBJ_TAG) { - const g = parse_tag(body)?; + const g = tag_parse(body)?; return (g: object); }; return errors::invalid; }; -fn read_obj_header(h: io::handle) ((u8, size, size) | io::error | errors::invalid) = { +fn pack_header_read(h: io::handle) ((u8, size, size) | io::error | errors::invalid) = { let consumed = 0z; let b0: [1]u8 = [0]; @@ -356,7 +356,7 @@ return (ty, sz, consumed); }; -fn inflate_section(h: io::handle) ([]u8 | io::error | nomem) = { +fn pack_section_inflate(h: io::handle) ([]u8 | io::error | nomem) = { let zr = zlib::decompress(h)?; defer io::close(&zr.vtable)!; @@ -364,7 +364,7 @@ let out = io::drain(&zr.vtable)?; return out; }; -fn resolve_ref_delta( +fn pack_delta_resolve_ref( r: repo, h: io::handle, ) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | nomem) = { @@ -378,15 +378,15 @@ case let ioe: io::error => return ioe; }; - let delta = inflate_section(h)?; + let delta = pack_section_inflate(h)?; defer free(delta); - let bt = read_resolved_body_by_id(r, base)?; - let out = apply_delta(bt.1, delta)?; + let bt = pack_body_resolve_by_id(r, base)?; + let out = pack_delta_apply(bt.1, delta)?; return (bt.0, out); }; -fn read_ofs_distance(h: io::handle) (u64 | io::error | errors::invalid) = { +fn pack_delta_read_ofs_distance(h: io::handle) (u64 | io::error | errors::invalid) = { let b: [1]u8 = [0]; match (io::readall(h, b)) { case size => @@ -421,12 +421,12 @@ return dist; }; -fn resolve_ofs_delta( +fn pack_delta_resolve_ofs( r: repo, h: io::handle, loc: pack_loc, ) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | nomem) = { - let dist = read_ofs_distance(h)?; + let dist = pack_delta_read_ofs_distance(h)?; let base_ofs: u64 = if (loc.ofs > dist) { yield loc.ofs - dist; } else { @@ -436,25 +436,25 @@ if (base_ofs == 0u64) { return errors::invalid; }; - let bt = read_resolved_body_at_ofs(r, loc.pack_rel, base_ofs)?; - let delta = inflate_section(h)?; + let bt = pack_body_resolve_at_ofs(r, loc.pack_rel, base_ofs)?; + let delta = pack_section_inflate(h)?; defer free(delta); - let out = apply_delta(bt.1, delta)?; + let out = pack_delta_apply(bt.1, delta)?; return (bt.0, out); }; -fn read_resolved_body_by_id( +fn pack_body_resolve_by_id( r: repo, id: oid, ) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | nomem) = { - match (find_in_indexes(r, id)) { + match (pack_index_find(r, id)) { case let pl: pack_loc => - let res = read_resolved_body_at_ofs(r, pl.pack_rel, pl.ofs); + let res = pack_body_resolve_at_ofs(r, pl.pack_rel, pl.ofs); free(pl.pack_rel); return res; case errors::noentry => - return read_loose_typed(r, id); + return loose_read_typed(r, id); case let fe: fs::error => return fe; case let ioe: io::error => @@ -466,7 +466,7 @@ return nomem; }; }; -fn read_resolved_body_at_ofs( +fn pack_body_resolve_at_ofs( r: repo, pack_rel: str, ofs: u64, @@ -490,20 +490,20 @@ return errors::invalid; }; io::seek(h, (ofs: i64), io::whence::SET)?; - match (read_obj_header(h)) { + match (pack_header_read(h)) { case let t: (u8, size, size) => switch ((t.0: objtype)) { case objtype::OBJ_COMMIT => - let body = inflate_section(h)?; + let body = pack_section_inflate(h)?; return (objtype::OBJ_COMMIT, body); case objtype::OBJ_TREE => - let body = inflate_section(h)?; + let body = pack_section_inflate(h)?; return (objtype::OBJ_TREE, body); case objtype::OBJ_BLOB => - let body = inflate_section(h)?; + let body = pack_section_inflate(h)?; return (objtype::OBJ_BLOB, body); case objtype::OBJ_TAG => - let body = inflate_section(h)?; + let body = pack_section_inflate(h)?; return (objtype::OBJ_TAG, body); case objtype::OBJ_REF_DELTA => let base: oid = [0...]; @@ -515,13 +515,13 @@ return errors::invalid; case let ioe: io::error => return ioe; }; - let delta = inflate_section(h)?; + let delta = pack_section_inflate(h)?; defer free(delta); - let bt = read_resolved_body_by_id(r, base)?; - let out = apply_delta(bt.1, delta)?; + let bt = pack_body_resolve_by_id(r, base)?; + let out = pack_delta_apply(bt.1, delta)?; return (bt.0, out); case objtype::OBJ_OFS_DELTA => - let dist = read_ofs_distance(h)?; + let dist = pack_delta_read_ofs_distance(h)?; let base_ofs: u64 = if (ofs > dist) { yield ofs - dist; } else { @@ -531,10 +531,10 @@ if (base_ofs == 0u64) { return errors::invalid; }; - let delta = inflate_section(h)?; + let delta = pack_section_inflate(h)?; defer free(delta); - let bt = read_resolved_body_at_ofs(r, pack_rel, base_ofs)?; - let out = apply_delta(bt.1, delta)?; + let bt = pack_body_resolve_at_ofs(r, pack_rel, base_ofs)?; + let out = pack_delta_apply(bt.1, delta)?; return (bt.0, out); case => return errors::invalid; @@ -546,11 +546,11 @@ return errors::invalid; }; }; -fn apply_delta(base: []u8, delta: []u8) ([]u8 | errors::invalid | nomem) = { +fn pack_delta_apply(base: []u8, delta: []u8) ([]u8 | errors::invalid | nomem) = { let i = 0z; - let srcsz = read_varint(delta, &i)?; - let dstsz = read_varint(delta, &i)?; + let srcsz = pack_varint_read(delta, &i)?; + let dstsz = pack_varint_read(delta, &i)?; if (srcsz != len(base)) { return errors::invalid; @@ -645,7 +645,7 @@ return out; }; -fn read_varint(buf: []u8, ip: *size) (size | errors::invalid) = { +fn pack_varint_read(buf: []u8, ip: *size) (size | errors::invalid) = { let res = 0z; let shift = 0z; for (true) { diff --git a/git/refs.ha b/git/refs.ha index a388a7f2b2b04457015d96d93d566229ccb39e0b..bbdb8731547d517d02ee0cf73ae9de33562cd3cb 100644 --- a/git/refs.ha +++ b/git/refs.ha @@ -5,7 +5,7 @@ use io; use strings; // Resolve a Git ref to its object ID from its fully qualified ref name. -export fn resolve_ref(r: repo, refname: const str) (oid | error) = { +export fn ref_resolve(r: repo, refname: const str) (oid | error) = { { match (fs::open(r.root, refname)) { case let fh: io::handle => @@ -20,7 +20,7 @@ yield len(b); }; let s = strings::fromutf8(b[..n])?; - return parse_oid(s)?; + return oid_parse(s)?; case let fe: fs::error => if (!(fe is errors::noentry)) { return fe; @@ -54,7 +54,7 @@ if (k == 64z && k + 1z < len(line)) { let name_b = line[k + 1z..]; if (bytes::equal(name_b, want)) { let hexs = strings::fromutf8(line[..k])?; - return parse_oid(hexs)?; + return oid_parse(hexs)?; }; }; }; @@ -78,7 +78,7 @@ }; }; // Reads and resolves the HEAD ref to its object ID. -export fn head_oid(r: repo) (oid | error) = { +export fn ref_resolve_head(r: repo) (oid | error) = { let fh = fs::open(r.root, "HEAD")?; defer io::close(fh)!; @@ -95,9 +95,9 @@ const pfx = strings::toutf8("ref: "); if (len(line) >= len(pfx) && bytes::hasprefix(line, pfx)) { let rn = strings::fromutf8(line[len(pfx)..])?; - return resolve_ref(r, rn); + return ref_resolve(r, rn); }; let s = strings::fromutf8(line)?; - return parse_oid(s)?; + return oid_parse(s)?; }; diff --git a/git/repo.ha b/git/repo.ha index 691aaba81b10b9e27e5612733a5a4e129c5348ca..ce72f06dc04b31b6a43cce269d401b910a27e9c1 100644 --- a/git/repo.ha +++ b/git/repo.ha @@ -7,13 +7,13 @@ root: *fs::fs, }; // Open a repository at the given path. -export fn open(path: const str) (repo | fs::error) = { +export fn repo_open(path: const str) (repo | fs::error) = { return repo { root = os::diropen(path)?, }; }; // Close a repository, freeing its resources. -export fn close(r: repo) void = { +export fn repo_close(r: repo) void = { fs::close(r.root); }; diff --git a/git/walk.ha b/git/walk.ha index 1e58ce562ce77b15f5b71402b73c073b47a9a3a3..c448445adadf647ef9a3ea505aad9a4ac77b8308 100644 --- a/git/walk.ha +++ b/git/walk.ha @@ -6,7 +6,7 @@ // List recent commits starting from the given commit ID, following first // parents only. // TODO: Consider cases with merge commits. -export fn recent_commits(r: repo, start: oid, limit: int) +export fn walk_recent_commits(r: repo, start: oid, limit: int) ([]commit | error) = { if (limit <= 0) { let empty: []commit = []; @@ -17,7 +17,7 @@ let out: []commit = []; let cur = start; for (let n = 0; n < limit; n += 1) { - match (read_object(r, cur)) { + match (object_read(r, cur)) { case let c: commit => append(out, c)!; if (len(c.parents) == 0) { -- 2.48.1