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