authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-25 21:40:54 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-25 21:40:54 -07:00
log905b67e572b68bc9358ef3fbcb17a022701315c1
treeb04386b0991cd3f312f42a05cbfd748e4f73164c
parent12685a4cfdc92dc8e660952339373af15ecf2f07
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

read names from mailmap too


1 files changed, 11 insertions(+), 2 deletions(-)

git.zig+11-2
......@@ -157,7 +157,7 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa
157157 return std.mem.trimEnd(u8, result.stdout, "\n");
158158}
159159
160pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string, mailmap: *const std.hash_map.StringHashMapUnmanaged([]const u8)) !Commit {
160pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string, mailmap: *const std.hash_map.StringHashMapUnmanaged([]const u8), mailmap_names: *const std.hash_map.StringHashMapUnmanaged([]const u8)) !Commit {
161161 const t = tracer.trace(@src(), "", .{});
162162 defer t.end();
163163
......@@ -185,7 +185,9 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string, mailmap: *const
185185 }
186186 result.parents = try parents.toOwnedSlice();
187187 result.author.email = mailmap.get(result.author.email) orelse result.author.email;
188 result.author.name = mailmap_names.get(result.author.email) orelse result.author.name;
188189 result.committer.email = mailmap.get(result.committer.email) orelse result.committer.email;
190 result.committer.name = mailmap_names.get(result.committer.email) orelse result.committer.name;
189191 result.message = iter.rest();
190192 return result;
191193}
......@@ -715,6 +717,7 @@ pub const Repository = struct {
715717 trees: std.StringArrayHashMapUnmanaged(Tree),
716718 tags: std.StringArrayHashMapUnmanaged(Tag),
717719 mailmap: std.hash_map.StringHashMapUnmanaged([]const u8),
720 mailmap_names: std.hash_map.StringHashMapUnmanaged([]const u8),
718721
719722 pub const CacheBehavior = enum { no_cache, cache };
720723
......@@ -730,6 +733,7 @@ pub const Repository = struct {
730733 .trees = .empty,
731734 .tags = .empty,
732735 .mailmap = .empty,
736 .mailmap_names = .empty,
733737 };
734738 }
735739
......@@ -749,6 +753,7 @@ pub const Repository = struct {
749753 r.trees.deinit(r.gpa);
750754 r.tags.deinit(r.gpa);
751755 r.mailmap.deinit(r.gpa);
756 r.mailmap_names.deinit(r.gpa);
752757 }
753758
754759 pub fn initMailmap(r: *Repository) !void {
......@@ -760,16 +765,19 @@ pub const Repository = struct {
760765 const mailmap_content = try r.getBlobA(blob.id.blob.id, .cache);
761766
762767 var mailmap: std.hash_map.StringHashMapUnmanaged([]const u8) = .empty;
768 var mailmap_names: std.hash_map.StringHashMapUnmanaged([]const u8) = .empty;
763769 if (mailmap_content.len > 0) {
764770 var iter = std.mem.splitScalar(u8, mailmap_content, '\n');
765771 while (iter.next()) |line| {
766772 if (std.mem.startsWith(u8, line, "#")) continue;
767773 var jter = std.mem.splitScalar(u8, line, '<');
774 const name = std.mem.trim(u8, jter.next().?, " ");
768775 var first: ?[]const u8 = null;
769776 while (jter.next()) |fntry| {
770777 const email = fntry[0 .. std.mem.indexOfScalar(u8, fntry, '>') orelse continue];
771778 if (first == null) {
772779 first = email;
780 try mailmap_names.put(r.gpa, email, name);
773781 continue;
774782 }
775783 try mailmap.put(r.gpa, email, first.?);
......@@ -777,6 +785,7 @@ pub const Repository = struct {
777785 }
778786 }
779787 r.mailmap = mailmap;
788 r.mailmap_names = mailmap_names;
780789 }
781790
782791 pub fn getObject(r: *Repository, oid: Id, cache_behavior: CacheBehavior) anyerror!?GitObject {
......@@ -1095,7 +1104,7 @@ pub const Repository = struct {
10951104 if (try r.getObject(id.id, cache_behavior)) |obj| {
10961105 if (obj.type == .commit) {
10971106 errdefer if (cache_behavior == .no_cache) r.gpa.free(obj.content);
1098 const commit = try parseCommit(r.gpa, obj.content, &r.mailmap);
1107 const commit = try parseCommit(r.gpa, obj.content, &r.mailmap, &r.mailmap_names);
10991108 try r.commits.put(r.gpa, id.id, commit);
11001109 return .{ id, commit };
11011110 }