From 2df84408c14190fb518e4e0fe31b6acd0422b002 Mon Sep 17 00:00:00 2001 From: Adrian Ho Date: Sat, 15 Feb 2025 20:15:53 +0800 Subject: [PATCH] formula: don't include DATA patches in initial Git repo Currently, existing DATA patches are subsumed into the initial Git repo created by `brew install --git`, which makes creating a new DATA patch after more fixes a tedious and error-prone process. This PR delays DATA patch processing till after the Git repo is created, so a `git diff` at the end creates a correct and consolidated DATA patch block ready for insertion/replacement, or even migration to a proper remote patch URL. The difference is clearly seen in `gromgit/fuse/dislocker-mac`, which has both remote and DATA patches. Before: ``` % brew install -sig dislocker-mac ==> Fetching gromgit/fuse/dislocker-mac ==> Downloading https://github.com/Aorimn/dislocker/commit/2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch?full_index=1 Already downloaded: /Volumes/aho/Library/Caches/Homebrew/downloads/37276859cbebc1711941278db00cd8b25b98d69e15e31e33915a98d01a13febc--2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch ==> Downloading https://github.com/Aorimn/dislocker/archive/refs/tags/v0.7.3.tar.gz Already downloaded: /Volumes/aho/Library/Caches/Homebrew/downloads/b1ba1098c95535574936051eca45cc472955a5a024b81cc72e1c3b006e1950b3--dislocker-0.7.3.tar.gz ==> Installing dislocker-mac from gromgit/fuse ==> Patching ==> Applying 2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch Initialized empty Git repository in /private/tmp/dislocker-mac-20250215-35534-8qlxtp/dislocker-0.7.3/.git/ ==> Entering interactive mode... Type `exit` to return and finalize the installation. Install to this prefix: /opt/homebrew/Cellar/dislocker-mac/0.7.3_2 This directory is now a Git repository. Make your changes and then use: git diff | pbcopy to copy the diff to the clipboard. % git diff ``` After: ``` % brew install -sig dislocker-mac ==> Fetching gromgit/fuse/dislocker-mac ==> Downloading https://github.com/Aorimn/dislocker/commit/2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch?full_index=1 Already downloaded: /Volumes/aho/Library/Caches/Homebrew/downloads/37276859cbebc1711941278db00cd8b25b98d69e15e31e33915a98d01a13febc--2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch ==> Downloading https://github.com/Aorimn/dislocker/archive/refs/tags/v0.7.3.tar.gz Already downloaded: /Volumes/aho/Library/Caches/Homebrew/downloads/b1ba1098c95535574936051eca45cc472955a5a024b81cc72e1c3b006e1950b3--dislocker-0.7.3.tar.gz ==> Installing dislocker-mac from gromgit/fuse ==> Applying non-DATA patches ==> Applying 2cfbba2c8cc07e529622ba134d0a6982815d2b30.patch Initialized empty Git repository in /private/tmp/dislocker-mac-20250215-32462-zh1akh/dislocker-0.7.3/.git/ ==> Applying DATA patches ==> Entering interactive mode... Type `exit` to return and finalize the installation. Install to this prefix: /opt/homebrew/Cellar/dislocker-mac/0.7.3_2 This directory is now a Git repository. Make your changes and then use: git diff | pbcopy to copy the diff to the clipboard. % git diff diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd854d2..9ab137d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,7 +92,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") # Don't use `-read_only_relocs' here as it seems to only work for 32 bits # binaries set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-bind_at_load") - set (FUSE_LIB osxfuse_i64) + set (FUSE_LIB fuse) else() # Useless warnings when used within Darwin set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion") diff --git a/src/dislocker-fuse.c b/src/dislocker-fuse.c index f93523f..3dd106c 100644 --- a/src/dislocker-fuse.c +++ b/src/dislocker-fuse.c @@ -33,11 +33,7 @@ -#ifdef __DARWIN -# include -#else -# include -#endif /* __DARWIN */ +#include /** NTFS virtual partition's name */ ``` --- Library/Homebrew/build.rb | 7 +++++-- Library/Homebrew/formula.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index ae869d5e08..f169e10179 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -148,12 +148,15 @@ class Build # https://github.com/Homebrew/homebrew-core/pull/87470 TZ: "UTC0", ) do - formula.patch - if args.git? + formula.selective_patch(is_data: false) system "git", "init" system "git", "add", "-A" + formula.selective_patch(is_data: true) + else + formula.patch end + if args.interactive? ohai "Entering interactive mode..." puts <<~EOS diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 1bfd73a0e2..9a024f9eb7 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1608,6 +1608,20 @@ class Formula patchlist.each(&:apply) end + sig { params(is_data: T::Boolean).void } + def selective_patch(is_data: false) + patches = patchlist.select { |p| p.is_a?(DATAPatch) == is_data } + return if patches.empty? + + patchtype = if is_data + "DATA" + else + "non-DATA" + end + ohai "Applying #{patchtype} patches" + patches.each(&:apply) + end + # Yields |self,staging| with current working directory set to the uncompressed tarball # where staging is a {Mktemp} staging context. sig(:final) {