| ... | ... | @@ -157,7 +157,7 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa |
| 157 | 157 | return std.mem.trimEnd(u8, result.stdout, "\n"); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | | pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string, mailmap: *const std.hash_map.StringHashMapUnmanaged([]const u8)) !Commit { |
| 160 | pub 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 { |
| 161 | 161 | const t = tracer.trace(@src(), "", .{}); |
| 162 | 162 | defer t.end(); |
| 163 | 163 | |
| ... | ... | @@ -185,7 +185,9 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string, mailmap: *const |
| 185 | 185 | } |
| 186 | 186 | result.parents = try parents.toOwnedSlice(); |
| 187 | 187 | 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; |
| 188 | 189 | 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; |
| 189 | 191 | result.message = iter.rest(); |
| 190 | 192 | return result; |
| 191 | 193 | } |
| ... | ... | @@ -715,6 +717,7 @@ pub const Repository = struct { |
| 715 | 717 | trees: std.StringArrayHashMapUnmanaged(Tree), |
| 716 | 718 | tags: std.StringArrayHashMapUnmanaged(Tag), |
| 717 | 719 | mailmap: std.hash_map.StringHashMapUnmanaged([]const u8), |
| 720 | mailmap_names: std.hash_map.StringHashMapUnmanaged([]const u8), |
| 718 | 721 | |
| 719 | 722 | pub const CacheBehavior = enum { no_cache, cache }; |
| 720 | 723 | |
| ... | ... | @@ -730,6 +733,7 @@ pub const Repository = struct { |
| 730 | 733 | .trees = .empty, |
| 731 | 734 | .tags = .empty, |
| 732 | 735 | .mailmap = .empty, |
| 736 | .mailmap_names = .empty, |
| 733 | 737 | }; |
| 734 | 738 | } |
| 735 | 739 | |
| ... | ... | @@ -749,6 +753,7 @@ pub const Repository = struct { |
| 749 | 753 | r.trees.deinit(r.gpa); |
| 750 | 754 | r.tags.deinit(r.gpa); |
| 751 | 755 | r.mailmap.deinit(r.gpa); |
| 756 | r.mailmap_names.deinit(r.gpa); |
| 752 | 757 | } |
| 753 | 758 | |
| 754 | 759 | pub fn initMailmap(r: *Repository) !void { |
| ... | ... | @@ -760,16 +765,19 @@ pub const Repository = struct { |
| 760 | 765 | const mailmap_content = try r.getBlobA(blob.id.blob.id, .cache); |
| 761 | 766 | |
| 762 | 767 | var mailmap: std.hash_map.StringHashMapUnmanaged([]const u8) = .empty; |
| 768 | var mailmap_names: std.hash_map.StringHashMapUnmanaged([]const u8) = .empty; |
| 763 | 769 | if (mailmap_content.len > 0) { |
| 764 | 770 | var iter = std.mem.splitScalar(u8, mailmap_content, '\n'); |
| 765 | 771 | while (iter.next()) |line| { |
| 766 | 772 | if (std.mem.startsWith(u8, line, "#")) continue; |
| 767 | 773 | var jter = std.mem.splitScalar(u8, line, '<'); |
| 774 | const name = std.mem.trim(u8, jter.next().?, " "); |
| 768 | 775 | var first: ?[]const u8 = null; |
| 769 | 776 | while (jter.next()) |fntry| { |
| 770 | 777 | const email = fntry[0 .. std.mem.indexOfScalar(u8, fntry, '>') orelse continue]; |
| 771 | 778 | if (first == null) { |
| 772 | 779 | first = email; |
| 780 | try mailmap_names.put(r.gpa, email, name); |
| 773 | 781 | continue; |
| 774 | 782 | } |
| 775 | 783 | try mailmap.put(r.gpa, email, first.?); |
| ... | ... | @@ -777,6 +785,7 @@ pub const Repository = struct { |
| 777 | 785 | } |
| 778 | 786 | } |
| 779 | 787 | r.mailmap = mailmap; |
| 788 | r.mailmap_names = mailmap_names; |
| 780 | 789 | } |
| 781 | 790 | |
| 782 | 791 | pub fn getObject(r: *Repository, oid: Id, cache_behavior: CacheBehavior) anyerror!?GitObject { |
| ... | ... | @@ -1095,7 +1104,7 @@ pub const Repository = struct { |
| 1095 | 1104 | if (try r.getObject(id.id, cache_behavior)) |obj| { |
| 1096 | 1105 | if (obj.type == .commit) { |
| 1097 | 1106 | 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); |
| 1099 | 1108 | try r.commits.put(r.gpa, id.id, commit); |
| 1100 | 1109 | return .{ id, commit }; |
| 1101 | 1110 | } |