From: Tomas Mlcoch Date: Tue, 10 Jan 2012 14:49:28 +0000 (+0100) Subject: Add support for parsing changelogs into parse_header. X-Git-Tag: upstream/0.2.1~607 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7653db011bbc12f56f27d05a4b0ef15bee2ad3f6;p=services%2Fcreaterepo_c.git Add support for parsing changelogs into parse_header. --- diff --git a/parsehdr.c b/parsehdr.c index 1c53ee8..0e0c46e 100644 --- a/parsehdr.c +++ b/parsehdr.c @@ -6,7 +6,7 @@ Package *parse_header(Header hdr, gint64 mtime, gint64 size, const char *checksum, const char *checksum_type, - const char *location_href, const char *location_base, + const char *location_href, const char *location_base, int changelog_limit, gint64 hdr_start, gint64 hdr_end) { Package *pkg = NULL; @@ -173,7 +173,7 @@ Package *parse_header(Header hdr, gint64 mtime, gint64 size, const char *checksu } // Skip duplicate files - gpointer *value; + gpointer value; if (g_hash_table_lookup_extended(ap_hashtable, filename, NULL, &value)) { struct ap_value_struct *ap_value = value; if (!strcmp(ap_value->flags, flags) && @@ -244,13 +244,63 @@ Package *parse_header(Header hdr, gint64 mtime, gint64 size, const char *checksu g_hash_table_remove_all(provided_hashtable); g_hash_table_remove_all(ap_hashtable); + rpmtdFree(filenames); + rpmtdFree(fileflags); + rpmtdFree(fileversions); + + + // + // Changelogs + // + + rpmtd changelogtimes = rpmtdNew(); + rpmtd changelognames = rpmtdNew(); + rpmtd changelogtexts = rpmtdNew(); + + if (headerGet(hdr, RPMTAG_CHANGELOGTIME, changelogtimes, flags) && + headerGet(hdr, RPMTAG_CHANGELOGNAME, changelognames, flags) && + headerGet(hdr, RPMTAG_CHANGELOGTEXT, changelogtexts, flags)) + { + gint64 last_time = 0; + gint64 time_offset = 1; + while ((rpmtdNext(changelogtimes) != -1) && + (rpmtdNext(changelognames) != -1) && + (rpmtdNext(changelogtexts) != -1) && + (changelog_limit > 0)) + { + gint64 time = rpmtdGetNumber(changelogtimes); + if (last_time == time) { + time += time_offset; + time_offset++; + } else { + last_time = time; + time_offset = 1; + } + + ChangelogEntry *changelog = changelog_entry_new(); + changelog->author = rpmtdGetString(changelognames); + changelog->date = time; + changelog->changelog = rpmtdGetString(changelogtexts); + + pkg->changelogs = g_slist_append(pkg->changelogs, changelog); + changelog_limit--; + } + } + + rpmtdFree(changelogtimes); + rpmtdFree(changelognames); + rpmtdFree(changelogtexts); + + return pkg; } struct XmlStruct xml_from_header(Header hdr, gint64 mtime, gint64 size, const char *checksum, const char *checksum_type, - const char *location_href, const char *location_base, gint64 hdr_start, gint64 hdr_end) + const char *location_href, const char *location_base, + int changelog_limit, gint64 hdr_start, gint64 hdr_end) { - Package *pkg = parse_header(hdr, mtime, size, checksum, checksum_type, location_href, location_base, hdr_start, hdr_end); + Package *pkg = parse_header(hdr, mtime, size, checksum, checksum_type, location_href, + location_base, changelog_limit, hdr_start, hdr_end); struct XmlStruct result; result.primary = xml_dump_primary(pkg, NULL); diff --git a/parsehdr.h b/parsehdr.h index 9cfa998..22a2b3f 100644 --- a/parsehdr.h +++ b/parsehdr.h @@ -14,9 +14,9 @@ struct XmlStruct{ Package *parse_header(Header hdr, gint64 mtime, gint64 size, const char *checksum, const char *checksum_type, const char *location_href, const char *location_base, - gint64 hdr_start, gint64 hdr_end); + int changelog_limit, gint64 hdr_start, gint64 hdr_end); struct XmlStruct xml_from_header(Header hdr, gint64 mtime, gint64 size, const char *checksum, const char *checksum_type, const char *location_href, const char *location_base, - gint64 hdr_start, gint64 hdr_end); + int changelog_limit, gint64 hdr_start, gint64 hdr_end); #endif /* __PARSEHDR__ */