aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-20 19:01:09 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-20 19:01:09 +0000
commit949d919e1a6eb7df75e9b76adee315e73462e131 (patch)
tree855017c7ae5d95b14abd770e3e65f00684131738
parent3bbeb72d543d9a5cb75d4053ade6252fa5e73445 (diff)
downloadperl-URPM-949d919e1a6eb7df75e9b76adee315e73462e131.tar
perl-URPM-949d919e1a6eb7df75e9b76adee315e73462e131.tar.gz
perl-URPM-949d919e1a6eb7df75e9b76adee315e73462e131.tar.bz2
perl-URPM-949d919e1a6eb7df75e9b76adee315e73462e131.tar.xz
perl-URPM-949d919e1a6eb7df75e9b76adee315e73462e131.zip
split get_fullname_parts() into two separate functions so they can be called as more specific, smaller functions for where only one is needed, which ie. might make it more eligble for inlining etc..
-rw-r--r--URPM.xs132
1 files changed, 70 insertions, 62 deletions
diff --git a/URPM.xs b/URPM.xs
index bc2e333..70de2d1 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -308,8 +308,8 @@ get_evr(URPM__Package pkg) {
/* This function might modify strings that needs to be restored after use
* with restore_chars()
*/
-static int
-get_fullname_parts(URPM__Package pkg, char **name, int *epoch, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) {
+static void
+get_fullname_parts_info(URPM__Package pkg, char **name, int *epoch, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) {
char *_version = NULL, *_release = NULL, *_disttag = NULL, *_distepoch = NULL, *_arch = NULL, *_eos = NULL, *tmp = NULL, *tmp2 = NULL;
/* XXX: Could've probably be written in a more generic way, only thing we
* really want to do is to check for arch field, which will be missing in
@@ -317,54 +317,52 @@ get_fullname_parts(URPM__Package pkg, char **name, int *epoch, char **version, c
*/
int pubkey;
- if(pkg->info) {
- if ((_eos = strchr(pkg->info, '@')) != NULL) {
- if (epoch != NULL) *epoch = isdigit(_eos[1]) ? atoi(_eos+1) : 0;
- if (name != NULL || version != NULL || release != NULL || disttag != NULL || distepoch != NULL || arch != NULL) {
- backup_char(_eos++);
- if (eos != NULL) *eos = _eos;
- if ((pubkey = !strncmp(pkg->info, "gpg-pubkey", 10)) || (_arch = strrchr(pkg->info, '.')) != NULL) {
- if (!pubkey)
- backup_char(_arch++);
- if (arch != NULL) *arch = pubkey ? "" : _arch;
- if (distepoch != NULL || disttag != NULL || release != NULL || version != NULL || name != NULL) {
- if ((_distepoch = strchr(strrchr(pkg->provides, '-'), ':')) != NULL) {
- if ((tmp = strrchr(++_distepoch, ']'))) {
+ if ((_eos = strchr(pkg->info, '@')) != NULL) {
+ if (epoch != NULL) *epoch = isdigit(_eos[1]) ? atoi(_eos+1) : 0;
+ if (name != NULL || version != NULL || release != NULL || disttag != NULL || distepoch != NULL || arch != NULL) {
+ backup_char(_eos++);
+ if (eos != NULL) *eos = _eos;
+ if ((pubkey = !strncmp(pkg->info, "gpg-pubkey", 10)) || (_arch = strrchr(pkg->info, '.')) != NULL) {
+ if (!pubkey)
+ backup_char(_arch++);
+ if (arch != NULL) *arch = pubkey ? "" : _arch;
+ if (distepoch != NULL || disttag != NULL || release != NULL || version != NULL || name != NULL) {
+ if ((_distepoch = strchr(strrchr(pkg->provides, '-'), ':')) != NULL) {
+ if ((tmp = strrchr(++_distepoch, ']'))) {
+ backup_char(tmp);
+ if ((tmp = strstr(pkg->info, _distepoch)))
backup_char(tmp);
- if ((tmp = strstr(pkg->info, _distepoch)))
- backup_char(tmp);
- else {
- /* If synthesis is generated with older versions, disttag & distepoch will
- * not be part of NVRA at beginning of line, but as it'll still be part of
- * filename which is located at end of line, we can live with it as long
- * as we're aware of it and take the necessary precautions to cope.
- */
- if ((tmp = strrchr(_eos, '-'))) {
- if ((tmp2 = strstr(tmp++, _distepoch))) {
- backup_char(tmp2);
- _disttag = tmp;
- }
+ else {
+ /* If synthesis is generated with older versions, disttag & distepoch will
+ * not be part of NVRA at beginning of line, but as it'll still be part of
+ * filename which is located at end of line, we can live with it as long
+ * as we're aware of it and take the necessary precautions to cope.
+ */
+ if ((tmp = strrchr(_eos, '-'))) {
+ if ((tmp2 = strstr(tmp++, _distepoch))) {
+ backup_char(tmp2);
+ _disttag = tmp;
}
}
}
}
- if (distepoch != NULL) *distepoch = _distepoch ? _distepoch : "";
- if (disttag != NULL || release != NULL || version != NULL || name != NULL) {
- if (_disttag == NULL) {
- /* XXX: re-verify this logic, see comment above.. */
- if ((_disttag = strrchr(pkg->info, '-')) != NULL && (strstr(pkg->provides, _disttag)) == NULL) {
- backup_char(_disttag++);
- } else _disttag = NULL;
- }
- if (disttag != NULL) *disttag = _disttag ? _disttag : "";
- if ((release != NULL || version != NULL || name != NULL) && (_release = strrchr(pkg->info, '-')) != NULL) {
- backup_char(_release++);
- if (release != NULL) *release = _release;
- if ((version != NULL || name != NULL) && (_version = strrchr(pkg->info, '-')) != NULL) {
- backup_char(_version++);
- if (version != NULL) *version = _version;
- if (name != NULL) *name = pkg->info;
- }
+ }
+ if (distepoch != NULL) *distepoch = _distepoch ? _distepoch : "";
+ if (disttag != NULL || release != NULL || version != NULL || name != NULL) {
+ if (_disttag == NULL) {
+ /* XXX: re-verify this logic, see comment above.. */
+ if ((_disttag = strrchr(pkg->info, '-')) != NULL && (strstr(pkg->provides, _disttag)) == NULL) {
+ backup_char(_disttag++);
+ } else _disttag = NULL;
+ }
+ if (disttag != NULL) *disttag = _disttag ? _disttag : "";
+ if ((release != NULL || version != NULL || name != NULL) && (_release = strrchr(pkg->info, '-')) != NULL) {
+ backup_char(_release++);
+ if (release != NULL) *release = _release;
+ if ((version != NULL || name != NULL) && (_version = strrchr(pkg->info, '-')) != NULL) {
+ backup_char(_version++);
+ if (version != NULL) *version = _version;
+ if (name != NULL) *name = pkg->info;
}
}
}
@@ -372,18 +370,29 @@ get_fullname_parts(URPM__Package pkg, char **name, int *epoch, char **version, c
}
}
}
- else if(pkg->h) {
- if (name != NULL) *name = (char*)get_name(pkg->h, RPMTAG_NAME);
- if (epoch != NULL) *epoch = get_int(pkg->h, RPMTAG_EPOCH);
- if (version != NULL) *version = (char*)get_name(pkg->h, RPMTAG_VERSION);
- if (release != NULL) *release = (char*)get_name(pkg->h, RPMTAG_RELEASE);
- if (disttag != NULL) *disttag = (char*)get_name(pkg->h, RPMTAG_DISTTAG);
- if (distepoch != NULL) *distepoch = (char*)get_name(pkg->h, RPMTAG_DISTEPOCH);
- if (arch != NULL) *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? (char*)get_name(pkg->h, RPMTAG_ARCH) : "src";
+}
+
+static void
+get_fullname_parts_header(Header h, char **name, int *epoch, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) {
+ if (name != NULL) *name = (char*)get_name(h, RPMTAG_NAME);
+ if (epoch != NULL) *epoch = get_int(h, RPMTAG_EPOCH);
+ if (version != NULL) *version = (char*)get_name(h, RPMTAG_VERSION);
+ if (release != NULL) *release = (char*)get_name(h, RPMTAG_RELEASE);
+ if (disttag != NULL) *disttag = (char*)get_name(h, RPMTAG_DISTTAG);
+ if (distepoch != NULL) *distepoch = (char*)get_name(h, RPMTAG_DISTEPOCH);
+ if (arch != NULL) *arch = headerIsEntry(h, RPMTAG_SOURCERPM) ? (char*)get_name(h, RPMTAG_ARCH) : "src";
if (eos != NULL) *eos = NULL;
- }
+}
+
+static int
+get_fullname_parts(URPM__Package pkg, char **name, int *epoch, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) {
+ if(pkg->info)
+ get_fullname_parts_info(pkg, name, epoch, version, release, disttag, distepoch, arch, eos);
+ else if(pkg->h)
+ get_fullname_parts_header(pkg->h, name, epoch, version, release, disttag, distepoch, arch, eos);
else
return 1;
+
return 0;
}
@@ -774,48 +783,47 @@ return_list_tag(URPM__Package pkg, const char *tag_name) {
switch (tag) {
case RPMTAG_NAME:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(name, 0)));
}
break;
case RPMTAG_EPOCH: {
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSViv(epoch)));
}
case RPMTAG_VERSION:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(version, 0)));
}
break;
case RPMTAG_RELEASE:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(release, 0)));
-
}
break;
case RPMTAG_DISTTAG:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(disttag, 0)));
}
break;
case RPMTAG_DISTEPOCH:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(distepoch, 0)));
}
break;
case RPMTAG_ARCH:
{
- if(get_fullname_parts(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
+ if(get_fullname_parts_info(pkg, &name, &epoch, &version, &release, &arch, &disttag, &distepoch, &eos))
croak("invalid fullname");
XPUSHs(sv_2mortal(newSVpv(arch, 0)));
}