| ... | ... | @@ -712,6 +712,7 @@ pub const Repository = struct { |
| 712 | 712 | commits: std.StringArrayHashMapUnmanaged(Commit), |
| 713 | 713 | trees: std.StringArrayHashMapUnmanaged(Tree), |
| 714 | 714 | tags: std.StringArrayHashMapUnmanaged(Tag), |
| 715 | mailmap: std.hash_map.StringHashMapUnmanaged([]const u8), |
| 715 | 716 | |
| 716 | 717 | pub const CacheBehavior = enum { no_cache, cache }; |
| 717 | 718 | |
| ... | ... | @@ -726,6 +727,7 @@ pub const Repository = struct { |
| 726 | 727 | .commits = .empty, |
| 727 | 728 | .trees = .empty, |
| 728 | 729 | .tags = .empty, |
| 730 | .mailmap = .empty, |
| 729 | 731 | }; |
| 730 | 732 | } |
| 731 | 733 | |
| ... | ... | @@ -744,6 +746,35 @@ pub const Repository = struct { |
| 744 | 746 | for (r.trees.values()) |*v| r.gpa.free(v.children); |
| 745 | 747 | r.trees.deinit(r.gpa); |
| 746 | 748 | r.tags.deinit(r.gpa); |
| 749 | r.mailmap.deinit(r.gpa); |
| 750 | } |
| 751 | |
| 752 | pub fn initMailmap(r: *Repository) !void { |
| 753 | const headid = try getHEAD(r.gpa, r.gitdir) orelse return; |
| 754 | const head = try r.getCommitA(headid.id, .cache); |
| 755 | const tree = try r.getTreeA(head.tree.id, .cache); |
| 756 | const blob = tree.get(".mailmap") orelse return; |
| 757 | if (blob.id != .blob) return; |
| 758 | const mailmap_content = try r.getBlobA(blob.id.blob.id, .cache); |
| 759 | |
| 760 | var mailmap: std.hash_map.StringHashMapUnmanaged([]const u8) = .empty; |
| 761 | if (mailmap_content.len > 0) { |
| 762 | var iter = std.mem.splitScalar(u8, mailmap_content, '\n'); |
| 763 | while (iter.next()) |line| { |
| 764 | if (std.mem.startsWith(u8, line, "#")) continue; |
| 765 | var jter = std.mem.splitScalar(u8, line, '<'); |
| 766 | var first: ?[]const u8 = null; |
| 767 | while (jter.next()) |fntry| { |
| 768 | const email = fntry[0 .. std.mem.indexOfScalar(u8, fntry, '>') orelse continue]; |
| 769 | if (first == null) { |
| 770 | first = email; |
| 771 | continue; |
| 772 | } |
| 773 | try mailmap.put(r.gpa, email, first.?); |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | r.mailmap = mailmap; |
| 747 | 778 | } |
| 748 | 779 | |
| 749 | 780 | pub fn getObject(r: *Repository, oid: Id, cache_behavior: CacheBehavior) anyerror!?GitObject { |