[Bradford] How to apply git patch

Devo Too mike.goodman at devotoo.org.uk
Sat Jan 11 20:09:34 UTC 2020


Hi Michael (and list),

I'm top-posting because it seems that's the way everybody is going these 
days. If there are enough complaints, good, kudos to each of you, and 
I'll happily revert.

Wonderful response Michael, thank you. Truly appreciated. Just what I 
needed. Nuts and bolts. Verifies and adds to what John Hudson and I have 
discussed off list.

Not quite there yet, though. As will become extremely obvious from what 
follows, my depth of knowledge is, well, shallow may be exaggeration. 
Dry may be more to the point. Getting into kernels and source code 
directories is beyond me.

I need to find the source directory of dhcpcd. I would have expected to 
find something like that in /usr/src/. It is an empty directory. There 
are dhcpcd directories here: /usr/bin/dhcpcd /usr/lib/dhcpcd 
/etc/dhcpcd.conf /usr/share/dhcpcd, none of which contain a /src/ 
subdirectory, as in the patch contents.

There are source directories in dot directories, ignoring man pages 
these are /usr/bin/. /usr/lib/. /etc/. /etc/.updated /usr/local/bin/. 
/usr/local/sbin/. /usr/local/etc/. /usr/local/lib/. /usr/local/games/. 
/usr/include/. /usr/local/. /usr/share/. /usr/bin/site_perl/. 
/usr/bin/vendor_perl/. /usr/bin/core_perl/. from which I assume we can 
ignore the perl ones and treat games as irrelevant on a server. Or can we?

The one other point, which I think I understand but would like 
verification, is that the supplier of the patch has dome the work so I 
should simply run the patch commands rather than compiling and building 
the source code?

Michael, next time you're in the Leeds/Bradford area or I'm in Greater 
Manchester I shall certainly cough up for a pint or two! I'm none too 
sure the landlord of your local would accept my credit note :-(

Cheers,

Mike

On 11/01/2020 13:37, Michael Dorrington via Bradford wrote:
> On 10/01/2020 20:22, Devo Too via Bradford wrote:
>> Hi Folks,
>>
>> I've been sent a git patch by the developer of dhcpcd. What on earth do
>> I do with it? I can't even make out if the first line is part of the
>> patch or a command and web searches are confusing rather then enlightening.
> 
> Basically, a patch file is a line-by-line difference between 2 versions
> of files.  This is also known as a "diff" since you can use the `diff`
> command to produce them.  Since Git is version control you can use Git
> to produce a patch/diff between 2 versions; when it does that it uses
> the fake directory 'a' for the "original" version and directory 'b' as
> the "new" version.  That's why the Git patch you have contains:
> 
> diff --git a/src/ipv6.c b/src/ipv6.c
> 
> If you have Git installed then you should be able to change to the
> directory of the source code of dhcpd and run:
> 
> git apply --check location/of/your/dhcpd.patch
> git apply location/of/your/dhcpd.patch
> 
> See `man git-apply`.
> 
> If you haven't got Git installed then you can use `patch`.  In the dhcpd
> source directory do:
> 
> patch -p1 --dry-run location/of/your/dhcpd.patch
> patch -p1 location/of/your/dhcpd.patch
> 
> See `man patch`.
> 
> Answered more below inline ->
> 
>> Here are the first few lines. What follow those are definitely part of
>> the patch itself.
>>
>> diff --git a/src/ipv6.c b/src/ipv6.c
>> index c49300c1..92403912 100644
>> --- a/src/ipv6.c
>> +++ b/src/ipv6.c
>> @@ -1554,7 +1554,9 @@ ipv6_newaddr(struct interface *ifp, const struct
>> in6_addr *addr,
>>          tempaddr = false;
>>   #endif
>>
>> Is this correct and if not, what is correct:
> 
> It is correct.
> 
>> The first line is the command to run - or the first 4 lines?
> 
> The 1st line is the command that was/can be used to create the patch,
> the 2nd line is Git stuff (see `man git-diff`) and 3rd & 4th are as
> explained above.
> 
>> The rest is the patch, which I should save as a standard file with -
>> what name? - in /root, before running the command?
> 
> The whole lot is the patch.  You can save it with any name but recommend
> using a name that helps you such as one that describes what the patch is
> doing with `.patch` at the end like:
> 
> dhcpd-ipv6-widget-misfire-fix.patch
> 
>> Git is not installed but I understand the patch command should be able
>> to handle it. Is that correct?
> 
> Correct, see above.
> 
>> Also, the line which contains "const struct" looks questionable to me.
>> Is this correct code or a typo creating gobbledegook?
> 
> Not a typo.  The "const" means it is a constant and "struct" is a structure.
> 
> You will need to compile/build the source code to get a program with
> patch in it.
> 
>> The responder with the sensible, working answer will be entitled to a
>> drink from me on Tuesday evening after the LUG.
> 
> Can I get a voucher instead?
> 
> M.
> 
> P.S.
> More on patch: https://en.wikipedia.org/wiki/Patch_(Unix)
> 



More information about the Bradford mailing list