Skip to contentSkip to conversation

support/scripts/apply-patches.sh: do not apply patches with renames

PATCH New Thomas Petazzoni 4 participants 6 messages Jun 24, 2017 – Sep 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

Patches with renames apply properly with patch >= 2.7, but not with older patch versions. Since "git format-patch" by default generates patches with renames, Buildroot developers often don't realize that their patches will not apply properly on build machines that have patch < 2.7. In order to prevent such a situation from happening again, this commit adds some logic in apply-patches.sh to refuse applying patches that contain renames.

---
Changes since v1:
- Use "&&" for the "grep -q && grep -q" condition, as noticed by Yann E. Morin.

---
 support/scripts/apply-patches.sh | 5 +++++
 1 file changed, 5 insertions(+)
support/scripts/apply-patches.sh +5 -0
index 7ccb39d..0c24175 100755
@@ -113,6 +113,11 @@ function apply_patch {
         echo "  to be applied  : ${path}/${patch}"
         exit 1
     fi
+    if grep -q "^rename from" ${path}/${patch} && \
+       grep -q "^rename to" ${path}/${patch} ; then
+	echo "Error: patch contains some renames, not supported by old patch versions"
+	exit 1
+    fi
     echo "${path}/${patch}" >> ${builddir}/.applied_patches_list
     ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent
     if [ $? != 0 ] ; then
Signature · 1 line
2.9.4
#1 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

Quoted 9 lines · Thomas Petazzoni

Patches with renames apply properly with patch >= 2.7, but not with older patch versions. Since "git format-patch" by default generates patches with renames, Buildroot developers often don't realize that their patches will not apply properly on build machines that have patch < 2.7. In order to prevent such a situation from happening again, this commit adds some logic in apply-patches.sh to refuse applying patches that contain renames.

Perhaps add to the commit message why you don't just grep for '^rename':

Since the patch commit message may contain the words "rename from" or "rename to" as well, the grep expression is made as accurate as possible, checking both.

Ideally the test should start from the first ^diff, but that makes things a lot
more complicated...

An alternative would be to do

patch --dry-run -i ${path}/${patch} | grep "(renamed from"

but I can't guarantee that that works with all patch versions that understand rename. This the current patch is OK.

Regards,
Arnout

Quoted 25 lines

---
Changes since v1:
- Use "&&" for the "grep -q && grep -q" condition, as noticed by Yann E. Morin.

---
 support/scripts/apply-patches.sh | 5 +++++
 1 file changed, 5 insertions(+)
support/scripts/apply-patches.sh +5 -0
index 7ccb39d..0c24175 100755
@@ -113,6 +113,11 @@ function apply_patch {
         echo "  to be applied  : ${path}/${patch}"
         exit 1
     fi
+    if grep -q "^rename from" ${path}/${patch} && \
+       grep -q "^rename to" ${path}/${patch} ; then
+	echo "Error: patch contains some renames, not supported by old patch versions"
+	exit 1
+    fi
     echo "${path}/${patch}" >> ${builddir}/.applied_patches_list
     ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent
     if [ $? != 0 ] ; then
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#2 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

In reply to Thomas Petazzoni

Thomas, All,

On 2017-06-24 21:59 +0200, Thomas Petazzoni spake thusly:

Quoted 9 lines

Patches with renames apply properly with patch >= 2.7, but not with older patch versions. Since "git format-patch" by default generates patches with renames, Buildroot developers often don't realize that their patches will not apply properly on build machines that have patch < 2.7. In order to prevent such a situation from happening again, this commit adds some logic in apply-patches.sh to refuse applying patches that contain renames.

A small nit below...

Quoted 13 lines

---
Changes since v1:
- Use "&&" for the "grep -q && grep -q" condition, as noticed by Yann E. Morin.

---
 support/scripts/apply-patches.sh | 5 +++++
 1 file changed, 5 insertions(+)
support/scripts/apply-patches.sh +0 -0
index 7ccb39d..0c24175 100755

support/scripts/apply-patches.sh function apply_patch { · line 119

Quoted 7 lines
support/scripts/apply-patches.sh +4 -0
@@ -113,6 +113,11 @@ function apply_patch {
         echo "  to be applied  : ${path}/${patch}"
         exit 1
     fi
+    if grep -q "^rename from" ${path}/${patch} && \
+       grep -q "^rename to" ${path}/${patch} ; then
+	echo "Error: patch contains some renames, not supported by old patch versions"
+	exit 1

This file a space-leading, but here you have a tab...

Otherwise:

Regards,
Yann E. MORIN.

Quoted 7 lines
support/scripts/apply-patches.sh +1 -0
+    fi
     echo "${path}/${patch}" >> ${builddir}/.applied_patches_list
     ${uncomp} "${path}/$patch" | patch -g0 -p1 -E -d "${builddir}" -t -N $silent
     if [ $? != 0 ] ; then
Signature · 1 line
2.9.4
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

In reply to Thomas Petazzoni
Quoted 9 lines · Thomas Petazzoni

Patches with renames apply properly with patch >= 2.7, but not with older patch versions. Since "git format-patch" by default generates patches with renames, Buildroot developers often don't realize that their patches will not apply properly on build machines that have patch < 2.7. In order to prevent such a situation from happening again, this commit adds some logic in apply-patches.sh to refuse applying patches that contain renames.

Applied to master after incorporating Yann's and my suggestions, thanks.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#4 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

Peter, Bernd, All,

On 2017-09-19 23:01 +0200, Arnout Vandecappelle spake thusly:

Quoted 9 lines · Thomas Petazzoni
Quoted 8 lines

Patches with renames apply properly with patch >= 2.7, but not with older patch versions. Since "git format-patch" by default generates patches with renames, Buildroot developers often don't realize that their patches will not apply properly on build machines that have patch < 2.7. In order to prevent such a situation from happening again, this commit adds some logic in apply-patches.sh to refuse applying patches that contain renames.

Quoted 3 lines
Quoted 1 line

Applied to master after incorporating Yann's and my suggestions, thanks.

Which leaves the tree with a single patch that contains renames, which was added by 74a56295 (softether: don't download patch from Github) by Peter. ;-)

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH v2 1/1 support/scripts/apply-patches.sh: do not apply patches with renames

Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Applied to master after incorporating Yann's and my suggestions, thanks.

Which leaves the tree with a single patch that contains renames, which was added by 74a56295 (softether: don't download patch from Github) by Peter. ;-)

Ups, fixed now.

Signature · 1 line
Bye, Peter Korsgaard