Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
groups: implement the display part of pkg install @group
Baptiste Daroussin committed 2 years ago
commit 63dd227ea148dddd4f72543986112b1c725e4937
parent a961579
5 files changed +64 -41
modified libpkg/pkg_checksum.c
@@ -191,16 +191,21 @@ pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
	struct pkg_dep *dep = NULL;
	struct pkg_file *f = NULL;
	int i;
+
	bool is_group = false;

	if (pkg == NULL || type >= PKG_HASH_TYPE_UNKNOWN ||
					destlen < checksum_types[type].hlen)
		return (EPKG_FATAL);
+
	if (pkg_type(pkg) == PKG_GROUP_REMOTE || pkg_type(pkg) == PKG_GROUP_INSTALLED)
+
		is_group = true;

	tll_push_back(entries, pkg_kv_new("name", pkg->name));
-
	tll_push_back(entries, pkg_kv_new("origin", pkg->origin));
-
	if (inc_version)
+
	if (!is_group)
+
		tll_push_back(entries, pkg_kv_new("origin", pkg->origin));
+
	if (inc_version && !is_group)
		tll_push_back(entries, pkg_kv_new("version", pkg->version));
-
	tll_push_back(entries, pkg_kv_new("arch", pkg->arch));
+
	if (!is_group)
+
		tll_push_back(entries, pkg_kv_new("arch", pkg->arch));

	while (pkg_options(pkg, &option) == EPKG_OK) {
		tll_push_back(entries, pkg_kv_new(option->key, option->value));
modified libpkg/pkg_jobs.c
@@ -969,15 +969,6 @@ pkg_jobs_guess_upgrade_candidate(struct pkg_jobs *j, const char *pattern)
}

static int
-
pkg_jobs_find_group_upgrade(struct pkg_jobs *j __unused, const char *pattern __unused, match_t m __unused)
-
{
-
	int rc = EPKG_FATAL;
-
	struct pkg_repo_it *it;
-

-
	return (rc);
-
}
-

-
static int
pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)
{
	struct pkg *p = NULL;
@@ -992,10 +983,6 @@ pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)
			PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;
	struct pkg_job_universe_item *unit = NULL;

-
	/* We are looking for groups */
-
	if (*pattern == '@')
-
		return (pkg_jobs_find_group_upgrade(j, pattern, m));
-

	if ((it = pkgdb_repo_query(j->db, pattern, m, j->reponame)) == NULL)
		return (rc);

@@ -1013,7 +1000,7 @@ pkg_jobs_find_upgrade(struct pkg_jobs *j, const char *pattern, match_t m)
	while (it != NULL && pkgdb_it_next(it, &p, flags) == EPKG_OK) {
		if (checklocal && pkg_jobs_installed_local_pkg(j, p) != EPKG_OK)
			continue;
-
		if (pattern != NULL) {
+
		if (pattern != NULL && *pattern != '@') {
			with_version = strcmp(p->name, pattern);
		} else {
			with_version = 0;
modified libpkg/pkg_jobs_universe.c
@@ -68,19 +68,20 @@ pkg_jobs_universe_get_local(struct pkg_jobs_universe *universe,
		cur = unit;
		found = NULL;
		do {
-
			if (cur->pkg->type == PKG_INSTALLED) {
+
			if (cur->pkg->type == PKG_INSTALLED || cur->pkg->type == PKG_GROUP_INSTALLED) {
				found = cur;
				break;
			}
			cur = cur->prev;
		} while (cur != unit);

-
		if (found) {
+
		if (found && found->pkg->type == PKG_INSTALLED) {
			pkgdb_ensure_loaded(universe->j->db, unit->pkg, flag);
			return (unit->pkg);
		}
	}

+
	/* XX TODO query local groups */
	if ((it = pkgdb_query(universe->j->db, uid, MATCH_INTERNAL)) == NULL)
		return (NULL);

modified libpkg/repo/binary/query.c
@@ -97,7 +97,7 @@ pkg_repo_binary_it_new(struct pkg_repo *repo, sqlite3_stmt *s, short flags)
}

static struct pkg_repo_it *
-
pkg_repo_binary_group_it_new(struct pkg_repo *repo __unused, ucl_object_t *matching)
+
pkg_repo_binary_group_it_new(struct pkg_repo *repo, ucl_object_t *matching)
{
	struct pkg_repo_group *prg;
	struct pkg_repo_it *it;
@@ -105,6 +105,7 @@ pkg_repo_binary_group_it_new(struct pkg_repo *repo __unused, ucl_object_t *match
	it = xcalloc(1, sizeof(*it));
	prg = xcalloc(1, sizeof(*prg));
	prg->groups = matching;
+
	it->repo = repo;
	it->ops = &pkg_repo_binary_group_it_ops;
	it->data = prg;

@@ -138,6 +139,7 @@ pkg_repo_binary_group_it_next(struct pkg_repo_it *it, struct pkg **pkg_p, unsign
	xasprintf(&(*pkg_p)->uid, "@%s", (*pkg_p)->name);
	o = ucl_object_find_key(el, "comment");
	xasprintf(&(*pkg_p)->comment, ucl_object_tostring(o));
+
	pkg_kv_add(&(*pkg_p)->annotations, "repository",   it->repo->name, "annotation");

	return (EPKG_OK);
}
@@ -574,7 +576,7 @@ pkg_repo_binary_groupsearch(struct pkg_repo *repo, const char *pattern, match_t
		case MATCH_ALL:
			break;
		case MATCH_INTERNAL:
-
			if (strcmp(cmp, pattern) == 0)
+
			if (strcmp(cmp, pattern) != 0)
				continue;
			break;
		case MATCH_EXACT:
modified src/utils.c
@@ -65,6 +65,8 @@ struct jobs_sum_number {
	int upgrade;
	int delete;
	int fetch;
+
	int group_install;
+
	int group_upgrade;
};

void
@@ -716,6 +718,8 @@ enum pkg_display_type {
	PKG_DISPLAY_DOWNGRADE,
	PKG_DISPLAY_REINSTALL,
	PKG_DISPLAY_FETCH,
+
	PKG_DISPLAY_GROUP_INSTALL,
+
	PKG_DISPLAY_GROUP_UPGRADE,
	PKG_DISPLAY_MAX
};
struct pkg_solved_display {
@@ -786,27 +790,37 @@ set_jobs_summary_pkg(struct pkg_jobs *jobs, struct pkg *new_pkg,
			nbtodl += 1;
		}

-
		if (old_pkg != NULL) {
-
			switch (pkg_version_change_between(new_pkg, old_pkg)) {
-
			case PKG_DOWNGRADE:
-
				it->display_type = PKG_DISPLAY_DOWNGRADE;
-
				sum->downgrade++;
-
				break;
-
			case PKG_REINSTALL:
-
				it->display_type = PKG_DISPLAY_REINSTALL;
-
				sum->reinstall++;
-
				break;
-
			case PKG_UPGRADE:
-
				it->display_type = PKG_DISPLAY_UPGRADE;
-
				sum->upgrade++;
-
				break;
+
		if (pkg_type(new_pkg) == PKG_GROUP_REMOTE) {
+
			if (old_pkg == NULL) {
+
				it->display_type = PKG_DISPLAY_GROUP_INSTALL;
+
				sum->group_install++;
+
			} else {
+
				it->display_type = PKG_DISPLAY_GROUP_UPGRADE;
+
				sum->group_upgrade++;
			}
-
			*oldsize += oldflatsize;
-
			*newsize += flatsize;
		} else {
-
			it->display_type = PKG_DISPLAY_INSTALL;
-
			sum->install++;
-
			*newsize += flatsize;
+
			if (old_pkg != NULL) {
+
				switch (pkg_version_change_between(new_pkg, old_pkg)) {
+
				case PKG_DOWNGRADE:
+
					it->display_type = PKG_DISPLAY_DOWNGRADE;
+
					sum->downgrade++;
+
					break;
+
				case PKG_REINSTALL:
+
					it->display_type = PKG_DISPLAY_REINSTALL;
+
					sum->reinstall++;
+
					break;
+
				case PKG_UPGRADE:
+
					it->display_type = PKG_DISPLAY_UPGRADE;
+
					sum->upgrade++;
+
					break;
+
				}
+
				*oldsize += oldflatsize;
+
				*newsize += flatsize;
+
			} else {
+
				it->display_type = PKG_DISPLAY_INSTALL;
+
				sum->install++;
+
				*newsize += flatsize;
+
			}
		}
		break;
	case PKG_SOLVED_DELETE:
@@ -938,6 +952,18 @@ display_summary_item(struct pkg_solved_display *it, int64_t dlsize)
		printf("(%s: %.2f%% of the %s to download)\n", size,
		    ((double)100 * pkgsize) / (double)dlsize, tlsize);
		break;
+
	case PKG_DISPLAY_GROUP_UPGRADE:
+
		pkg_printf("\t%n", it->new, it->new);
+
		if (pkg_repos_total_count() > 1)
+
			pkg_printf(" [%N]", it->new);
+
		printf("\n");
+
		break;
+
	case PKG_DISPLAY_GROUP_INSTALL:
+
		pkg_printf("\t@%n", it->new, it->new);
+
		if (pkg_repos_total_count() > 1)
+
			pkg_printf(" [%N]", it->new);
+
		printf("\n");
+
		break;
	default:
		break;
	}
@@ -948,10 +974,12 @@ static const char* pkg_display_messages[PKG_DISPLAY_MAX + 1] = {
	[PKG_DISPLAY_LOCKED] = "Installed packages LOCKED",
	[PKG_DISPLAY_DELETE] = "Installed packages to be REMOVED",
	[PKG_DISPLAY_INSTALL] = "New packages to be INSTALLED",
-
	[PKG_DISPLAY_UPGRADE] = "Installed packages to be UPGRADED",
+
	[PKG_DISPLAY_GROUP_UPGRADE] = "New groups to be UPGRADED",
	[PKG_DISPLAY_DOWNGRADE] = "Installed packages to be DOWNGRADED",
	[PKG_DISPLAY_REINSTALL] = "Installed packages to be REINSTALLED",
	[PKG_DISPLAY_FETCH] = "New packages to be FETCHED",
+
	[PKG_DISPLAY_GROUP_INSTALL] = "New groups to be INSTALLED",
+
	[PKG_DISPLAY_UPGRADE] = "Installed packages to be UPGRADED",
	[PKG_DISPLAY_MAX] = NULL
};