Is it standard practice to edit a .patch
using an editor?
I use .patch
in Yocto Applications where I want to adapt a few small changes to the repository which I wish to port to my embedded device.
One of the patches is as following (some details removed for brewity):
From 85987c659762939241e4bdd4223e63eb5997b181 Mon Sep 17 00:00:00 2001
OE ships php5 as php
---
airmar/airmar.php | 2 +-
n2kd/n2kd_monitor | 2 +-
send-message/format-message | 2 +-
util/list-product-information | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/airmar/airmar.php b/airmar/airmar.php
index ccd4b4d..46ed49d 100755
--- a/airmar/airmar.php
+++ b/airmar/airmar.php
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
<?php
if (!is_array($argv))
{
diff --git a/n2kd/n2kd_monitor b/n2kd/n2kd_monitor
index f8cfd42..4cb4766 100755
--- a/n2kd/n2kd_monitor
+++ b/n2kd/n2kd_monitor
@@ -233,7 +233,7 @@ for (;;)
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>>', $MONITOR_LOGFILE or die "Can't write to $MONITOR_LOGFILE $!";
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
- exec 'php5', '/usr/local/bin/n2k.php', '-monitor';
+ exec 'php', '/usr/bin/n2k.php', '-monitor';
}
if (!$monitor)
{
diff --git a/send-message/format-message b/send-message/format-message
index 590a815..2d91185 100755
--- a/send-message/format-message
+++ b/send-message/format-message
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
<?
#
# Format a particular N2K command
diff --git a/util/list-product-information b/util/list-product-information
index d958ae4..a54a0f2 100755
--- a/util/list-product-information
+++ b/util/list-product-information
@@ -1,4 +1,4 @@
-#!/usr/bin/php5
+#!/usr/bin/env php
<?php
#
# A very limited script engine that sends and receives CAN messages.
--
2.17.0
This patch simply replaces php5
with env php
whereever it occurs.
However, the main code repository changed one of its file where previously there was a shebang for php as follows:
#!/usr/bin/php5
And now after a few commits it doesn't.
From my understanding, the current patch won't work as it will seek to first find the line number and the content to remove but will through errors since it won't be able to find the above mentioned shebang in the file anymore. (already tried it out)
env php
and not php5
) to the code and use git format-patch -1
to obtain a new patch to be restored.However this puts a lot of effort and when there are more than a certain number of files changed then this procedure seems to be tedious.
Is it reasonable to edit the patch using an editor (I am quite sure it isn't)? Or are there some git
features that help modify the patch directly and not the corresponding file?
There is one other alternative way using quilt refresh
. To brief, when using quilt, you will have all the patches copied inside a directory called patches
(IMO this is configurable in quiltrc).
File named series
inside this patch directory stores all the patch file names. When you apply patch using,
quilt push
or
quilt push -a
you will exit with error. Assume you have 10 patches and 3rd couldn't be applied directly as you have some changes already part of repository.
Then you can call
quilt push -f
which will try to apply all the possible places and stores the line which couldn't applied into .rej
file. Example output,
Applying patch patches/0001-To-apply.patch
patching file README.md
Hunk #2 FAILED at 51.
1 out of 2 hunks FAILED -- saving rejects to file README.md.rej
where I have hunks in my README.md file.
Now you can examine the changes which doesn't apply cleanly by comparing original file. In above case between README.md
and README.md.rej
. You can resolve the failed places and call
quilt refresh
After refresh, your original patch file in patches
will be updated with according changes and now you can continue using quilt push
or quilt push -a
Note: Yocto by default uses quilt until otherwise change using PATCHTOOL
variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With