patch: make Header struct use one-based line indexing by default (#21995)

### 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 <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2025-09-12 23:59:24 -07:00
committed by GitHub
parent 9907c2e9fa
commit 069a8d0b5d

View File

@@ -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,