View previous topic :: View next topic |
Author |
Message |
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sat Jul 30, 2005 10:49 am Post subject: How do I write patches to distribute to other people? |
|
|
Hi.
I've written my first HOWTO. It involves patching an ebuild with a custom patch I made. I've yet struggled to have it work on my machine.
What I do is:
- Copy the ebuild to my home directory, into sub-directory test/
- Change the ebuild copy
- Run diff -Naur <initial ebuild in portage> <modified ebuild copy> > ~/test.patch
- Remove path information in test.patch so that it must be applied from directory where the file to patch resides.
Example, before :
Code: | --- /usr/portage/x11-base/xorg-x11/xorg-x11-6.8.99.15.ebuild 2005-07-21 22:05:58.000000000 +0200
+++ test/xorg-x11-6.8.99.15.ebuild 2005-07-30 00:41:50.000000000 +0200 |
after:
Code: | --- xorg-x11-6.8.99.15.ebuild 2005-07-21 22:05:58.000000000 +0200
+++ new/xorg-x11-6.8.99.15.ebuild 2005-07-30 00:41:50.000000000 +0200 |
On my machine the patch is applied as expected but there are people who reported the patch doesn't work on their machine. Do file dates matter? Are there guidelines to distribute a cutom patch?
Thanks in advance.
FYI: if date matters, on my machine CLOCK is set to local in /etc/conf.d/clock. _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
kallamej Administrator
Joined: 27 Jun 2003 Posts: 4975 Location: Gothenburg, Sweden
|
Posted: Sat Jul 30, 2005 1:05 pm Post subject: |
|
|
Typically, you have the original and the updated file in the same directory. That way you don't have to fix the paths afterwards. Time stamps shouldn't matter. _________________ Please read our FAQ Forum, it answers many of your questions.
irc: #gentoo-forums on irc.libera.chat |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sat Jul 30, 2005 1:13 pm Post subject: |
|
|
kallamej wrote: | Typically, you have the original and the updated file in the same directory. That way you don't have to fix the paths afterwards. Time stamps shouldn't matter. |
Thanks, kallamej. So if that works on my machine, there should be no reason why it shouldn't on others? Hence if a patch is not applied and returns errors that means the target file differs too much from the patch context? _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
kallamej Administrator
Joined: 27 Jun 2003 Posts: 4975 Location: Gothenburg, Sweden
|
Posted: Sat Jul 30, 2005 1:36 pm Post subject: |
|
|
The problem may also be that you have different path levels in your patch. _________________ Please read our FAQ Forum, it answers many of your questions.
irc: #gentoo-forums on irc.libera.chat |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sat Jul 30, 2005 2:17 pm Post subject: |
|
|
kallamej wrote: | The problem may also be that you have different path levels in your patch. |
Patch level? _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
kallamej Administrator
Joined: 27 Jun 2003 Posts: 4975 Location: Gothenburg, Sweden
|
Posted: Sat Jul 30, 2005 2:44 pm Post subject: |
|
|
I meant Code: | --- foo
+++ new/foo |
instead of
Code: | --- old/foo
+++ new/foo |
According to the patch manpage, some versions of patch may have a problem with the former. _________________ Please read our FAQ Forum, it answers many of your questions.
irc: #gentoo-forums on irc.libera.chat |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sat Jul 30, 2005 2:54 pm Post subject: |
|
|
Ah I see now. If I understand correctly, the first line must designate the actual file I want to change, right? Does it matter if a patch is structured like the following even if applied from where the patched file resides?
Code: | +++ path-to-old/file
--- path-to-new/file |
And do both paths have to be present in the actual file path? _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
metty Tux's lil' helper
Joined: 25 Oct 2004 Posts: 118
|
Posted: Sat Jul 30, 2005 4:23 pm Post subject: |
|
|
VinzC wrote: | Ah I see now. If I understand correctly, the first line must designate the actual file I want to change, right? Does it matter if a patch is structured like the following even if applied from where the patched file resides?
Code: | +++ path-to-old/file
--- path-to-new/file |
And do both paths have to be present in the actual file path? |
You mixed it up. --- is old file, +++ is new file. And that means --- is the first line, then comes +++.
So...
Also, as someone pointed out in your tutorial/howto thread:
the -p option in patch is quite useful. Check the man page on patch.
Lastly, an article I came across once upon a time that may help you:
http://www.circlemud.org/cdp/wtfaq/handpatch.html |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sat Jul 30, 2005 11:06 pm Post subject: |
|
|
metty wrote: | You mixed it up. --- is old file, +++ is new file. And that means --- is the first line, then comes +++.
So...
Also, as someone pointed out in your tutorial/howto thread:
the -p option in patch is quite useful. Check the man page on patch.
Lastly, an article I came across once upon a time that may help you:
http://www.circlemud.org/cdp/wtfaq/handpatch.html |
Sorry, I made a typo, I should have read my post once more . Thanks for the link. I think have understood the meaning of patch symbols. I just wanted to know if the subdirectories mentioned in a patch (and how many of them) had to reflect the actual path of the file to be patched. For instance, if I must patch /usr/local/path/targetfile *and* I am already in /usr/local/path/, can it be patched with:
Code: | --- old/targetfile
+++ new/targetfile
... |
Or should the patch begin with
Code: | --- path/targetfile
+++ new/targetfile
... |
_________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
metty Tux's lil' helper
Joined: 25 Oct 2004 Posts: 118
|
Posted: Sun Jul 31, 2005 3:19 am Post subject: |
|
|
Firstly, from patch man page:
Quote: |
-p<num> or --strip=num
Strip the smallest prefix containing num leading slashes from each file name found in the
patch file. A sequence of one or more adjacent slashes is counted as a single slash.
This controls how file names found in the patch file are treated, in case you keep your
files in a different directory than the person who sent out the patch. For example, sup-
posing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
setting -p0 gives the entire file name unmodified, -p1 gives
u/howard/src/blurfl/blurfl.c
without the leading slash, -p4 gives
blurfl/blurfl.c
and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked
for either in the current directory, or the directory specified by the -d option.
|
Easiest is probably what kallamej said (that you have the old file and new file in the same directory, thus elimenating the problems with path). If not you can try experimenting with -p<num>.
If you're still confused, I'll see if I can give you a practical example tomorrow or so (kind of busy atm and it's soon bed time for me). |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sun Jul 31, 2005 9:55 am Post subject: |
|
|
Thanks for taking your time. I didn't read toroughly the man pages indeed.
Putting things together to check if I've understood correctly (sorry but my brains are working slowly today as I'm just back from a birthday dinner at a Chinese restaurant; I only slept 4 hours so bear with me ).
As for paths in a patch, my main idea was about applying patches in an ebuild. IIRC epatch tries -p0 to -p4, is that correct? Hence this means the actual location (relative to where "patch -pN" is run from) of the file being patched must appear in either the "Index:" or the ---/+++ paths, right?
So if there is an "Index:" line, the file name ought to contain the actual [relative] path of the file to patch, right? So in my howto, I can safely remove the "Index:" part from the lnx_agp patch because it contains no path information; since epatch function runs "patch" from the ebuild working directory the latter won't find lnx_ag.c just looking at the "Index:" line. It relies on the ---/+++ lines to find the file.
From what you told me kallamej, there should be the same number of slashes in both the --- and +++ lines, right? As for use with ebuilds: I must add paths to the patch afterwards in cases I diff the original file from its current directory. _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
metty Tux's lil' helper
Joined: 25 Oct 2004 Posts: 118
|
Posted: Sun Jul 31, 2005 3:11 pm Post subject: |
|
|
I can't answer the question in regards to epatch, because I have never had a need/want to make my own ebuild/etc... I'd guess very similar though. Maybe someone else can answer this question (or I suppose you could try it out yourself with different directory structures) ? Or maybe it has a --dry-run option like normal patch ? I honestly don't know, but you might want to look in to that.
For index stuff, this is taken directly from the patch man page (again I don't know about epatch):
Quote: |
First, patch takes an ordered list of candidate file names as follows:
o If the header is that of a context diff, patch takes the old and new file names in the
header. A name is ignored if it does not have enough slashes to satisfy the -pnum or
--strip=num option. The name /dev/null is also ignored.
o If there is an Index: line in the leading garbage and if either the old and new names are
both absent or if patch is conforming to POSIX, patch takes the name in the Index: line.
o For the purpose of the following rules, the candidate file names are considered to be in
the order (old, new, index), regardless of the order that they appear in the header.
|
So yeah, you probably could take out the index. I personally don't often see it in normal patches.
And yes, it's easiest and maybe best to have the same number of slashes in the old path and new path (I can't think of any patches I made or used that didn't have the same number of directories). It's been a while since I've made my own patches though.
I think that covers your questions, but if you have more, feel free to ask. Would of course recommend you try various methods of patching (different number of directories, that kind of thing). |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Sun Jul 31, 2005 3:15 pm Post subject: |
|
|
Thanks again. _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
metty Tux's lil' helper
Joined: 25 Oct 2004 Posts: 118
|
Posted: Sun Jul 31, 2005 3:48 pm Post subject: |
|
|
Glad to help. |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Wed Aug 03, 2005 9:49 pm Post subject: |
|
|
Hi again, metty.
It seems some people still cannot patch the ebuild file with the patch from my howto. The error messages say both hunks are rejected. Would you mind giving it a go and telling me what's wrong, please?
Thanks again. _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
kallamej Administrator
Joined: 27 Jun 2003 Posts: 4975 Location: Gothenburg, Sweden
|
Posted: Wed Aug 03, 2005 10:22 pm Post subject: |
|
|
Tested and it failed because of white space issues. The ebuild has tab indents whilst a simple copy-paste of the patch produces ordinary spaces. _________________ Please read our FAQ Forum, it answers many of your questions.
irc: #gentoo-forums on irc.libera.chat |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Thu Aug 04, 2005 7:04 pm Post subject: |
|
|
kallamej wrote: | Tested and it failed because of white space issues. The ebuild has tab indents whilst a simple copy-paste of the patch produces ordinary spaces. |
???? Seriously??? You mean people must convert spaces to the same number of tabs? Spaces and tabs are alike, normally...
IMHO this should be submitted as a bug, shouldn't it?
Anyway thanks a (whole) lot for your kind help. _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
metty Tux's lil' helper
Joined: 25 Oct 2004 Posts: 118
|
Posted: Thu Aug 04, 2005 7:08 pm Post subject: |
|
|
It's a standard, in essence. And it's not the only program that does this, either:
When you build a Makefile, for instance, 'make' insists you use tabs instead of spaces. |
|
Back to top |
|
|
VinzC Watchman
Joined: 17 Apr 2004 Posts: 5098 Location: Dark side of the mood
|
Posted: Thu Aug 04, 2005 7:33 pm Post subject: |
|
|
metty wrote: | It's a standard, in essence. And it's not the only program that does this, either:
When you build a Makefile, for instance, 'make' insists you use tabs instead of spaces. |
Then if it's a standard... _________________ Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739! |
|
Back to top |
|
|
|