From 5698bc4d1af0ed8286189295288fb144e27db325 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 21 Sep 2025 03:15:38 +0800 Subject: [PATCH] Stop using _is gihg --- git/ident.ha | 9 +++++---- git/loose.ha | 9 +++++---- git/obj_commit.ha | 7 ++++--- git/obj_tree.ha | 5 +++-- diff --git a/git/ident.ha b/git/ident.ha index f78923dbda599cc84543974676744c9a365ca362..74e9e48c80d802fbcec3389518c61ad3776710ef 100644 --- a/git/ident.ha +++ b/git/ident.ha @@ -1,5 +1,6 @@ use bytes; use errors; +use encoding::utf8; use strings; use strconv; @@ -21,7 +22,7 @@ // Parses an [[ident]] from its canonical byte-slice representation. fn parse_ident( line: []u8, -) (ident | errors::invalid | strconv::invalid | strconv::overflow | nomem) = { +) (ident | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let mlt = bytes::index(line, '<'); if (mlt is void) { return errors::invalid; @@ -51,7 +52,7 @@ return errors::invalid; }; let sp = msp: size; - const when_s = strings::fromutf8_unsafe(rest[..sp]); + const when_s = strings::fromutf8(rest[..sp])?; const tz_b = rest[sp + 1z..]; if (len(tz_b) < 5) { return errors::invalid; @@ -64,8 +65,8 @@ if (tz_b[0] == '-') { sign = -1; }; - const hh = strconv::stou32(strings::fromutf8_unsafe(tz_b[1..3]), strconv::base::DEC)?; - const mm = strconv::stou32(strings::fromutf8_unsafe(tz_b[3..5]), strconv::base::DEC)?; + const hh = strconv::stou32(strings::fromutf8(tz_b[1..3])?, strconv::base::DEC)?; + const mm = strconv::stou32(strings::fromutf8(tz_b[3..5])?, strconv::base::DEC)?; const mins: i32 = (hh: i32) * 60 + (mm: i32); const ofs: i32 = sign * mins; diff --git a/git/loose.ha b/git/loose.ha index 2573736e6923ff410e064acfbaaea9d0011a2b31..04640b338f8005fd15ed71e93466a034edd28510 100644 --- a/git/loose.ha +++ b/git/loose.ha @@ -7,6 +7,7 @@ use fs; use io; use strconv; use strings; +use encoding::utf8; // Find the path to a loose object with the given ID, // relative to the repository root. @@ -52,8 +53,8 @@ return errors::invalid; }; let sp = msp: size; - const ty = strings::fromutf8_unsafe(header[..sp]); - const szs = strings::fromutf8_unsafe(header[sp + 1z ..]); + const ty = strings::fromutf8(header[..sp])?; + const szs = strings::fromutf8(header[sp + 1z ..])?; const expect = strconv::stoz(szs)?; if (expect != len(body)) { @@ -114,8 +115,8 @@ return errors::invalid; }; let sp = msp: size; - const ty = strings::fromutf8_unsafe(header[..sp]); - const szs = strings::fromutf8_unsafe(header[sp + 1z ..]); + const ty = strings::fromutf8(header[..sp])?; + const szs = strings::fromutf8(header[sp + 1z ..])?; const expect = strconv::stoz(szs)?; if (expect != len(body)) { return errors::invalid; diff --git a/git/obj_commit.ha b/git/obj_commit.ha index 96ae1050cbd8c3306c7e846dc2e69d6d8cbc1487..15d59cf024bc0b244f1fc8f55fdecd6d3776a784 100644 --- a/git/obj_commit.ha +++ b/git/obj_commit.ha @@ -1,4 +1,5 @@ use bytes; +use encoding::utf8; use errors; use strconv; use strings; @@ -24,7 +25,7 @@ // Parses a commit from its raw data and object ID. export fn parse_commit( body: []u8, -) (commit | errors::invalid | strconv::invalid | strconv::overflow | nomem) = { +) (commit | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let c = commit { tree = [0...], parents = [], @@ -49,7 +50,7 @@ break; }; if (bytes::hasprefix(line, strings::toutf8("tree "))) { - const hex = strings::fromutf8_unsafe(line[5..]); + const hex = strings::fromutf8(line[5..])?; match (parse_oid(hex)) { case let o: oid => c.tree = o; @@ -59,7 +60,7 @@ case => return errors::invalid; }; } else if (bytes::hasprefix(line, strings::toutf8("parent "))) { - const hex = strings::fromutf8_unsafe(line[7..]); + const hex = strings::fromutf8(line[7..])?; match (parse_oid(hex)) { case let o: oid => append(c.parents, o)!; diff --git a/git/obj_tree.ha b/git/obj_tree.ha index df5b1b4f62966f7fe3b72cf3bf24370ab141523e..1532af0bd210b346e828623ed836c8845e419a6b 100644 --- a/git/obj_tree.ha +++ b/git/obj_tree.ha @@ -1,5 +1,6 @@ use bytes; use crypto::sha256; +use encoding::utf8; use errors; use fs; use io; @@ -33,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 | nomem) = { +export fn parse_tree(body: []u8) (tree | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem) = { let entries: []tree_entry = []; let i = 0z; @@ -57,7 +58,7 @@ let child: oid = [0...]; child[..] = body[i .. i+sha256::SZ]; i += sha256::SZ; - const mode_s = strings::fromutf8_unsafe(mode_b); + const mode_s = strings::fromutf8(mode_b)?; const mode = strconv::stou32(mode_s, strconv::base::OCT)?; const name = alloc(name_b...)?; -- 2.48.1