aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2012-06-22 16:02:53 +0000
committerThierry Vignaud <tv@mageia.org>2012-06-22 16:02:53 +0000
commit9f9a92b7dee5615ab213a3217fcccbdda01af16c (patch)
treed5750dbbedd8ef46c8d70422e52fc5056cee8969
parentebc816b062408510a7b36dab7e7a6c2851c40989 (diff)
downloadperl-URPM-9f9a92b7dee5615ab213a3217fcccbdda01af16c.tar
perl-URPM-9f9a92b7dee5615ab213a3217fcccbdda01af16c.tar.gz
perl-URPM-9f9a92b7dee5615ab213a3217fcccbdda01af16c.tar.bz2
perl-URPM-9f9a92b7dee5615ab213a3217fcccbdda01af16c.tar.xz
perl-URPM-9f9a92b7dee5615ab213a3217fcccbdda01af16c.zip
(get_e_v_r) factorize code
-rw-r--r--NEWS1
-rw-r--r--URPM.xs92
2 files changed, 33 insertions, 60 deletions
diff --git a/NEWS b/NEWS
index 7b88605..3e27c53 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,4 @@
+- internal cleanups
- ranges_overlap(): use rpm to compute whether it overlaps or not
Version 4.7 - 19 June 2012
diff --git a/URPM.xs b/URPM.xs
index da53874..e8ec8c3 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -1359,6 +1359,33 @@ static int compare_evrs(int lepoch, char*lversion, char*lrelease, int repoch, ch
return compare;
}
+static int get_e_v_r(URPM__Package pkg, int *epoch, char **version, char **release, char **arch) {
+ if (pkg->info) {
+ char *s, *eos;
+
+ if ((s = strchr(pkg->info, '@')) != NULL) {
+ if ((eos = strchr(s+1, '@')) != NULL)
+ *eos = 0; /* mark end of string to enable searching backwards */
+ *epoch = atoi(s+1);
+ if (eos != NULL) *eos = '@';
+ } else
+ *epoch = 0;
+ get_fullname_parts(pkg, NULL, version, release, arch, &eos);
+ /* temporarily mark end of each substring */
+ (*release)[-1] = 0;
+ (*arch)[-1] = 0;
+ return 1;
+ } else if (pkg->h) {
+ *epoch = get_int(pkg->h, RPMTAG_EPOCH);
+ *version = get_name(pkg->h, RPMTAG_VERSION);
+ *release = get_name(pkg->h, RPMTAG_RELEASE);
+ *arch = get_arch(pkg->h);
+ return 1;
+ }
+ return 0;
+}
+
+
MODULE = URPM PACKAGE = URPM::Package PREFIX = Pkg_
void
@@ -1592,54 +1619,17 @@ Pkg_compare_pkg(lpkg, rpkg)
char *lversion;
char *lrelease;
char *larch;
- char *leos;
int repoch;
char *rversion;
char *rrelease;
char *rarch;
- char *reos;
CODE:
if (lpkg == rpkg) RETVAL = 0;
else {
- if (lpkg->info) {
- char *s;
-
- if ((s = strchr(lpkg->info, '@')) != NULL) {
- if ((leos = strchr(s+1, '@')) != NULL)
- *leos = 0; /* mark end of string to enable searching backwards */
- lepoch = atoi(s+1);
- if (leos != NULL) *leos = '@';
- } else
- lepoch = 0;
- get_fullname_parts(lpkg, NULL, &lversion, &lrelease, &larch, &leos);
- /* temporarily mark end of each substring */
- lrelease[-1] = 0;
- larch[-1] = 0;
- } else if (lpkg->h) {
- lepoch = get_int(lpkg->h, RPMTAG_EPOCH);
- lversion = get_name(lpkg->h, RPMTAG_VERSION);
- lrelease = get_name(lpkg->h, RPMTAG_RELEASE);
- larch = get_arch(lpkg->h);
- } else croak("undefined package");
- if (rpkg->info) {
- char *s;
+ if (!get_e_v_r(lpkg, &lepoch, &lversion, &lrelease, &larch))
+ croak("undefined package");
- if ((s = strchr(rpkg->info, '@')) != NULL) {
- if ((reos = strchr(s+1, '@')) != NULL) *reos = 0; /* mark end of string to enable searching backwards */
- repoch = atoi(s+1);
- if (reos != NULL) *reos = '@';
- } else
- repoch = 0;
- get_fullname_parts(rpkg, NULL, &rversion, &rrelease, &rarch, &reos);
- /* temporarily mark end of each substring */
- rrelease[-1] = 0;
- rarch[-1] = 0;
- } else if (rpkg->h) {
- repoch = get_int(rpkg->h, RPMTAG_EPOCH);
- rversion = get_name(rpkg->h, RPMTAG_VERSION);
- rrelease = get_name(rpkg->h, RPMTAG_RELEASE);
- rarch = get_arch(rpkg->h);
- } else {
+ if (!get_e_v_r(rpkg, &repoch, &rversion, &rrelease, &rarch)) {
/* restore info string modified */
if (lpkg->info) {
lrelease[-1] = '-';
@@ -1697,26 +1687,8 @@ Pkg_compare(pkg, evr)
char *_release;
char *_eos;
CODE:
- if (pkg->info) {
- char *s;
-
- if ((s = strchr(pkg->info, '@')) != NULL) {
- if ((_eos = strchr(s+1, '@')) != NULL)
- *_eos = 0; /* mark end of string to enable searching backwards */
- _epoch = atoi(s+1);
- if (_eos != NULL)
- *_eos = '@';
- } else
- _epoch = 0;
- get_fullname_parts(pkg, NULL, &_version, &_release, &_eos, NULL);
- /* temporarily mark end of each substring */
- _release[-1] = 0;
- _eos[-1] = 0;
- } else if (pkg->h) {
- _epoch = get_int(pkg->h, RPMTAG_EPOCH);
- _version = get_name(pkg->h, RPMTAG_VERSION);
- _release = get_name(pkg->h, RPMTAG_RELEASE);
- } else croak("undefined package");
+ if (!get_e_v_r(pkg, &_epoch, &_version, &_release, &_eos))
+ croak("undefined package");
char *epoch = NULL, *version, *release;