Talk:Creating a patch

From Gentoo Wiki
(Redirected from Talk:Patches)
Jump to:navigation Jump to:search
Note
This is a Talk page - please see the documentation about using talk pages. Add newer comments below older ones, sign comments using four tildes (~~~~), and indent successive comments with colons (:). Add new sections at the bottom of the page, under a heading (== ==). Please remember to mark sections as "open for discussion" using {{talk|open}}, so they will show up in the list of open discussions.

How to create a patch?

Talk status
This discussion is done.

What I am missing here is a simple example how to do it. Something like:

--- Begin ---

If souce code is provided as a git repository, get and unpack it:

user $ebuild $(portageq get_repo_path / gentoo)/x11-misc/pcmanfm/pcmanfm-9999.ebuild clean unpack
 * checking ebuild checksums ;-) ...                                                                                                                               [ ok ]
 * checking auxfile checksums ;-) ...                                                                                                                              [ ok ]
 * checking miscfile checksums ;-) ...                                                                                                                             [ ok ]
>>> Unpacking source...
 * Fetching git://git.lxde.org/git/lxde/pcmanfm ...
git fetch git://git.lxde.org/git/lxde/pcmanfm +HEAD:refs/git-r3/HEAD
git symbolic-ref refs/git-r3/x11-misc/pcmanfm/0/__main__ refs/git-r3/HEAD
 * Checking out git://git.lxde.org/git/lxde/pcmanfm to /var/tmp/portage/x11-misc/pcmanfm-9999/work/pcmanfm-9999 ...
git checkout --quiet refs/git-r3/HEAD
GIT update -->
   repository:               git://git.lxde.org/git/lxde/pcmanfm
   at the commit:            4fbe54d913bd5d7ad890c69f55878da924c67eb5
>>> Source unpacked in /var/tmp/portage/x11-misc/pcmanfm-9999/work

Step into the git repository just created:

user $cd /var/tmp/portage/x11-misc/pcmanfm-9999/work/pcmanfm-9999

Modify some file, e.g ./data/ui/Makefile.am

Let git diff display the difference (works very nice even if more or many files were modified):

user $git diff HEAD
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index f834427..7932953 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -3,8 +3,6 @@ NULL=
 # GtkBuilder UI definition files
 uidir=$(datadir)/pcmanfm/ui
 ui_SOURCES = \
-       pref.glade \
-       desktop-pref.glade \
        autorun.glade \
        connect.glade \
        $(NULL)

Save the differences into a file:

user $git diff HEAD > /tmp/mypatch.patch

--- END ---

Git will do it all (almost).--Charles17 (talk) 14:30, 31 July 2017 (UTC)

In case the source code is not providing a git repository, see User:Charles17/cheat_sheet#Creating_a_patch. But that example needs to get much more text explaining it. --Charles17 (talk) 08:00, 1 August 2017 (UTC)

TortoiseGit and Git for Windows

Talk status
This discussion is done.

As the main section header is called "Creating patches": How could a Gentoo user create patches with those tools which both seem not being available on Gentoo?--Charles17 (talk) 18:28, 31 July 2017 (UTC)

Just renamed that section.--Charles17 (talk) 13:46, 1 August 2017 (UTC)

Sync with devmanual

Talk status
This discussion is still ongoing.

We should sync this with the guidance in the devmanual.

Sam (talk) 07:20, 15 March 2021 (UTC)

Duplicate devmanual's content here? It's already mentioned 2nd reference in External resources.
--Charles17 (talk) 07:53, 15 March 2021 (UTC)
Not duplicate, but make clear that tidy patches should drop some of the git metadata.
--Sam (talk) 07:57, 15 March 2021 (UTC)
No clue.
And, I doubt those patches as written in Devmanual would apply under EAPI 7 as so often people have to replace
---
+++
with
--- a/
+++ b/
--Charles17 (talk) 08:19, 15 March 2021 (UTC)


Patching Windows Code That Has Carriage Return/Linefeeds

Talk status
This discussion is still ongoing.

A package may import auxiliary code that is based on a project that is MS Windows based. As a result, you will have code being brought in that has carriage return + line feeds, aka "^M" and if you created a patch to that code, the eapply (as of 2/14/2023) will complain

    (Stripping trailing CRs from patch; use --binary to disable.)
    patching file GenFfs/GenFfs.c
    Hunk #1 FAILED at 542 (different line endings).
    1 out of 1 hunk FAILED -- saving rejects to file GenFfs/GenFfs.c.rej
    (Stripping trailing CRs from patch; use --binary to disable.)
    patching file GenSec/GenSec.c
    Hunk #1 FAILED at 1062 (different line endings).

You might think that you can finesse the problem by converting the line endings of your patch created in Linux by processing the patch using unix2dos. But that will not work, because eapply will "Strip" the carriage returns thereby defeating your attempt to make your patch match the source code.

What to do? Well, I first tried to find some instructions/documentation about "eapply" and how to pass the "--binary" flag within an ebuild. I did not find any. So I thought I'd present this issue here while I experiment and or ask others so this problem is documented for future users.

A solution is to modify the ebuild and insert "--binary " as a parameter to the eapply statement. Example:

    eapply --binary "${FILESDIR}/${PN}-4.15.1-edk-gcc12.patch"

Jlpoole (talk) 22:02, 14 February 2023 (UTC)