mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user