Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkghash: use iterator every where possible
Baptiste Daroussin committed 4 years ago
commit 284d5ef57485dc169c44acce3c09d92be90ec1fa
parent 06b59b5
3 files changed +23 -21
modified libpkg/pkg_manifest.c
@@ -1099,10 +1099,11 @@ pkg_emit_object(struct pkg *pkg, short flags)
	pkg_debug(4, "Emitting users");
	seq = NULL;
	buf = NULL;
-
	while (pkg_users(pkg, &buf) == EPKG_OK) {
+
	it = pkghash_iterator(pkg->users);
+
	while (pkghash_next(&it)) {
		if (seq == NULL)
			seq = ucl_object_typed_new(UCL_ARRAY);
-
		ucl_array_append(seq, ucl_object_fromstring(buf));
+
		ucl_array_append(seq, ucl_object_fromstring(it.key));
	}
	if (seq)
		ucl_object_insert_key(top, seq, "users", 5, false);
@@ -1110,10 +1111,11 @@ pkg_emit_object(struct pkg *pkg, short flags)
	pkg_debug(4, "Emitting groups");
	seq = NULL;
	buf = NULL;
-
	while (pkg_groups(pkg, &buf) == EPKG_OK) {
+
	it = pkghash_iterator(pkg->users);
+
	while (pkghash_next(&it)) {
		if (seq == NULL)
			seq = ucl_object_typed_new(UCL_ARRAY);
-
		ucl_array_append(seq, ucl_object_fromstring(buf));
+
		ucl_array_append(seq, ucl_object_fromstring(it.key));
	}
	if (seq)
		ucl_object_insert_key(top, seq, "groups", 6, false);
modified libpkg/pkg_printf.c
@@ -1182,7 +1182,6 @@ format_groups(xstring *buf, const void *data, struct percent_esc *p)
	if (p->flags & (PP_ALTERNATE_FORM1|PP_ALTERNATE_FORM2))
		return (list_count(buf, pkg_list_count(pkg, PKG_GROUPS), p));
	else {
-
		char	*group = NULL;
		int	 count;

		set_list_defaults(p, "%Gn\n", "");
@@ -1190,13 +1189,14 @@ format_groups(xstring *buf, const void *data, struct percent_esc *p)
		count = 1;
		fflush(p->sep_fmt->fp);
		fflush(p->item_fmt->fp);
-
		while(pkg_groups(pkg, &group) == EPKG_OK) {
+
		pkghash_it it = pkghash_iterator(pkg->users);
+
		while (pkghash_next(&it)) {
			if (count > 1)
				iterate_item(buf, pkg, p->sep_fmt->buf,
-
					     group, count, PP_G);
+
					     it.key, count, PP_G);

			iterate_item(buf, pkg,p->item_fmt->buf,
-
				     group, count, PP_G);
+
				     it.key, count, PP_G);
			count++;
		}
	}
@@ -1469,7 +1469,6 @@ format_users(xstring *buf, const void *data, struct percent_esc *p)
	if (p->flags & (PP_ALTERNATE_FORM1|PP_ALTERNATE_FORM2))
		return (list_count(buf, pkg_list_count(pkg, PKG_USERS), p));
	else {
-
		char	*user = NULL;
		int	 count;

		set_list_defaults(p, "%Un\n", "");
@@ -1477,13 +1476,14 @@ format_users(xstring *buf, const void *data, struct percent_esc *p)
		count = 1;
		fflush(p->sep_fmt->fp);
		fflush(p->item_fmt->fp);
-
		while (pkg_users(pkg, &user) == EPKG_OK) {
+
		pkghash_it it = pkghash_iterator(pkg->users);
+
		while (pkghash_next(&it)) {
			if (count > 1)
				iterate_item(buf, pkg, p->sep_fmt->buf,
-
					     user, count, PP_U);
+
					     it.key, count, PP_U);

			iterate_item(buf, pkg, p->item_fmt->buf,
-
				     user, count, PP_U);
+
				     it.key, count, PP_U);
			count++;
		}
	}
modified libpkg/pkgdb.c
@@ -1752,7 +1752,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int forced,
	struct pkg_conflict	*conflict = NULL;
	struct pkg_config_file	*cf = NULL;
	struct pkgdb_it		*it = NULL;
-
	char			*buf, *msg = NULL;
+
	char			*msg = NULL;

	sqlite3			*s;

@@ -1957,12 +1957,12 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int forced,
	 * Insert users
	 */

-
	buf = NULL;
-
	while (pkg_users(pkg, &buf) == EPKG_OK) {
-
		if (run_prstmt(USERS1, buf)
+
	hit = pkghash_iterator(pkg->users);
+
	while (pkghash_next(&hit)) {
+
		if (run_prstmt(USERS1, hit.key)
		    != SQLITE_DONE
		    ||
-
		    run_prstmt(USERS2, package_id, buf)
+
		    run_prstmt(USERS2, package_id, hit.key)
		    != SQLITE_DONE) {
			ERROR_STMT_SQLITE(s, STMT(USERS2));
			goto cleanup;
@@ -1973,12 +1973,12 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int forced,
	 * Insert groups
	 */

-
	buf = NULL;
-
	while (pkg_groups(pkg, &buf) == EPKG_OK) {
-
		if (run_prstmt(GROUPS1, buf)
+
	hit = pkghash_iterator(pkg->groups);
+
	while (pkghash_next(&hit)) {
+
		if (run_prstmt(GROUPS1, hit.key)
		    != SQLITE_DONE
		    ||
-
		    run_prstmt(GROUPS2, package_id, buf)
+
		    run_prstmt(GROUPS2, package_id, hit.key)
		    != SQLITE_DONE) {
			ERROR_STMT_SQLITE(s, STMT(GROUPS2));
			goto cleanup;