Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchpatch: ignores file renames #32084

Open
domenkozar opened this issue Nov 26, 2017 · 29 comments
Open

fetchpatch: ignores file renames #32084

domenkozar opened this issue Nov 26, 2017 · 29 comments
Assignees
Labels
5. scope: tracked Issue (or PR) is linked back to a `5. scope: tracking` issue 6.topic: fetch 9.needs: upstream fix This PR needs upstream to change something

Comments

@domenkozar
Copy link
Member

If the patch renames a file, and contains:

rename from libraries/base/GHC/Event/Clock.hsc
rename to libraries/base/GHC/Clock.hsc

Then using patch -p1 < foobar.patch works as expected, while using fetchpatch no rename happens.

cc @vcunat @aszlig @copumpkin @fpletz @globin

@domenkozar
Copy link
Member Author

@nh2
Copy link
Contributor

nh2 commented Nov 26, 2017

Example:

diff --git a/libraries/base/GHC/Event/Clock.hsc b/libraries/base/GHC/Clock.hsc
similarity index 53%
rename from libraries/base/GHC/Event/Clock.hsc
rename to libraries/base/GHC/Clock.hsc
index 5dbdb674d31..6339dc0a52b 100644
--- a/libraries/base/GHC/Event/Clock.hsc
+++ b/libraries/base/GHC/Clock.hsc
@@ -1,17 +1,25 @@
 {-# LANGUAGE Trustworthy #-}
 {-# LANGUAGE NoImplicitPrelude #-}
...

If in this patch, you strip everything before the ---, then patch will not execute the rename.

In other words, it interprets the

rename from libraries/base/GHC/Event/Clock.hsc
rename to libraries/base/GHC/Clock.hsc

and potentially other stuff; fetchpatch stripping that off breaks it.

(I personally also thought that everything before --- was a comment and would be ignored for the purpose of applying the patch; turns out this is wrong.)

@dezgeg
Copy link
Contributor

dezgeg commented Nov 27, 2017

(I personally also thought that everything before --- was a comment and would be ignored for the purpose of applying the patch; turns out this is wrong.)

The rename lines (like index ...) are a Git extension to the patch format.

@aszlig
Copy link
Member

aszlig commented Nov 27, 2017

This should already be fixed upstream (twaugh/patchutils@14261ad), we just need to bump patchutils.

@dezgeg
Copy link
Contributor

dezgeg commented Nov 27, 2017

Last time that was attempted, those new git-specific lines caused most existing fetchpatch hashes to change.

@aszlig
Copy link
Member

aszlig commented Nov 27, 2017

@dezgeg: Okay, which is probably because of that very commit, because it left in other git-specific extensions. Regardless of that, I just checked to verify whether this is problem persists in 0.3.4 and even in master and it's still the case, because lsdiff is simply dropping renames because they're essentially non-existing hunks.

@aszlig
Copy link
Member

aszlig commented Nov 27, 2017

Okay, while trying to patch patchutils it turns out that fixing the renames is a bit more involved, because the way patchutils does its parsing it's not very easy to do lookahead. Another obstacle is what @dezgeg mentioned with the changed hashes.

So what we practically need is just to turn the patch into a form that is deterministic in its results, which patchutils only does to a certain extent, for example it doesn't sort the file names.

Maybe it makes sense to implement what we need for fetchpatch ourselves and not use patchutils?

@dezgeg
Copy link
Contributor

dezgeg commented Nov 28, 2017

Yeah, I suppose writing a custom implementation is the best. After all, I think all it is doing now is stripping out any comments from the .patch files.

@globin
Copy link
Member

globin commented Nov 28, 2017

We also use it to exclude files from patches and add prefixes/suffixes(?)

@aszlig
Copy link
Member

aszlig commented Nov 29, 2017

@globin: Sure, that's no problem once we have a parser that uses proper data structures for the patches. On the other hand, however I was thinking about writing such an implementation in Haskell and parser combinators, but that would increase the closure size of fetchpatch a lot and also probably won't work that well because we probably have fetchpatch in the dependency graph of GHC (haven't checked).

So I'd like to amend my comment in a way that it's still probably better to patch patchutils to use proper data structures instead of that painful getline-based state-all-over-the-place parser that it's currently using and also add options to it for our main use case, which is bringing the patch into a form which deterministic in its output.

edit: Rewriting the parser of patchutils also has the advantage that the project already has a comprehensive test suite, which should make it a bit easier to implement.

@orivej
Copy link
Contributor

orivej commented Nov 29, 2017

I consider updating patchutils and automatically recomputing all fetchpatch hashes.

@aszlig
Copy link
Member

aszlig commented Nov 29, 2017

@orivej: Just updating patchutils won't be enough, as mentioned previously because it won't handle file renames.

@stale
Copy link

stale bot commented Jun 5, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 5, 2020
@arapov
Copy link
Contributor

arapov commented Nov 14, 2020

I hit this issue today. It would be nice to document this behaviour somehow .... I replaced fetchpatch() with fetchurl() and it did the trick for me.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 14, 2020
@jtojnar
Copy link
Member

jtojnar commented Nov 14, 2020

@arapov Using fetchurl for dynamically generated patches (e.g. those from GitHub) is not safe since the file can change in the future. You might be better just inlining the patch into the source tree (or re-adding the renames in fetchpatch’s postFetch attribute).

@arapov
Copy link
Contributor

arapov commented Nov 14, 2020

@arapov Using fetchurl for dynamically generated patches (e.g. those from GitHub) is not safe since the file can change in the future. You might be better just inlining the patch into the source tree (or re-adding the renames in fetchpatch’s postFetch attribute).

@jtojnar, why fetchpatch is not fixed the way it respects moves/renames?

@jtojnar
Copy link
Member

jtojnar commented Nov 15, 2020

@arapov We would need a fetchpatch2 in order not to break the old hashes. And we would also need to change patchutils to support renames, 0.3.4 does not support it according to #32084 (comment), even though it is supposed to preserve some git metadata. Looking at the changelogs of the newer version they did not add that either.

Edit: There is a long-standing issue open twaugh/patchutils#22, no-one probably found time to implement it yet. Nor implement a custom, more fitting tool as proposed above.

@stale
Copy link

stale bot commented Jun 4, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 4, 2021
@bobby285271
Copy link
Member

Still important (I think I just hit this issue, #140429 (comment)).

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 4, 2021
@eyJhb
Copy link
Member

eyJhb commented Oct 13, 2021

Also just ran into this, while applying a patch from Github using applyPatches. :)

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 16, 2022
@eyJhb
Copy link
Member

eyJhb commented Apr 21, 2022

Still important

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 21, 2022
Artturin added a commit to Artturin/nixpkgs that referenced this issue Jul 20, 2022
allows us to use the new features of patchutils without having to reset
all fetchpatch hashes in nixpkgs

NixOS#32084
@Artturin Artturin mentioned this issue Jul 20, 2022
13 tasks
@Artturin
Copy link
Member

#182250
1st path is by fetchpatch and 2nd is by fetchpatch2

$ diff /nix/store/namp0v9k05pjcax761h7nacpvh77205b-abc52460201bc5c7603505bb187138b0c59291aa.diff /nix/store/d2vkicv4b3xghlmaw4bnwnp01zhk7x6f-abc52460201bc5c7603505bb187138b0c59291aa.diff
0a1,2
> diff --git a/configure b/configure
> index b6c9b462f24..a86f2ceaa5b 100755
18a21,22
> diff --git a/mkspecs/common/macx.conf b/mkspecs/common/macx.conf
> index d16b77acb8e..4ba0a8eaa36 100644
28a33,37
> diff --git a/mkspecs/macx-clang/qmake.conf b/mkspecs/common/clang-macx-desktop.conf
> similarity index 83%
> rename from mkspecs/macx-clang/qmake.conf
> rename to mkspecs/common/clang-macx-desktop.conf
> index 0cf1f31b60d..042319a2aa3 100644

github-actions bot pushed a commit that referenced this issue Dec 1, 2022
allows us to use the new features of patchutils without having to reset
all fetchpatch hashes in nixpkgs

#32084
(cherry picked from commit 4187709)
@Luflosi
Copy link
Contributor

Luflosi commented Jan 2, 2023

Is fetchpatch2 supposed to fix this issue? I'm trying to apply teeworlds/teeworlds@86d6687, which only renames files and nothing else and I get the error message error: Normalized patch '/build/patch' is empty (while the fetched file was not)!.

@Artturin
Copy link
Member

Artturin commented Jan 2, 2023

Is fetchpatch2 supposed to fix this issue?

Yep

I'm trying to apply teeworlds/teeworlds@86d6687, which only renames files and nothing else and I get the error message error: Normalized patch '/build/patch' is empty (while the fetched file was not)!.

If youre already using it then experiment with https://github.com/nixos/nixpkgs/blob/41877098f3ac00295a2a9d5e5846201b969a689b/pkgs/build-support/fetchpatch/default.nix#L39 and see if you can get it working

If not, then it's a upstream issue

@Luflosi
Copy link
Contributor

Luflosi commented Jan 2, 2023

I executed

nix-shell -p patchutils_0_4_2

then inside the shell:

wget 'https://github.com/teeworlds/teeworlds/commit/86d6687ef07f7f05457a7f67537b650656b13820.patch'
lsdiff e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch

lsdiff outputs nothing, so this looks like an upstream issue, right? Did I invoke it correctly?

@Luflosi
Copy link
Contributor

Luflosi commented Jan 2, 2023

For reference, #208826 is where I wanted to use this.

@Artturin Artturin added the 9.needs: upstream fix This PR needs upstream to change something label Jan 3, 2023
@wegank
Copy link
Member

wegank commented Jan 3, 2023

#208918 also has fetchpatch2 failing on the first patch.

@vcunat
Copy link
Member

vcunat commented May 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5. scope: tracked Issue (or PR) is linked back to a `5. scope: tracking` issue 6.topic: fetch 9.needs: upstream fix This PR needs upstream to change something
Projects
None yet
Development

No branches or pull requests