authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-11 23:28:59 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-11 23:28:59 -07:00
log0d3672c5140a76b4dfdffdf7c72f37f7218bee51
treeaaccc1f51a6636a82e3e94b58985bc8d85022545
parentbd5f11314b2bb5cb61779e164f1525b5fc8107d9
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

rename obj -> oid


1 files changed, 24 insertions(+), 24 deletions(-)

git.zig+24-24
......@@ -126,14 +126,14 @@ pub fn ensureObjId(comptime T: type, input: string) T {
126126// TODO make this return a Reader when we implement it ourselves
127127// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
128128// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
129pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !string {
130 const t = tracer.trace(@src(), " {s}", .{obj});
129pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !string {
130 const t = tracer.trace(@src(), " {s}", .{oid});
131131 defer t.end();
132132
133133 const result = try std.process.Child.run(.{
134134 .allocator = alloc,
135135 .cwd_dir = dir.to_std(),
136 .argv = &.{ "git", "cat-file", "-p", obj },
136 .argv = &.{ "git", "cat-file", "-p", oid },
137137 .max_output_bytes = 1024 * 1024 * 1024,
138138 });
139139 extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr});
......@@ -143,14 +143,14 @@ pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !string
143143// TODO make this inspect .git/objects manually
144144// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
145145// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
146pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 {
147 const t = tracer.trace(@src(), " {s}", .{obj});
146pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !u64 {
147 const t = tracer.trace(@src(), " {s}", .{oid});
148148 defer t.end();
149149
150150 const result = try std.process.Child.run(.{
151151 .allocator = alloc,
152152 .cwd_dir = dir.to_std(),
153 .argv = &.{ "git", "cat-file", "-s", obj },
153 .argv = &.{ "git", "cat-file", "-s", oid },
154154 });
155155 extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr});
156156 return try extras.parseDigits(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10);
......@@ -159,14 +159,14 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 {
159159// TODO make this inspect .git manually
160160// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
161161// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
162pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType) !bool {
163 const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeobj, @tagName(typ) });
162pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeoid: Id, typ: RefType) !bool {
163 const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeoid, @tagName(typ) });
164164 defer t.end();
165165
166166 const result = try std.process.Child.run(.{
167167 .allocator = alloc,
168168 .cwd_dir = dir.to_std(),
169 .argv = &.{ "git", "cat-file", "-t", maybeobj },
169 .argv = &.{ "git", "cat-file", "-t", maybeoid },
170170 });
171171 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
172172 const output = std.mem.trimRight(u8, result.stdout, "\n");
......@@ -176,14 +176,14 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType
176176// TODO make this inspect .git manually
177177// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
178178// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
179pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !RefType {
180 const t = tracer.trace(@src(), " {s}", .{obj});
179pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !RefType {
180 const t = tracer.trace(@src(), " {s}", .{oid});
181181 defer t.end();
182182
183183 const result = try std.process.Child.run(.{
184184 .allocator = alloc,
185185 .cwd_dir = dir.to_std(),
186 .argv = &.{ "git", "cat-file", "-t", obj },
186 .argv = &.{ "git", "cat-file", "-t", oid },
187187 });
188188 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
189189 const output = std.mem.trimRight(u8, result.stdout, "\n");
......@@ -1010,14 +1010,14 @@ pub const Repository = struct {
10101010 r.tags.deinit(r.gpa);
10111011 }
10121012
1013 fn getObject(r: *Repository, obj: Id, arena: std.mem.Allocator) !?RawObject {
1014 if (r.raw_object_contents.get(obj)) |data| {
1013 fn getObject(r: *Repository, oid: Id, arena: std.mem.Allocator) !?RawObject {
1014 if (r.raw_object_contents.get(oid)) |data| {
10151015 return data;
10161016 }
1017 if (obj.len == 40) blk: { //sha1 object
1017 if (oid.len == 40) blk: { //sha1 object
10181018 var sub_path: [49:0]u8 = "objects/00/00000000000000000000000000000000000000".*;
1019 @memcpy(sub_path[8..][0..2], obj[0..2]);
1020 @memcpy(sub_path[11..], obj[2..]);
1019 @memcpy(sub_path[8..][0..2], oid[0..2]);
1020 @memcpy(sub_path[11..], oid[2..]);
10211021 const objfile = r.gitdir.openFile(&sub_path, .{}) catch |err| switch (err) {
10221022 error.ENOENT => break :blk,
10231023 else => |e| return e,
......@@ -1036,7 +1036,7 @@ pub const Repository = struct {
10361036 list.replaceRangeAssumeCapacity(0, header.len + 1, "");
10371037 const content = try list.toOwnedSlice();
10381038 std.debug.assert(content.len == content_len);
1039 try r.raw_object_contents.put(r.gpa, obj, .{ _type, content });
1039 try r.raw_object_contents.put(r.gpa, oid, .{ _type, content });
10401040 return .{ _type, content };
10411041 }
10421042
......@@ -1072,7 +1072,7 @@ pub const Repository = struct {
10721072 for (0..object_count) |i| {
10731073 const object_id = &extras.to_hex(name_bytes[i * 20 ..][0..20].*);
10741074 const pack_offset = std.mem.readInt(u32, offset_bytes[i * 4 ..][0..4], .big);
1075 if (std.mem.eql(u8, object_id, obj)) {
1075 if (std.mem.eql(u8, object_id, oid)) {
10761076 std.log.debug("found {s} in {s} at offset {d}", .{ obj, idx_path, pack_offset });
10771077 const pack_index = r.pack_content.getIndex(idx_path) orelse clk: {
10781078 var pack_path: [128]u8 = @splat(0);
......@@ -1098,10 +1098,10 @@ pub const Repository = struct {
10981098 // parse .pack
10991099 std.log.warn("pack_index={d} pack_offset={d}", .{ pack_index, pack_offset });
11001100
1101 return try r.getPackedObject(obj, pack_index, pack_offset);
1101 return try r.getPackedObject(oid, pack_index, pack_offset);
11021102 }
11031103
1104 fn getPackedObject(r: *Repository, maybe_obj: ?Id, pack_index: usize, pack_offset: usize) !RawObject {
1104 fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !RawObject {
11051105 const pack_content = r.pack_content.values()[pack_index];
11061106 if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack;
11071107 const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big);
......@@ -1140,7 +1140,7 @@ pub const Repository = struct {
11401140 try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer());
11411141 const _type = std.meta.stringToEnum(RefType, @tagName(ty)).?;
11421142 const content = try list.toOwnedSlice();
1143 if (maybe_obj) |obj| try r.raw_object_contents.put(r.gpa, obj, .{ _type, content });
1143 if (maybe_oid) |oid| try r.raw_object_contents.put(r.gpa, oid, .{ _type, content });
11441144 return .{ _type, content };
11451145 },
11461146 .ofs_delta => {
......@@ -1161,8 +1161,8 @@ pub const Repository = struct {
11611161 }
11621162 }
11631163
1164 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, obj: Id) !?GitObject {
1165 if (try r.getObject(obj, arena)) |data| {
1164 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject {
1165 if (try r.getObject(oid, arena)) |data| {
11661166 const _type, const content = data;
11671167 return .{ .type = _type, .content = content };
11681168 }