Skip to content

Commit

Permalink
last conversion from uthash to pkghash
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Aug 23, 2021
1 parent 282b83b commit 486a5b7
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 57 deletions.
19 changes: 14 additions & 5 deletions libpkg/pkg_cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,21 @@ static int
cudf_emit_request_packages(const char *op, struct pkg_jobs *j, FILE *f)
{
struct pkg_job_request *req, *tmp;
int column = 0;
int column = 0, cnt = 0, max;
bool printed = false;
pkghash_it it;

max = pkghash_count(j->request_add);
if (fprintf(f, "%s: ", op) < 0)
return (EPKG_FATAL);
HASH_ITER(hh, j->request_add, req, tmp) {
it = pkghash_iterator(j->request_add);
while (pkghash_next(&it)) {
req = it.value;
cnt++;
if (req->skip)
continue;
if (cudf_print_element(f, req->item->pkg->uid,
(req->hh.next != NULL), &column) < 0) {
(max > cnt), &column) < 0) {
return (EPKG_FATAL);
}
printed = true;
Expand All @@ -206,11 +211,15 @@ cudf_emit_request_packages(const char *op, struct pkg_jobs *j, FILE *f)
printed = false;
if (fprintf(f, "remove: ") < 0)
return (EPKG_FATAL);
HASH_ITER(hh, j->request_delete, req, tmp) {
max = pkghash_count(j->request_delete);
it = pkghash_iterator(j->request_delete);
while (pkghash_next(&it)) {
req = it.value;
cnt++;
if (req->skip)
continue;
if (cudf_print_element(f, req->item->pkg->uid,
(req->hh.next != NULL), &column) < 0) {
(max > cnt), &column) < 0) {
return (EPKG_FATAL);
}
printed = true;
Expand Down
98 changes: 60 additions & 38 deletions libpkg/pkg_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,22 @@ pkg_jobs_request_free(struct pkg_job_request *req)
void
pkg_jobs_free(struct pkg_jobs *j)
{
struct pkg_job_request *req, *tmp;
pkghash_it it;

if (j == NULL)
return;

HASH_ITER(hh, j->request_add, req, tmp) {
HASH_DEL(j->request_add, req);
pkg_jobs_request_free(req);
}
HASH_ITER(hh, j->request_delete, req, tmp) {
HASH_DEL(j->request_delete, req);
pkg_jobs_request_free(req);
}
it = pkghash_iterator(j->request_add);
while (pkghash_next(&it))
pkg_jobs_request_free(it.value);
pkghash_destroy(j->request_add);
j->request_add = NULL;

it = pkghash_iterator(j->request_delete);
while (pkghash_next(&it))
pkg_jobs_request_free(it.value);
pkghash_destroy(j->request_delete);
j->request_delete = NULL;

pkg_jobs_universe_free(j->universe);
LL_FREE(j->jobs, free);
Expand Down Expand Up @@ -294,16 +297,16 @@ pkg_jobs_iter(struct pkg_jobs *jobs, void **iter,
}

static struct pkg_job_request_item*
pkg_jobs_add_req_from_universe(struct pkg_job_request **head,
struct pkg_job_universe_item *un, bool local, bool automatic)
pkg_jobs_add_req_from_universe(pkghash **head, struct pkg_job_universe_item *un,
bool local, bool automatic)
{
struct pkg_job_request *req;
struct pkg_job_request_item *nit;
struct pkg_job_universe_item *uit;
bool new_req = false;

assert(un != NULL);
HASH_FIND_STR(*head, un->pkg->uid, req);
req = pkghash_get_value(*head, un->pkg->uid);

if (req == NULL) {
req = xcalloc(1, sizeof(*req));
Expand All @@ -330,7 +333,7 @@ pkg_jobs_add_req_from_universe(struct pkg_job_request **head,

if (new_req) {
if (req->item != NULL) {
HASH_ADD_KEYPTR(hh, *head, un->pkg->uid, strlen(un->pkg->uid), req);
pkghash_safe_add(*head, un->pkg->uid, req, NULL);
}
else {
free(req);
Expand All @@ -344,7 +347,8 @@ pkg_jobs_add_req_from_universe(struct pkg_job_request **head,
static struct pkg_job_request_item*
pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
{
struct pkg_job_request *req, **head;
pkghash **head;
struct pkg_job_request *req;
struct pkg_job_request_item *nit;
struct pkg_job_universe_item *un;
int rc;
Expand All @@ -370,7 +374,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
* digest. In turn, that means that two upgrade candidates are equal,
* we thus won't do anything with this item, as it is definitely useless
*/
HASH_FIND_STR(*head, pkg->uid, req);
req = pkghash_get_value(*head, pkg->uid);
if (req != NULL) {
DL_FOREACH(req->item, nit) {
if (nit->unit == un)
Expand Down Expand Up @@ -398,7 +402,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
return (NULL);
}

HASH_FIND_STR(*head, pkg->uid, req);
req = pkghash_get_value(*head, pkg->uid);

nit = xcalloc(1, sizeof(*nit));
nit->pkg = pkg;
Expand All @@ -407,7 +411,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
if (req == NULL) {
/* Allocate new unique request item */
req = xcalloc(1, sizeof(*req));
HASH_ADD_KEYPTR(hh, *head, pkg->uid, strlen(pkg->uid), req);
pkghash_safe_add(*head, pkg->uid, req, NULL);
}

/* Append candidate to the list of candidates */
Expand All @@ -428,19 +432,22 @@ pkg_jobs_process_add_request(struct pkg_jobs *j)
bool force = j->flags & PKG_FLAG_FORCE,
reverse = j->flags & PKG_FLAG_RECURSIVE,
upgrade = j->type == PKG_JOBS_UPGRADE;
struct pkg_job_request *req, *tmp, *found;
struct pkg_job_request *req;
struct pkg_job_request_item *it;
struct pkg_job_universe_item *un, *cur;
struct pkg_dep *d;
struct pkg *lp;
int (*deps_func)(const struct pkg *pkg, struct pkg_dep **d);
kvec_t(struct pkg_job_universe_item *) to_process;
pkghash_it hit;

if (!upgrade && !reverse)
return;

kv_init(to_process);
HASH_ITER(hh, j->request_add, req, tmp) {
hit = pkghash_iterator(j->request_add);
while (pkghash_next(&hit)) {
req = hit.value;
it = req->item;

if (reverse)
Expand All @@ -459,8 +466,7 @@ pkg_jobs_process_add_request(struct pkg_jobs *j)
/*
* Do not add duplicated upgrade candidates
*/
HASH_FIND_STR(j->request_add, d->uid, found);
if (found != NULL)
if (pkghash_get(j->request_add, d->uid))
continue;

pkg_debug(4, "adding dependency %s to request", d->uid);
Expand Down Expand Up @@ -505,11 +511,12 @@ static int
pkg_jobs_process_delete_request(struct pkg_jobs *j)
{
bool force = j->flags & PKG_FLAG_FORCE;
struct pkg_job_request *req, *tmp, *found;
struct pkg_job_request *req;
struct pkg_dep *d = NULL;
struct pkg *lp;
int rc = EPKG_OK;
kvec_t(struct pkg *) to_process;
pkghash_it it;

if (force)
return (EPKG_OK);
Expand All @@ -518,11 +525,12 @@ pkg_jobs_process_delete_request(struct pkg_jobs *j)
/*
* Need to add also all reverse deps here
*/
HASH_ITER(hh, j->request_delete, req, tmp) {
it = pkghash_iterator(j->request_delete);
while (pkghash_next(&it)) {
req = it.value;
d = NULL;
while (pkg_rdeps(req->item->pkg, &d) == EPKG_OK) {
HASH_FIND_STR(j->request_delete, d->uid, found);
if (found)
if (pkghash_get(j->request_delete, d->uid))
continue;

lp = pkg_jobs_universe_get_local(j->universe, d->uid, 0);
Expand Down Expand Up @@ -1067,7 +1075,7 @@ pkg_jobs_find_remote_pattern(struct pkg_jobs *j, struct job_pattern *jp)
pkg->type = PKG_FILE;
pkg_jobs_add_req(j, pkg);

HASH_FIND_STR(j->request_add, pkg->uid, req);
req = pkghash_get_value(j->request_add, pkg->uid);
if (req != NULL)
req->item->jp = jp;
}
Expand Down Expand Up @@ -1321,7 +1329,7 @@ pkg_jobs_propagate_automatic(struct pkg_jobs *j)
* For packages that are alone in the installation list
* we search them in the corresponding request
*/
HASH_FIND_STR(j->request_add, unit->pkg->uid, req);
req = pkghash_get_value(j->request_add, unit->pkg->uid);
if ((req == NULL || req->automatic) &&
unit->pkg->type != PKG_INSTALLED) {
automatic = true;
Expand Down Expand Up @@ -1366,7 +1374,7 @@ pkg_jobs_propagate_automatic(struct pkg_jobs *j)
*
* See #1374
*/
HASH_FIND_STR(j->request_add, unit->pkg->uid, req);
req = pkghash_get_value(j->request_add, unit->pkg->uid);
if ((req == NULL || req->automatic)) {
automatic = true;
pkg_debug(2, "set automatic flag for %s", unit->pkg->uid);
Expand Down Expand Up @@ -1394,7 +1402,7 @@ pkg_jobs_find_deinstall_request(struct pkg_job_universe_item *item,
return (NULL);
}

HASH_FIND_STR(j->request_delete, pkg->uid, found);
found = pkghash_get_value(j->request_delete, pkg->uid);
if (found == NULL) {
while (pkg_deps(pkg, &d) == EPKG_OK) {
dep_item = pkg_jobs_universe_find(j->universe, d->uid);
Expand Down Expand Up @@ -1590,8 +1598,9 @@ jobs_solve_full_upgrade(struct pkg_jobs *j)
size_t elt_num = 0;
char sqlbuf[256];
struct pkg_jobs_install_candidate *candidates, *c;
struct pkg_job_request *req, *rtmp;
struct pkg_job_request *req;
struct pkgdb_it *it;
pkghash_it hit;
unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_DEPS|PKG_LOAD_REQUIRES|
PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;

Expand Down Expand Up @@ -1622,7 +1631,9 @@ jobs_solve_full_upgrade(struct pkg_jobs *j)
jcount);
elt_num = 0;

HASH_ITER(hh, j->request_add, req, rtmp) {
hit = pkghash_iterator(j->request_add);
while (pkghash_next(&hit)) {
req = hit.value;
pkg_emit_progress_tick(++elt_num, jcount);
pkg_jobs_universe_process(j->universe, req->item->pkg);
}
Expand All @@ -1637,9 +1648,10 @@ static int
jobs_solve_partial_upgrade(struct pkg_jobs *j)
{
struct job_pattern *jp;
struct pkg_job_request *req, *rtmp;
struct pkg_job_request *req;
bool error_found = false;
int retcode;
pkghash_it it;

LL_FOREACH(j->patterns, jp) {
retcode = pkg_jobs_find_remote_pattern(j, jp);
Expand Down Expand Up @@ -1669,7 +1681,10 @@ jobs_solve_partial_upgrade(struct pkg_jobs *j)
/*
* Need to iterate request one more time to recurse depends
*/
HASH_ITER(hh, j->request_add, req, rtmp) {

it = pkghash_iterator(j->request_add);
while (pkghash_next(&it)) {
req = it.value;
pkg_jobs_universe_process(j->universe, req->item->pkg);
}
return (EPKG_OK);
Expand All @@ -1678,8 +1693,9 @@ jobs_solve_partial_upgrade(struct pkg_jobs *j)
static int
jobs_solve_install_upgrade(struct pkg_jobs *j)
{
struct pkg_job_request *req, *rtmp;
struct pkg_job_request *req;
int retcode = 0;
pkghash_it it;

/* Check for new pkg. Skip for 'upgrade -F'. */
if (((j->flags & PKG_FLAG_SKIP_INSTALL) == 0 &&
Expand Down Expand Up @@ -1714,7 +1730,9 @@ jobs_solve_install_upgrade(struct pkg_jobs *j)
* If we have tried to solve request, then we just want to re-add all
* request packages to the universe to find out any potential conflicts
*/
HASH_ITER(hh, j->request_add, req, rtmp) {
it = pkghash_iterator(j->request_add);
while (pkghash_next(&it)) {
req = it.value;
pkg_jobs_universe_process(j->universe, req->item->pkg);
}
}
Expand Down Expand Up @@ -1743,7 +1761,8 @@ jobs_solve_fetch(struct pkg_jobs *j)
struct job_pattern *jp;
struct pkg *pkg = NULL;
struct pkgdb_it *it;
struct pkg_job_request *req, *rtmp;
struct pkg_job_request *req;
pkghash_it hit;

if ((j->flags & PKG_FLAG_UPGRADES_FOR_INSTALLED) == PKG_FLAG_UPGRADES_FOR_INSTALLED) {
if ((it = pkgdb_query(j->db, NULL, MATCH_ALL)) == NULL)
Expand All @@ -1767,8 +1786,11 @@ jobs_solve_fetch(struct pkg_jobs *j)
pkg_emit_error("No packages matching '%s' have been found in the "
"repositories", jp->pattern);
}
HASH_ITER(hh, j->request_add, req, rtmp)
hit = pkghash_iterator(j->request_add);
while (pkghash_next(&hit)) {
req = hit.value;
pkg_jobs_universe_process(j->universe, req->item->pkg);
}
}

j->solved ++;
Expand Down Expand Up @@ -2035,7 +2057,7 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j,
old = ps->items[1] ? ps->items[1]->pkg : NULL;
new = ps->items[0]->pkg;

HASH_FIND_STR(j->request_add, new->uid, req);
req = pkghash_get_value(j->request_add, new->uid);
if (req != NULL && req->item->jp != NULL &&
(req->item->jp->flags & PKG_PATTERN_FLAG_FILE)) {
/*
Expand Down
11 changes: 7 additions & 4 deletions libpkg/pkg_jobs_conflicts.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,24 @@ pkg_conflicts_request_add_chain(struct pkg_conflict_chain **chain, struct pkg_jo
int
pkg_conflicts_request_resolve(struct pkg_jobs *j)
{
struct pkg_job_request *req, *rtmp, *found;
struct pkg_job_request *req, *found;
struct pkg_conflict *c;
struct pkg_conflict_chain *chain;
struct pkg_job_universe_item *unit;
pkghash_it it;

HASH_ITER(hh, j->request_add, req, rtmp) {
it = pkghash_iterator(j->request_add);
while (pkghash_next(&it)) {
req = it.value;
chain = NULL;
if (req->skip)
continue;

LL_FOREACH(req->item->pkg->conflicts, c) {
unit = pkg_jobs_universe_find(j->universe, c->uid);
if (unit != NULL) {
HASH_FIND_STR(j->request_add, unit->pkg->uid, found);
if (found && !found->skip) {
found = pkghash_get_value(j->request_add, unit->pkg->uid);
if (found != NULL && !found->skip) {
pkg_conflicts_request_add_chain(&chain, found);
}
}
Expand Down
Loading

0 comments on commit 486a5b7

Please sign in to comment.