[pacman-dev] [PATCH 1/5] graph.h: replace hardcoded values with an enum
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
Signed-off-by: Andrew Gregory
On 16/04/17 07:57, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- lib/libalpm/deps.c | 70 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 6f05f0d0..01e550a4 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -158,6 +158,42 @@ static alpm_list_t *dep_graph_init(alpm_handle_t *handle, return vertices; }
+static void _alpm_warn_dep_cycle(alpm_handle_t *handle, alpm_list_t *targets, + alpm_graph_t *ancestor, alpm_graph_t *vertex, int reverse) +{ + /* vertex depends on and is required by ancestor */ + if(!alpm_list_find_ptr(targets, vertex->data)) { + /* child is not part of the transaction, not a problem */ + return; + } + + /* find the nearest ancestor that's part of the transaction */ + while(ancestor) { + if(alpm_list_find_ptr(targets, ancestor->data)) { + break; + } + ancestor = ancestor->parent; + } + + if(!ancestor || ancestor == vertex) { + /* no transaction package in our ancestry or the package has + * a circular dependency with itself, not a problem */ + } else { + alpm_pkg_t *ancestorpkg = ancestor->data; + alpm_pkg_t *childpkg = vertex->data; + _alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n")); + if(reverse) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("%s will be removed after its %s dependency\n"), + ancestorpkg->name, childpkg->name); + } else { + _alpm_log(handle, ALPM_LOG_WARNING, + _("%s will be installed before its %s dependency\n"), + ancestorpkg->name, childpkg->name); + } + } +} +
Patch is OK. I'd love it if these messages migrated to the front end too... A
/* Re-order a list of target packages with respect to their dependencies. * * Example (reverse == 0): @@ -204,39 +240,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle, nextchild->parent = vertex; vertex = nextchild; } else if(nextchild->state == ALPM_GRAPH_STATE_PROCESSING) { - /* child is an ancestor of vertex */ - alpm_graph_t *transvertex = vertex; - - if(!alpm_list_find_ptr(targets, nextchild->data)) { - /* child is not part of the transaction, not a problem */ - continue; - } - - /* find the nearest parent that's part of the transaction */ - while(transvertex) { - if(alpm_list_find_ptr(targets, transvertex->data)) { - break; - } - transvertex = transvertex->parent; - } - - if(!transvertex || transvertex == nextchild) { - /* no transaction package in our ancestry or the package has - * a circular dependency with itself, not a problem */ - } else { - alpm_pkg_t *transpkg = transvertex->data; - alpm_pkg_t *childpkg = nextchild->data; - _alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n")); - if(reverse) { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s will be removed after its %s dependency\n"), - transpkg->name, childpkg->name); - } else { - _alpm_log(handle, ALPM_LOG_WARNING, - _("%s will be installed before its %s dependency\n"), - transpkg->name, childpkg->name); - } - } + _alpm_warn_dep_cycle(handle, targets, vertex, nextchild, reverse); } } if(!found) {
Signed-off-by: Andrew Gregory
vptr is a simple list iterator, which are typically named i.
Signed-off-by: Andrew Gregory
On 16/04/17 07:57, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
---
<snip>
+enum __alpm_graph_vertex_state { + ALPM_GRAPH_STATE_UNPROCESSED = 0, + ALPM_GRAPH_STATE_PROCESSING = -1, + ALPM_GRAPH_STATE_PROCESSED = 1 +}; +
Why keep the -1, 0, 1 state when switching to an enum? I can't see a point when it matters?
typedef struct __alpm_graph_t { void *data; struct __alpm_graph_t *parent; /* where did we come from? */ alpm_list_t *children; alpm_list_t *childptr; /* points to a child in children list */ off_t weight; /* weight of the node */ - signed char state; /* 0: untouched, -1: entered, other: leaving time */ + signed char state;
struct __alpm_graph_vertex_state state ?
} alpm_graph_t;
alpm_graph_t *_alpm_graph_new(void);
Signed-off-by: Andrew Gregory
participants (2)
-
Allan McRae
-
Andrew Gregory