Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Patch creation questions
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
creaker
Guru
Guru


Joined: 14 Jul 2012
Posts: 480

PostPosted: Sun Sep 15, 2013 6:09 pm    Post subject: Patch creation questions Reply with quote

Hi there!
I never wrote patches before and now I want to write a patch. I've looked around and found that the "diff" utility does it. So I did the following: I put both initial ebuild and edited into the same directory (with different names) and ran:
Code:
diff -Naur initial.ebuild edited.ebuild > ebuild.patch

I've got a file named ebuild.patch, that contains some strings marked with "+" sign - exactly a difference between two files.
When I trying to apply this patch:
Code:
patch -p0 < ebuild.patch

I get the result, directly opposite to the expected: patch modifies edited ebuild and restores it to initial state instead of modifying initial ebuild.
I tried to build patch in reverse way as
Code:
diff -Naur edited.ebuild initial.ebuild > ebuild.patch

this case I've got a patch with strings marked with "-" sign, but this patch does nothing. No modification on initial ebuild.
Where am I wrong?
_________________
Intel Core i3-2120 / 4Gb RAM / 250Gb HDD / NVidia GeForce-550Ti
Back to top
View user's profile Send private message
VoidMage
Watchman
Watchman


Joined: 14 Oct 2006
Posts: 5271

PostPosted: Sun Sep 15, 2013 6:35 pm    Post subject: Reply with quote

Does "restores it to initial state" actually means "prompts 'patch already applied; assume -R'" ?
Cause if so, it does exactly what it should.
rename patches are a fairly new construct. In the header of the patch you've created only the second name is considered ('edited.ebuild').
You need to correct the header to the name of the file you want it to be applied to.
Back to top
View user's profile Send private message
creaker
Guru
Guru


Joined: 14 Jul 2012
Posts: 480

PostPosted: Sun Sep 15, 2013 7:25 pm    Post subject: Reply with quote

thanks for reply!
I tried to apply patch several times, and once I got exactly the same message about "patch already applied", but I did not noticed any changes. May be I overlooked something...
Have to try it again.
_________________
Intel Core i3-2120 / 4Gb RAM / 250Gb HDD / NVidia GeForce-550Ti
Back to top
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 8617

PostPosted: Sun Sep 15, 2013 8:34 pm    Post subject: Reply with quote

You should always have the second name match the name that the recipient will patch. Some users will arrange the files to have the same name, but in parallel directories. Git users in particular tend to have patches of the form:
Code:
--- a/name
+++ b/name
Back to top
View user's profile Send private message
creaker
Guru
Guru


Joined: 14 Jul 2012
Posts: 480

PostPosted: Sun Sep 15, 2013 11:10 pm    Post subject: Reply with quote

Hu wrote:
You should always have the second name match the name that the recipient will patch. Some users will arrange the files to have the same name, but in parallel directories. Git users in particular tend to have patches of the form:
Code:
--- a/name
+++ b/name

Strangely enough, I was able to apply the patch properly, when the name of the recipient was marked as "---" (first name)
I have in the same directory three files:
    initial ebuld: kdelibs-4.11.1.ebuild
    edited ebuild: kdelibs-edited.ebuild
    patch file: kdelibs.patch


here is the content of kdelibs.patch:

Code:
--- kdelibs-4.11.1.ebuild   2013-09-05 11:31:19.000000000 +0000
+++ kdelibs-edited.ebuild   2013-09-07 12:47:15.000000000 +0000
@@ -29,7 +29,6 @@
 
 COMMONDEPEND="
    app-crypt/qca:2
-   >=app-misc/strigi-0.7.7
    app-text/docbook-xml-dtd:4.2
    app-text/docbook-xsl-stylesheets
    >=dev-libs/libattica-0.4.2
@@ -38,7 +37,6 @@
    dev-libs/libxml2
    dev-libs/libxslt
    >=dev-libs/shared-desktop-ontologies-0.11.0
-   >=dev-libs/soprano-2.9.0[dbus,raptor,redland]
    media-libs/fontconfig
    media-libs/freetype:2
    media-libs/giflib
@@ -107,8 +105,6 @@
 "
 PDEPEND="
    $(add_kdebase_dep katepart)
-   $(add_kdebase_dep nepomuk-core)
-   $(add_kdebase_dep nepomuk-widgets)
    || (
       $(add_kdebase_dep kfmclient)
       x11-misc/xdg-utils


After running "patch < kdelibs.patch" patch was applied to the first file (kdelibs-4.11.1.ebuild), not to the second, and I got kdelibs-4.11.1.ebuild patched (the same content as kdelibs-edited.ebuild)

I think here the changes that marked in patch with "-" will be applied to file that name preceded with "---", and changes marked with "+" will be applied to file, marked with "+++". Regardless what a filename was written at first string
_________________
Intel Core i3-2120 / 4Gb RAM / 250Gb HDD / NVidia GeForce-550Ti
Back to top
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 8617

PostPosted: Sun Sep 15, 2013 11:46 pm    Post subject: Reply with quote

I may be wrong, then. For best results, I suggest using the parallel directory approach, so that both the old and new file names reference the file to be patched.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum