| ... | @@ -3,6 +3,9 @@ const string = []const u8; | ... | @@ -3,6 +3,9 @@ const string = []const u8; |
| 3 | | 3 | |
| 4 | // 40 is length of sha1 hash | 4 | // 40 is length of sha1 hash |
| 5 | pub const Id = *const [40]u8; | 5 | pub const Id = *const [40]u8; |
| | 6 | pub const TreeId = struct { id: Id }; |
| | 7 | pub const CommitId = struct { id: Id }; |
| | 8 | pub const BlobId = struct { id: Id }; |
| 6 | | 9 | |
| 7 | /// Returns the result of running `git rev-parse HEAD` | 10 | /// Returns the result of running `git rev-parse HEAD` |
| 8 | /// dir must already be pointing at the .git folder | 11 | /// dir must already be pointing at the .git folder |
| ... | @@ -35,7 +38,7 @@ pub fn getObject(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !string { | ... | @@ -35,7 +38,7 @@ pub fn getObject(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !string { |
| 35 | pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { | 38 | pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { |
| 36 | var iter = std.mem.split(u8, commitfile, "\n"); | 39 | var iter = std.mem.split(u8, commitfile, "\n"); |
| 37 | var result: Commit = undefined; | 40 | var result: Commit = undefined; |
| 38 | var parents = std.ArrayList(Id).init(alloc); | 41 | var parents = std.ArrayList(CommitId).init(alloc); |
| 39 | errdefer parents.deinit(); | 42 | errdefer parents.deinit(); |
| 40 | while (true) { | 43 | while (true) { |
| 41 | const line = iter.next().?; | 44 | const line = iter.next().?; |
| ... | @@ -43,10 +46,10 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { | ... | @@ -43,10 +46,10 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { |
| 43 | const space = std.mem.indexOfScalar(u8, line, ' ').?; | 46 | const space = std.mem.indexOfScalar(u8, line, ' ').?; |
| 44 | const k = line[0..space]; | 47 | const k = line[0..space]; |
| 45 | | 48 | |
| 46 | if (std.mem.eql(u8, k, "tree")) result.tree = line[space + 1 ..][0..40]; | 49 | if (std.mem.eql(u8, k, "tree")) result.tree = .{ .id = line[space + 1 ..][0..40] }; |
| 47 | if (std.mem.eql(u8, k, "author")) result.author = line[space + 1 ..]; | 50 | if (std.mem.eql(u8, k, "author")) result.author = line[space + 1 ..]; |
| 48 | if (std.mem.eql(u8, k, "committer")) result.committer = line[space + 1 ..]; | 51 | if (std.mem.eql(u8, k, "committer")) result.committer = line[space + 1 ..]; |
| 49 | if (std.mem.eql(u8, k, "parent")) try parents.append(line[space + 1 ..][0..40]); | 52 | if (std.mem.eql(u8, k, "parent")) try parents.append(.{ .id = line[space + 1 ..][0..40] }); |
| 50 | } | 53 | } |
| 51 | result.parents = try parents.toOwnedSlice(); | 54 | result.parents = try parents.toOwnedSlice(); |
| 52 | result.message = iter.rest(); | 55 | result.message = iter.rest(); |
| ... | @@ -54,8 +57,8 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { | ... | @@ -54,8 +57,8 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit { |
| 54 | } | 57 | } |
| 55 | | 58 | |
| 56 | pub const Commit = struct { | 59 | pub const Commit = struct { |
| 57 | tree: Id, | 60 | tree: TreeId, |
| 58 | parents: []const Id, | 61 | parents: []const CommitId, |
| 59 | author: string, | 62 | author: string, |
| 60 | committer: string, | 63 | committer: string, |
| 61 | gpgsig: string, | 64 | gpgsig: string, |