authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 19:30:31 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 19:30:31 -07:00
logb291df3aa42c279eb53dbdefb0f1026948d92368
tree1c2f24e6075591e2c7fd14c3933a3f65653bd792
parenta542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e

add tracer calls


2 files changed, 51 insertions(+), 0 deletions(-)

git.zig+50
......@@ -3,6 +3,7 @@ const string = []const u8;
33const top = @This();
44const time = @import("time");
55const extras = @import("extras");
6const tracer = @import("tracer");
67
78// 40 is length of sha1 hash
89pub const Id = *const [40]u8;
......@@ -27,6 +28,9 @@ pub fn version(alloc: std.mem.Allocator) !string {
2728/// dir must already be pointing at the .git folder
2829// TODO this doesnt handle when there are 0 commits
2930pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !?CommitId {
31 const t = tracer.trace(@src());
32 defer t.end();
33
3034 const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n");
3135
3236 if (std.mem.startsWith(u8, h, "ref:")) {
......@@ -70,6 +74,9 @@ fn ensureObjId(comptime T: type, input: string) T {
7074// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
7175// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
7276pub fn getObject(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !string {
77 const t = tracer.trace(@src());
78 defer t.end();
79
7380 const result = try std.ChildProcess.exec(.{
7481 .allocator = alloc,
7582 .cwd_dir = dir,
......@@ -85,6 +92,9 @@ pub fn getObject(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !string {
8592// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
8693// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
8794pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {
95 const t = tracer.trace(@src());
96 defer t.end();
97
8898 const result = try std.ChildProcess.exec(.{
8999 .allocator = alloc,
90100 .cwd_dir = dir,
......@@ -98,6 +108,9 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !u64 {
98108// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
99109// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
100110pub fn isType(alloc: std.mem.Allocator, dir: std.fs.Dir, maybeobj: Id, typ: Tree.Object.Id.Tag) !?bool {
111 const t = tracer.trace(@src());
112 defer t.end();
113
101114 const result = try std.ChildProcess.exec(.{
102115 .allocator = alloc,
103116 .cwd_dir = dir,
......@@ -112,6 +125,9 @@ pub fn isType(alloc: std.mem.Allocator, dir: std.fs.Dir, maybeobj: Id, typ: Tree
112125// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
113126// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
114127pub fn getType(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !Tree.Object.Id.Tag {
128 const t = tracer.trace(@src());
129 defer t.end();
130
115131 const result = try std.ChildProcess.exec(.{
116132 .allocator = alloc,
117133 .cwd_dir = dir,
......@@ -128,6 +144,9 @@ pub fn getType(alloc: std.mem.Allocator, dir: std.fs.Dir, obj: Id) !Tree.Object.
128144// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
129145// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
130146pub fn revList(alloc: std.mem.Allocator, dir: std.fs.Dir, comptime count: u31, from: CommitId, sub_path: string) !string {
147 const t = tracer.trace(@src());
148 defer t.end();
149
131150 const result = try std.ChildProcess.exec(.{
132151 .allocator = alloc,
133152 .cwd_dir = dir,
......@@ -145,6 +164,9 @@ pub fn revList(alloc: std.mem.Allocator, dir: std.fs.Dir, comptime count: u31, f
145164}
146165
147166pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit {
167 const t = tracer.trace(@src());
168 defer t.end();
169
148170 var iter = std.mem.split(u8, commitfile, "\n");
149171 var result: Commit = undefined;
150172 var parents = std.ArrayList(CommitId).init(alloc);
......@@ -166,6 +188,9 @@ pub fn parseCommit(alloc: std.mem.Allocator, commitfile: string) !Commit {
166188}
167189
168190fn parseCommitUserAndAt(input: string) !Commit.UserAndAt {
191 const t = tracer.trace(@src());
192 defer t.end();
193
169194 // Mitchell Hashimoto <mitchell.hashimoto@gmail.com> 1680797363 -0700
170195 // first and second part is https://datatracker.ietf.org/doc/html/rfc5322#section-3.4
171196 // third part is unix epoch timestamp
......@@ -218,6 +243,9 @@ pub const Commit = struct {
218243};
219244
220245pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {
246 const t = tracer.trace(@src());
247 defer t.end();
248
221249 var iter = std.mem.split(u8, treefile, "\n");
222250 var children = std.ArrayList(Tree.Object).init(alloc);
223251 errdefer children.deinit();
......@@ -249,6 +277,9 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {
249277}
250278
251279fn parseTreeMode(input: string) !Tree.Object.Mode {
280 const t = tracer.trace(@src());
281 defer t.end();
282
252283 std.debug.assert(input.len == 6);
253284 return .{
254285 .type = @enumFromInt(try std.fmt.parseInt(u16, input[0..3], 10)),
......@@ -354,6 +385,9 @@ pub const Tree = struct {
354385// TODO make this inspect .git manually
355386// TODO make this return a Reader when we implement it ourselves
356387pub fn getTreeDiff(alloc: std.mem.Allocator, dir: std.fs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
388 const t = tracer.trace(@src());
389 defer t.end();
390
357391 if (parentid == null) {
358392 const result = try std.ChildProcess.exec(.{
359393 .allocator = alloc,
......@@ -377,6 +411,9 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: std.fs.Dir, commitid: CommitId
377411}
378412
379413pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta {
414 const t = tracer.trace(@src());
415 defer t.end();
416
380417 var result = std.mem.zeroes(TreeDiffMeta);
381418 var lineiter = std.mem.split(u8, input, "\n");
382419
......@@ -448,6 +485,9 @@ pub const TreeDiffMeta = struct {
448485};
449486
450487pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
488 const t = tracer.trace(@src());
489 defer t.end();
490
451491 var lineiter = std.mem.split(u8, input, "\n");
452492 var overview = std.ArrayList(TreeDiff.StateLine).init(alloc);
453493 var diffs = std.ArrayList(TreeDiff.Diff).init(alloc);
......@@ -604,6 +644,9 @@ pub const TreeDiff = struct {
604644};
605645
606646pub fn getBranches(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const Ref {
647 const t = tracer.trace(@src());
648 defer t.end();
649
607650 const result = try std.ChildProcess.exec(.{
608651 .allocator = alloc,
609652 .cwd_dir = dir,
......@@ -627,6 +670,13 @@ pub fn getBranches(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const Ref {
627670}
628671
629672pub fn getTags(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const Ref {
673 const t = tracer.trace(@src());
674 defer t.end();
675
676 // 97bc4b5f87656a34139e1a8122866c8c5b432598 refs/tags/1.2.5
677 // a450a23e318c5a8fcba5a52c8fdc2e23584650b3 refs/tags/1.2.5^{}
678 // 71264720050572b7bad24532ff39951f47d9296a refs/tags/15.3.1
679 // 7dfd3948a9095f0253bfba60fed52895ffbf84bb refs/tags/15.3.2
630680 const result = try std.ChildProcess.exec(.{
631681 .allocator = alloc,
632682 .cwd_dir = dir,
zig.mod+1
......@@ -6,3 +6,4 @@ description: Inspect into the depths of your .git folder purely from Zig
66dependencies:
77 - src: git https://github.com/nektro/zig-time
88 - src: git https://github.com/nektro/zig-extras
9 - src: git https://github.com/nektro/zig-tracer