Added changelog support from repodata

This commit is contained in:
Silvan Calarco 2021-02-16 15:43:38 +01:00
parent f804316c02
commit c0c8df638e
3 changed files with 72 additions and 13 deletions

View File

@ -1,7 +1,7 @@
/* /*
* distromatic - tool for RPM based repositories * distromatic - tool for RPM based repositories
* *
* Copyright (C) 2004-2020 by Silvan Calarco <silvan.calarco@mambasoft.it> * Copyright (C) 2004-2021 by Silvan Calarco <silvan.calarco@mambasoft.it>
* Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com> * Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
@ -116,23 +116,18 @@ getPackagerByName(char *name, int create)
struct changeLog * struct changeLog *
getPackageChangelog(Header h, struct headerSourceList* headersource) getPackageChangelog(uint_32 *changelogtime, char **changelogrelease,
char **changelogtext, int count, struct headerSourceList* headersource)
{ {
int count, i; int i;
struct changeLogFull *newchangelogfull, *prevchangelogfull; struct changeLogFull *newchangelogfull, *prevchangelogfull;
struct changeLog *newchangelog, struct changeLog *newchangelog,
*oldchangelog = NULL, *oldchangelog = NULL,
*firstchangelog = NULL; *firstchangelog = NULL;
struct Packager *currpackager = NULL; struct Packager *currpackager = NULL;
char **changelogtext, **changelogrelease;
char *endp; char *endp;
uint_32 *changelogtime;
char changelogname[255]; char changelogname[255];
changelogtime = headerGetUIntArrayEntry(h, RPMTAG_CHANGELOGTIME, &count);
changelogrelease = headerGetStringArrayEntry(h, RPMTAG_CHANGELOGNAME, &count);
changelogtext = headerGetStringArrayEntry(h, RPMTAG_CHANGELOGTEXT, &count);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
newchangelog = malloc(sizeof(struct changeLog)); newchangelog = malloc(sizeof(struct changeLog));

View File

@ -876,6 +876,35 @@ void getXMLPackageFiles(xmlNode *parent, uint **type, char ***path, int *count)
(*path)[i] = NULL; (*path)[i] = NULL;
} }
void getXMLPackageChangelog(xmlNode *parent,
uint_32 **changelogtime, char ***changelogrelease,
char ***changelogtext, int *count) {
*count = xmlChildElementCount(parent) - 1;
if (*count == 0) {
*changelogtime = NULL;
*changelogrelease = NULL;
*changelogtext = NULL;
return;
}
*changelogtime = malloc(sizeof(uint_32*) * *count);
*changelogrelease = malloc(sizeof(char*) * *count);
*changelogtext = malloc(sizeof(char*) * *count);
int i = 0;
for (xmlNode *entry=parent->children; entry; entry=entry->next) {
if (entry->type == XML_ELEMENT_NODE && !strcmp((char*)entry->name, "changelog")) {
(*changelogtime)[i] = atoi((char*)findXMLAttributeByName(entry, "date"));
(*changelogrelease)[i] = strdup((char*)findXMLAttributeByName(entry, "author"));
(*changelogtext)[i] = strdup((char*)entry->children->content);
i++;
}
}
}
void getXMLPackageNFV(xmlNode *parent, char ***name, void getXMLPackageNFV(xmlNode *parent, char ***name,
uint_32 **flags, char ***version, int *count) { uint_32 **flags, char ***version, int *count) {
@ -1118,8 +1147,33 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) {
newheadersourcelist->source = basenames; newheadersourcelist->source = basenames;
newheadersourcelist->filenamecount = 0; newheadersourcelist->filenamecount = 0;
// TODO: changelog // Changelog
if (mode & GENHEADER_CHANGELOG) {
int changelogcount;
uint_32 *changelogtime;
char **changelogrelease;
char **changelogtext;
getXMLPackageChangelog(other_node, &changelogtime, &changelogrelease,
&changelogtext, &changelogcount);
changelog = getPackageChangelog(changelogtime, changelogrelease,
changelogtext, changelogcount, newheadersourcelist);
while (changelog) {
if ((!changelog->pkg) || (!changelog->text)) {
snprintf(warning, PATH_MAX, "missing changelog name and/or text");
logmsg(LOG_WARNING,
"%s: missing changelog name and/or text",
newheadersourcelist->name);
addWarning(newheadersourcelist, warning);
}
changelog = changelog->next;
}
} else {
newheadersourcelist->changelog = NULL;
}
// Add newheadersourcelist to sourceheaderlist
addNewToSourceHeaderList(newheadersourcelist, ct, altrepository); addNewToSourceHeaderList(newheadersourcelist, ct, altrepository);
} }
} }
@ -1196,7 +1250,16 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) {
newheadersourcelist->requirecount = requirecount; newheadersourcelist->requirecount = requirecount;
if (mode & GENHEADER_CHANGELOG) { if (mode & GENHEADER_CHANGELOG) {
changelog = getPackageChangelog(h, newheadersourcelist); int count;
uint_32 *changelogtime = headerGetUIntArrayEntry(h,
RPMTAG_CHANGELOGTIME, &count);
char **changelogrelease = headerGetStringArrayEntry(h,
RPMTAG_CHANGELOGNAME, &count);
char **changelogtext = headerGetStringArrayEntry(h,
RPMTAG_CHANGELOGTEXT, &count);
changelog = getPackageChangelog(changelogtime, changelogrelease,
changelogtext, count, newheadersourcelist);
while (changelog) { while (changelog) {
if ((!changelog->pkg) || (!changelog->text)) { if ((!changelog->pkg) || (!changelog->text)) {
snprintf(warning, PATH_MAX, "missing changelog name and/or text"); snprintf(warning, PATH_MAX, "missing changelog name and/or text");

View File

@ -1,7 +1,7 @@
/* /*
* distromatic - tool for RPM based repositories * distromatic - tool for RPM based repositories
* *
* Copyright (C) 2004-2020 by Silvan Calarco <silvan.calarco@mambasoft.it> * Copyright (C) 2004-2021 by Silvan Calarco <silvan.calarco@mambasoft.it>
* Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com> * Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com>
*/ */
@ -65,7 +65,8 @@ struct Packager *
getPackagerByName(char *name, int create); getPackagerByName(char *name, int create);
struct changeLog * struct changeLog *
getPackageChangelog(Header h, struct headerSourceList *headersourcelist); getPackageChangelog(uint_32 *changelogtime, char **changelogrelease,
char **changelogtext, int count, struct headerSourceList* headersource);
char *changeLogTimeStr(char buf[16], struct changeLog *changelog); char *changeLogTimeStr(char buf[16], struct changeLog *changelog);