Skip to content

Don't depend on git for patching files - #566

Open
JAicewizard wants to merge 1 commit into
cloudflare:masterfrom
JAicewizard:use_patch
Open

JAicewizard wants to merge 1 commit into
cloudflare:masterfrom
JAicewizard:use_patch

Conversation

@JAicewizard

Copy link
Copy Markdown
Contributor

Some build environments do have git, such as freebsd. All unix systems have patch as it is part of the unix standard, requirering no additional build tools.

@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).

@kornelski

Copy link
Copy Markdown
Contributor

This is generally a good idea, but the implementation is a chopped up salad of cfg(). Please refactor it into something like if cfg!(unix) { patch() } else { git() }

@JAicewizard

Copy link
Copy Markdown
Contributor Author

Yes I agree, I was wondering what your preference would be. Should I also put the canonicalize in the unix path?

@nox

nox commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@clanky-the-clanker review

Git remains preferred to preserve its existing whitespace handling. The standard patch utility is used when Git is unavailable, regardless of the host platform.

Backend selection occurs before source mutation, and the Git-specific environment cleanup remains in effect.
@nox

nox commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Refactored this to select the patch backend once before applying anything. It prefers git apply to preserve the existing --whitespace=fix behavior and falls back to patch when Git is unavailable, independent of the host OS. Git initialization and environment sanitization are only used by the Git backend, and both backends use equivalent -p1/-p2 strip levels.

The commits are squashed with the original author preserved. I also verified formatting, compilation, Clippy, and application of all shipped patches with patch.

@JAicewizard

Copy link
Copy Markdown
Contributor Author

Oh seems like I forgot to push, its been a busy week.

A dynamic selection process feels complicated, but if you find the behavior important it is necessary.

I will try building this pr on freebsd to verify it is working

@nox

nox commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

On Windows you can often have git without patch, patch.exe can be present but not in PATH, and MinGit strips it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants