976aaf
From f00bb5be9caa62220c6aeaf3f7264840d5c089e3 Mon Sep 17 00:00:00 2001
976aaf
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
976aaf
Date: Tue, 5 Feb 2019 18:15:47 +0100
976aaf
Subject: [PATCH] Add limits to autopatch macro
976aaf
976aaf
Limits allow to apply only range of patches with given parameters.
976aaf
Useful if something needs to be done between patch sets. Allows applying
976aaf
of patches with different -pX parameter in one spec file.
976aaf
976aaf
Resolves: #626
976aaf
Co-authored-by: Florian Festi <ffesti@redhat.com>
976aaf
---
976aaf
 macros.in | 12 ++++++++++--
976aaf
 1 file changed, 10 insertions(+), 2 deletions(-)
976aaf
976aaf
diff --git a/macros.in b/macros.in
976aaf
index 7b5b63020..912ad5997 100644
976aaf
--- a/macros.in
976aaf
+++ b/macros.in
976aaf
@@ -1265,11 +1265,19 @@ else\
976aaf
 end}
976aaf
 
976aaf
 # Automatically apply all patches
976aaf
-%autopatch(vp:)\
976aaf
+# -m<min>       Apply patches with number >= min only
976aaf
+# -M<max>       Apply patches with number <= max only
976aaf
+%autopatch(vp:m:M:)\
976aaf
 %{lua:\
976aaf
 local options = rpm.expand("%{!-v:-q} %{-p:-p%{-p*}} ")\
976aaf
+local low_limit = tonumber(rpm.expand("%{-m:%{-m*}}"))\
976aaf
+local high_limit = tonumber(rpm.expand("%{-M:%{-M*}}"))\
976aaf
 for i, p in ipairs(patches) do\
976aaf
-    print(rpm.expand("%apply_patch -m %{basename:"..p.."}  "..options..p.." "..i.."\\n"))\
976aaf
+    local inum = patch_nums[i]\
976aaf
+    if ((not low_limit or inum>=low_limit) and (not high_limit or inum<=high_limit)) \
976aaf
+    then\
976aaf
+        print(rpm.expand("%apply_patch -m %{basename:"..p.."}  "..options..p.." "..i.."\\n")) \
976aaf
+    end\
976aaf
 end}
976aaf
 
976aaf
 # One macro to (optionally) do it all.
976aaf
-- 
976aaf
2.26.2
976aaf