Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions qmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ static void pkg_fetch(int, const depend_atom *, tree_pkg_ctx *);
static void pkg_merge(int, const depend_atom *, tree_pkg_ctx *);
static int pkg_unmerge(tree_pkg_ctx *, depend_atom *, set *, int, char **, int, char **);

/* track packages being processed to detect circular dependencies */
static set *merge_stack = NULL;

static bool
qmerge_prompt(const char *p)
{
Expand Down Expand Up @@ -1135,6 +1138,17 @@ pkg_merge(int level, const depend_atom *qatom, tree_pkg_ctx *mpkg)
matom->SLOT == NULL ? "0" : matom->SLOT);
slotatom = atom_explode(buf);

/* circular dependency detection */
if (merge_stack == NULL)
merge_stack = create_set();

if (contains_set(buf, merge_stack)) {
warn("circular dependency detected: %s", buf);
atom_implode(slotatom);
return;
}
add_set(buf, merge_stack);

previnst = best_version(slotatom, BV_INSTALLED);
if (previnst != NULL) {
atom_ctx *atom = tree_pkg_atom(previnst, false);
Expand Down Expand Up @@ -1204,6 +1218,15 @@ pkg_merge(int level, const depend_atom *qatom, tree_pkg_ctx *mpkg)
}

if (pretend == 100) {
/* if we do full -p, remove from circular dependency tracking */
if (merge_stack != NULL) {
char pkgkey[_Q_PATH_MAX];
snprintf(pkgkey, sizeof(pkgkey), "%s/%s:%s",
matom->CATEGORY,
matom->PN,
matom->SLOT == NULL ? "0" : matom->SLOT);
del_set(pkgkey, merge_stack, NULL);
}
return;
}

Expand Down Expand Up @@ -1744,6 +1767,16 @@ pkg_merge(int level, const depend_atom *qatom, tree_pkg_ctx *mpkg)
/* don't care about return, but when empty, remove */
rmdir("../qmerge");

/* remove from circular dependency tracking */
if (merge_stack != NULL) {
char pkgkey[_Q_PATH_MAX];
snprintf(pkgkey, sizeof(pkgkey), "%s/%s:%s",
matom->CATEGORY,
matom->PN,
matom->SLOT == NULL ? "0" : matom->SLOT);
del_set(pkgkey, merge_stack, NULL);
}

printf("%s>>>%s %s\n",
YELLOW, NORM, atom_format("%[CAT]%[PF]", matom));
}
Expand Down Expand Up @@ -2396,6 +2429,9 @@ int qmerge_main(int argc, char **argv)
if (todo != NULL)
free_set(todo);

if (merge_stack != NULL)
free_set(merge_stack);

if (_qmerge_binpkg_tree != NULL)
tree_close(_qmerge_binpkg_tree);
if (_qmerge_vdb_tree != NULL)
Expand Down