tiny.smg.git
Defined in tiny.smg.
API (3)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
Source: tools/smg/src/git.zig
zig
const std = @import("std");pub const Output = struct { ok: bool, stdout: []const u8, stderr: []const u8,};pub fn run(allocator: std.mem.Allocator, root: []const u8, argv: []const []const u8, limit: usize) !Output { var io_state = std.Io.Threaded.init(allocator, .{}); defer io_state.deinit(); const result = std.process.run(allocator, io_state.io(), .{ .argv = argv, .cwd = .{ .path = root }, .expand_arg0 = .expand, .stdout_limit = .limited(limit), .stderr_limit = .limited(limit), }) catch return .{ .ok = false, .stdout = "", .stderr = "" }; return .{ .ok = switch (result.term) { .exited => |code| code == 0, else => false, }, .stdout = result.stdout, .stderr = result.stderr, };}pub fn refExists(allocator: std.mem.Allocator, root: []const u8, ref: []const u8) !bool { const commit_ref = try std.fmt.allocPrint(allocator, "{s}^{{commit}}", .{ref}); const output = try run(allocator, root, &.{ "git", "rev-parse", "--verify", "--quiet", commit_ref }, 1024 * 1024); return output.ok;}test "run captures successful command output" { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); const output = try run(arena.allocator(), ".", &.{ "git", "--version" }, 1024); try std.testing.expect(output.ok); try std.testing.expect(std.mem.startsWith(u8, output.stdout, "git version"));}test "run reports process launch failure as not ok" { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); const output = try run(arena.allocator(), ".", &.{"smg-definitely-missing-command"}, 1024); try std.testing.expect(!output.ok); try std.testing.expectEqualStrings("", output.stdout); try std.testing.expectEqualStrings("", output.stderr);}Source: tools/smg/src/root.zig:22
zig
pub const git = @import("git.zig");Complete caller list for git.run
10 direct callers.
tiny.smg.blame.entity[function] attools/smg/src/blame.zig:20tiny.smg.churn.compute[function] attools/smg/src/churn.zig:44tools.smg.src.churn.expectGit[function] — private; no exact target attools/smg/src/churn.zig:309in nearest public ownertiny.smg.churntools.smg.src.command.scan.changed.test_changed_files_include_both_sides_of_a_source_rename[function] — test; no exact target attools/smg/src/command/scan/changed.zig:136in nearest public ownertiny.smg.command.scan.changedtools.smg.src.command.scan.changed.test_changed_files_preserve_a_deleted_source_tombstone[function] — test; no exact target attools/smg/src/command/scan/changed.zig:110in nearest public ownertiny.smg.command.scan.changedtiny.smg.diff.loadGraphFromGit[function] attools/smg/src/diff.zig:242tools.smg.src.diff.test_loadGraphFromGit_scans_committed_source_ref[function] — test; no exact target attools/smg/src/diff.zig:263in nearest public ownertiny.smg.difftiny.smg.git.refExists[function] attools/smg/src/git.zig:29tools.smg.src.git.test_run_captures_successful_command_output[function] — test; no exact target attools/smg/src/git.zig:35in nearest public ownertiny.smg.gittools.smg.src.git.test_run_reports_process_launch_failure_as_not_ok[function] — test; no exact target attools/smg/src/git.zig:43in nearest public ownertiny.smg.git
Audit
| Definitions | 4 |
|---|---|
| Public names | 4 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |