dcavalca / rpms / rpm

Forked from rpms/rpm a year ago
Clone

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

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