aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2012-06-08 18:49:43 +0000
committerThierry Vignaud <tv@mageia.org>2012-06-08 18:49:43 +0000
commit2512e09dc6b9cbb383efa40be09b95d3d419bc3f (patch)
tree730a75e58f2b21f21514963fd8f29647c1c91284
parent4e351504dc092a0a99f33dcbd301f48877eaa2f0 (diff)
downloadperl-URPM-2512e09dc6b9cbb383efa40be09b95d3d419bc3f.tar
perl-URPM-2512e09dc6b9cbb383efa40be09b95d3d419bc3f.tar.gz
perl-URPM-2512e09dc6b9cbb383efa40be09b95d3d419bc3f.tar.bz2
perl-URPM-2512e09dc6b9cbb383efa40be09b95d3d419bc3f.tar.xz
perl-URPM-2512e09dc6b9cbb383efa40be09b95d3d419bc3f.zip
(get_arch) introduce this new helper in order to simplify the code
-rw-r--r--URPM.xs19
1 files changed, 12 insertions, 7 deletions
diff --git a/URPM.xs b/URPM.xs
index 04c713a..07a0038 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -162,6 +162,11 @@ get_name(Header header, int32_t tag) {
return name ? name : "";
}
+static char*
+get_arch(Header header) {
+ return headerIsEntry(header, RPMTAG_SOURCERPM) ? get_name(header, RPMTAG_ARCH) : "src";
+}
+
static int
get_int(Header header, int32_t tag) {
struct rpmtd_s val;
@@ -791,7 +796,7 @@ pack_header(URPM__Package pkg) {
char *name = get_name(pkg->h, RPMTAG_NAME);
char *version = get_name(pkg->h, RPMTAG_VERSION);
char *release = get_name(pkg->h, RPMTAG_RELEASE);
- char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src";
+ char *arch = get_arch(pkg->h);
p += 1 + snprintf(buff, sizeof(buff), "%s-%s-%s.%s@%d@%d@%s", name, version, release, arch,
get_int(pkg->h, RPMTAG_EPOCH), get_int(pkg->h, RPMTAG_SIZE),
@@ -1454,7 +1459,7 @@ Pkg_arch(pkg)
get_fullname_parts(pkg, NULL, NULL, NULL, &arch, &eos);
mXPUSHs(newSVpv(arch, eos-arch));
} else if (pkg->h) {
- mXPUSHs(newSVpv(headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src", 0));
+ mXPUSHs(newSVpv(get_arch(pkg->h), 0));
}
int
@@ -1622,7 +1627,7 @@ Pkg_fullname(pkg)
char *name = get_name(pkg->h, RPMTAG_NAME);
char *version = get_name(pkg->h, RPMTAG_VERSION);
char *release = get_name(pkg->h, RPMTAG_RELEASE);
- char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src";
+ char *arch = get_arch(pkg->h);
if (gimme == G_SCALAR) {
mXPUSHs(newSVpvf("%s-%s-%s.%s", name, version, release, arch));
@@ -1690,7 +1695,7 @@ Pkg_compare_pkg(lpkg, rpkg)
lepoch = get_int(lpkg->h, RPMTAG_EPOCH);
lversion = get_name(lpkg->h, RPMTAG_VERSION);
lrelease = get_name(lpkg->h, RPMTAG_RELEASE);
- larch = headerIsEntry(lpkg->h, RPMTAG_SOURCERPM) ? get_name(lpkg->h, RPMTAG_ARCH) : "src";
+ larch = get_arch(lpkg->h);
} else croak("undefined package");
if (rpkg->info) {
char *s;
@@ -1709,7 +1714,7 @@ Pkg_compare_pkg(lpkg, rpkg)
repoch = get_int(rpkg->h, RPMTAG_EPOCH);
rversion = get_name(rpkg->h, RPMTAG_VERSION);
rrelease = get_name(rpkg->h, RPMTAG_RELEASE);
- rarch = headerIsEntry(rpkg->h, RPMTAG_SOURCERPM) ? get_name(rpkg->h, RPMTAG_ARCH) : "src";
+ rarch = get_arch(rpkg->h);
} else {
/* restore info string modified */
if (lpkg->info) {
@@ -1909,7 +1914,7 @@ Pkg_filename(pkg)
char *name = get_name(pkg->h, RPMTAG_NAME);
char *version = get_name(pkg->h, RPMTAG_VERSION);
char *release = get_name(pkg->h, RPMTAG_RELEASE);
- char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src";
+ char *arch = get_arch(pkg->h);
mXPUSHs(newSVpvf("%s-%s-%s.%s.rpm", name, version, release, arch));
}
@@ -1931,7 +1936,7 @@ Pkg_header_filename(pkg)
char *name = get_name(pkg->h, RPMTAG_NAME);
char *version = get_name(pkg->h, RPMTAG_VERSION);
char *release = get_name(pkg->h, RPMTAG_RELEASE);
- char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src";
+ char *arch = get_arch(pkg->h);
p += snprintf(buff, sizeof(buff), "%s-%s-%s.%s", name, version, release, arch);
mXPUSHs(newSVpv(buff, p-buff));