Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
messages: convert to tllist
Baptiste Daroussin committed 3 years ago
commit 0b8ce042cbcb4572fbd9c3ff3bfef9e34fded5bf
parent 52ab097
8 files changed +30 -36
modified libpkg/pkg.c
@@ -112,7 +112,7 @@ pkg_free(struct pkg *pkg)
	tll_free_and_free(pkg->licenses, free);
	pkg->flags &= ~PKG_LOAD_LICENSES;

-
	DL_FREE(pkg->message, pkg_message_free);
+
	tll_free_and_free(pkg->message, pkg_message_free);
	tll_free_and_free(pkg->annotations, pkg_kv_free);

	if (pkg->rootfd != -1)
@@ -186,7 +186,6 @@ pkg_vset(struct pkg *pkg, va_list ap)
	int attr;
	const char *buf;
	ucl_object_t *obj;
-
	struct pkg_message *msg;

	while ((attr = va_arg(ap, int)) > 0) {
		if (attr >= PKG_NUM_FIELDS || attr <= 0) {
@@ -221,9 +220,7 @@ pkg_vset(struct pkg *pkg, va_list ap)
			(void)va_arg(ap, const char *);
			break;
		case PKG_MESSAGE:
-
			LL_FOREACH(pkg->message, msg) {
-
				pkg_message_free(msg);
-
			}
+
			tll_free_and_free(pkg->message, pkg_message_free);
			buf = va_arg(ap, const char *);
			if (*buf == '[') {
				pkg_message_from_str(pkg, buf, strlen(buf));
@@ -1418,7 +1415,7 @@ pkg_is_installed(struct pkgdb *db, const char *name)
bool
pkg_has_message(struct pkg *p)
{
-
	return (p->message != NULL);
+
	return (tll_length(p->message) > 0);
}

bool
@@ -1515,7 +1512,7 @@ pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj)
		msg = xcalloc(1, sizeof(*msg));
		msg->str = xstrdup(ucl_object_tostring(obj));
		msg->type = PKG_MESSAGE_ALWAYS;
-
		DL_APPEND(pkg->message, msg);
+
		tll_push_back(pkg->message, msg);
		return (EPKG_OK);
	}

@@ -1551,7 +1548,7 @@ pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj)
				    " message will always be printed");
		}
		if (msg->type != PKG_MESSAGE_UPGRADE) {
-
			DL_APPEND(pkg->message, msg);
+
			tll_push_back(pkg->message, msg);
			continue;
		}

@@ -1565,7 +1562,7 @@ pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj)
			msg->maximum_version = xstrdup(ucl_object_tostring(elt));
		}

-
		DL_APPEND(pkg->message, msg);
+
		tll_push_back(pkg->message, msg);
	}

	return (EPKG_OK);
@@ -1621,7 +1618,8 @@ pkg_message_to_ucl(const struct pkg *pkg)
	ucl_object_t *obj;

	array = ucl_object_typed_new(UCL_ARRAY);
-
	LL_FOREACH(pkg->message, msg) {
+
	tll_foreach(pkg->message, t) {
+
		msg = t->item;
		obj = ucl_object_typed_new (UCL_OBJECT);

		ucl_object_insert_key(obj,
@@ -1670,9 +1668,8 @@ pkg_message_to_str(struct pkg *pkg)
	ucl_object_t *obj;
	char *ret = NULL;

-
	if (pkg->message == NULL) {
+
	if (tll_length(pkg->message) <= 0)
		return (NULL);
-
	}

	obj = pkg_message_to_ucl(pkg);
	ret = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
modified libpkg/pkg_add.c
@@ -1206,7 +1206,8 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
			pkg_emit_install_finished(pkg, local);
	}

-
	LL_FOREACH(pkg->message, msg) {
+
	tll_foreach(pkg->message, m) {
+
		msg = m->item;
		msgstr = NULL;
		if (msg->type == PKG_MESSAGE_ALWAYS) {
			msgstr = msg->str;
@@ -1240,7 +1241,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
			fprintf(message->fp, "--\n%s\n", msgstr);
		}
	}
-
	if (pkg->message != NULL && message != NULL) {
+
	if (pkg_has_message(pkg) && message != NULL) {
		fflush(message->fp);
		pkg_emit_message(message->buf);
		xstring_free(message);
modified libpkg/pkg_delete.c
@@ -56,7 +56,6 @@
int
pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
{
-
	struct pkg_message	*msg;
	xstring		*message = NULL;
	int		 ret;
	bool		 handle_rc = false;
@@ -115,17 +114,17 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)

	if ((flags & PKG_DELETE_UPGRADE) == 0) {
		pkg_emit_deinstall_finished(pkg);
-
		LL_FOREACH(pkg->message, msg) {
-
			if (msg->type == PKG_MESSAGE_REMOVE) {
+
		tll_foreach(pkg->message, m) {
+
			if (m->item->type == PKG_MESSAGE_REMOVE) {
				if (message == NULL) {
					message = xstring_new();
					pkg_fprintf(message->fp, "Message from "
					    "%n-%v:\n", pkg, pkg);
				}
-
				fprintf(message->fp, "%s\n", msg->str);
+
				fprintf(message->fp, "%s\n", m->item->str);
			}
		}
-
		if (pkg->message != NULL && message != NULL) {
+
		if (pkg_has_message(pkg) && message != NULL) {
			fflush(message->fp);
			pkg_emit_message(message->buf);
			xstring_free(message);
modified libpkg/pkg_manifest.c
@@ -1278,7 +1278,7 @@ pkg_emit_object(struct pkg *pkg, short flags)
	}

	pkg_debug(4, "Emitting message");
-
	if (pkg->message != NULL) {
+
	if (pkg_has_message(pkg))  {
		ucl_object_insert_key(top,
			pkg_message_to_ucl(pkg),
			"messages", sizeof("messages") - 1, false);
modified libpkg/pkg_ports.c
@@ -688,7 +688,7 @@ apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_a
				else if (strcasecmp(ucl_object_tostring(elt), "upgrade") == 0)
					msg->type = PKG_MESSAGE_UPGRADE;
			}
-
			DL_APPEND(p->pkg->message, msg);
+
			tll_push_back(p->pkg->message, msg);
		}
	}

@@ -1193,7 +1193,6 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
	const char *location;
	int rc = EPKG_OK;
	xstring *message;
-
	struct pkg_message *msg;

	if (db != NULL && pkg_is_installed(db, pkg->name) != EPKG_END) {
		return(EPKG_INSTALLED);
@@ -1238,15 +1237,15 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,

	if (rc == EPKG_OK) {
		pkg_emit_install_finished(pkg, NULL);
-
		if (pkg->message != NULL)
+
		if (pkg_has_message(pkg))
			message = xstring_new();
-
		LL_FOREACH(pkg->message, msg) {
-
			if (msg->type == PKG_MESSAGE_ALWAYS ||
-
			    msg->type == PKG_MESSAGE_INSTALL) {
-
				fprintf(message->fp, "%s\n", msg->str);
+
		tll_foreach(pkg->message, m) {
+
			if (m->item->type == PKG_MESSAGE_ALWAYS ||
+
			    m->item->type == PKG_MESSAGE_INSTALL) {
+
				fprintf(message->fp, "%s\n", m->item->str);
			}
		}
-
		if (pkg->message != NULL) {
+
		if (pkg_has_message(pkg)) {
			fflush(message->fp);
			if (message->buf[0] != '\0') {
				pkg_emit_message(message->buf);
modified libpkg/pkg_printf.c
@@ -1273,7 +1273,8 @@ format_message(xstring *buffer, const void *data, struct percent_esc *p)
	struct pkg_message	*msg;
	char			*message;

-
	LL_FOREACH(pkg->message, msg) {
+
	tll_foreach(pkg->message, m) {
+
		msg = m->item;
		if (bufmsg == NULL) {
			bufmsg = xstring_new();
		} else {
modified libpkg/pkgdb_iterator.c
@@ -902,14 +902,11 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
					}
					else {
						struct pkg_message *message;
-
						message = xcalloc(1, sizeof(*pkg->message));
+
						message = xcalloc(1, sizeof(*message));
						message->str = xstrdup(msg);
-
						DL_APPEND(pkg->message, message);
+
						tll_push_back(pkg->message, message);
					}
				}
-
				else {
-
					pkg->message = NULL;
-
				}
				break;
			case PKG_NAME:
				pkg->name = xstrdup(sqlite3_column_text(stmt, icol));
modified libpkg/private/pkg.h
@@ -177,6 +177,7 @@ struct pkg_repo_it;
struct pkg_repo;
struct pkg_message;
struct pkg_lua_script;
+
typedef tll(struct pkg_message *) messages_t;

struct pkg {
	bool		 direct;
@@ -197,7 +198,7 @@ struct pkg {
	char			*uid;
	char			*digest;
	char			*old_digest;
-
	struct pkg_message	*message;
+
	messages_t		 message;
	char			*prefix;
	char			*comment;
	char			*desc;
@@ -308,7 +309,6 @@ struct pkg_message {
	char			*minimum_version;
	char			*maximum_version;
	pkg_message_t		 type;
-
	struct pkg_message	*next, *prev;
};

struct pkg_lua_script {