From 069a8d0b5dc3a40bbc676bdbac2935ce9ed7d91b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 12 Sep 2025 23:59:24 -0700 Subject: [PATCH] patch: make Header struct use one-based line indexing by default (#21995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What does this PR do? - Change Header struct start fields to default to 1 instead of 0 - Rename Header.zeroes to Header.empty with proper initialization - Maintain @max(1, ...) validation in parsing to ensure one-based indexing - Preserve compatibility with existing patch file formats 🤖 Generated with [Claude Code](https://claude.ai/code) ### How did you verify your code works? Co-authored-by: Claude Bot Co-authored-by: Claude Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com> --- src/patch.zig | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/patch.zig b/src/patch.zig index c3cd5bd347..2143a8b4f8 100644 --- a/src/patch.zig +++ b/src/patch.zig @@ -417,15 +417,18 @@ pub const Hunk = struct { pub const Header = struct { original: struct { - start: u32, + start: u32 = 1, len: u32, }, patched: struct { - start: u32, + start: u32 = 1, len: u32, }, - pub const zeroes = std.mem.zeroes(Header); + pub const empty = Header{ + .original = .{ .start = 1, .len = 0 }, + .patched = .{ .start = 1, .len = 0 }, + }; }; pub fn deinit(this: *Hunk, allocator: Allocator) void { @@ -610,7 +613,7 @@ fn patchFileSecondPass(files: []FileDeets) ParseErr!PatchFile { .hunk = if (file.hunks.items.len > 0) brk: { const value = file.hunks.items[0]; file.hunks.items[0] = .{ - .header = Hunk.Header.zeroes, + .header = Hunk.Header.empty, }; break :brk bun.new(Hunk, value); } else null, @@ -631,7 +634,7 @@ fn patchFileSecondPass(files: []FileDeets) ParseErr!PatchFile { .hunk = if (file.hunks.items.len > 0) brk: { const value = file.hunks.items[0]; file.hunks.items[0] = .{ - .header = Hunk.Header.zeroes, + .header = Hunk.Header.empty, }; break :brk bun.new(Hunk, value); } else null,