dcavalca / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone

Blame SOURCES/0001-Introduce-patch_nums-and-source_nums-Lua-variables-i.patch

976aaf
From 9ad4b813483f8cf6c641f56387248b33b6dfc570 Mon Sep 17 00:00:00 2001
976aaf
From: Panu Matilainen <pmatilai@redhat.com>
976aaf
Date: Wed, 20 Feb 2019 15:28:30 +0200
976aaf
Subject: [PATCH] Introduce patch_nums and source_nums Lua variables in spec
976aaf
 context
976aaf
976aaf
The pre-existing patches and sources variables only contains patch and
976aaf
source filenames, but for some purposes we need access to the associated
976aaf
patch/source number too. We could use the number as the table key, but
976aaf
that would make the table unsorted. That we could handle in our own
976aaf
macros, but would break compatibility for anybody doing custom stuff
976aaf
with these. So it seems best to just add parallel arrays sharing the
976aaf
same array indexes so that both values are as easily accessible,
976aaf
depending on the need.
976aaf
976aaf
Inspired by Pascal "Pixel" Rigaux's similar patch in Mageia, which differs
976aaf
in that the number-arrays are indexed by the filename and is unordered.
976aaf
Compared to patches/sources this seemed against principle of least
976aaf
surprise, and is slightly more cumbersome int the case we want the number
976aaf
directly, such as in PR #626. The variable names differ so there
976aaf
is no incompatibility to that downstream patch introduced.
976aaf
---
976aaf
 build/parsePreamble.c | 9 +++++++++
976aaf
 build/spec.c          | 3 ++-
976aaf
 2 files changed, 11 insertions(+), 1 deletion(-)
976aaf
976aaf
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
976aaf
index 812c41f9f..9520bac4b 100644
976aaf
--- a/build/parsePreamble.c
976aaf
+++ b/build/parsePreamble.c
976aaf
@@ -322,6 +322,15 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag
976aaf
 	    rpmluaSetVar(lua, var);
976aaf
 	    rpmluavFree(var);
976aaf
 	    rpmluaPop(lua);
976aaf
+
976aaf
+	    what = (flag & RPMBUILD_ISPATCH) ? "patch_nums" : "source_nums";
976aaf
+	    rpmluaPushTable(lua, what);
976aaf
+	    var = rpmluavNew();
976aaf
+	    rpmluavSetListMode(var, 1);
976aaf
+	    rpmluavSetValueNum(var, p->num);
976aaf
+	    rpmluaSetVar(lua, var);
976aaf
+	    rpmluavFree(var);
976aaf
+	    rpmluaPop(lua);
976aaf
 	}
976aaf
 #endif
976aaf
 	free(body);
976aaf
diff --git a/build/spec.c b/build/spec.c
976aaf
index 80eaca611..55095c6ce 100644
976aaf
--- a/build/spec.c
976aaf
+++ b/build/spec.c
976aaf
@@ -305,7 +305,8 @@ rpmSpec newSpec(void)
976aaf
 #ifdef WITH_LUA
976aaf
     /* make sure patches and sources tables always exist */
976aaf
     rpmlua lua = NULL; /* global state */
976aaf
-    const char * luavars[] = { "patches", "sources", NULL, };
976aaf
+    const char * luavars[] = { "patches", "sources",
976aaf
+			       "patch_nums", "source_nums", NULL, };
976aaf
     for (const char **vp = luavars; vp && *vp; vp++) {
976aaf
 	rpmluaDelVar(lua, *vp);
976aaf
 	rpmluaPushTable(lua, *vp);
976aaf
-- 
976aaf
2.26.2
976aaf