summaryrefslogtreecommitdiff
path: root/src/diff.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 10:56:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch)
treec344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /src/diff.zig
parentfc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff)
downloadpardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz
pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'src/diff.zig')
-rw-r--r--src/diff.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/diff.zig b/src/diff.zig
index ed54c149..659576d3 100644
--- a/src/diff.zig
+++ b/src/diff.zig
@@ -8,6 +8,21 @@
//! taken for a file header.
const std = @import("std");
+/// The commit named by git show, format-patch or jj show's leading header.
+pub fn commitHash(content: []const u8) ?[]const u8 {
+ const line = content[0 .. std.mem.indexOfScalar(u8, content, '\n') orelse content.len];
+ inline for (.{ "commit ", "From ", "Commit ID: " }) |prefix| {
+ if (std.mem.startsWith(u8, line, prefix)) {
+ var words = std.mem.tokenizeAny(u8, line[prefix.len..], " \t\r");
+ const hash = words.next() orelse return null;
+ if (hash.len < 7 or hash.len > 64) return null;
+ for (hash) |c| if (!std.ascii.isHex(c)) return null;
+ return hash;
+ }
+ }
+ return null;
+}
+
pub const Kind = enum {
/// Anything outside a file header and a hunk: a commit message,
/// `Only in ...`, a mail's headers.
@@ -653,3 +668,12 @@ test "diff a section's paths are the repository's names under every prefix git w
try testing.expectEqualStrings("/dev/null", made[0]);
try testing.expectEqualStrings("n.zig", made[1]);
}
+
+test "diff commit headers retain the full hash, not message or hunk text" {
+ const hash = "0123456789abcdef0123456789abcdef01234567";
+ try std.testing.expectEqualStrings(hash, commitHash("commit " ++ hash ++ " (HEAD -> main)\nmessage").?);
+ try std.testing.expectEqualStrings(hash, commitHash("From " ++ hash ++ " Mon Sep 17 00:00:00 2001\n").?);
+ try std.testing.expectEqualStrings(hash, commitHash("Commit ID: " ++ hash ++ "\nChange ID: xyz").?);
+ inline for (.{ "commit ", "commit nope123", "From 1234\n", "@@ -1 +1 @@\n+commit " ++ hash }) |text|
+ try std.testing.expectEqual(@as(?[]const u8, null), commitHash(text));
+}