From: Kristian Høgsberg Date: Sun, 6 Apr 2008 23:24:07 +0000 (-0400) Subject: Hide a bunch of depsolver internals in razor.c. X-Git-Tag: 0.1~174 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=0b1dd60a9530f3e7d01f611bf09ae020aeb47bc4;p=razor2.git%2F.git Hide a bunch of depsolver internals in razor.c. --- diff --git a/main.c b/main.c index 4ac8c57..58277cd 100644 --- a/main.c +++ b/main.c @@ -338,14 +338,15 @@ command_update(int argc, const char *argv[]) { struct razor_set *set, *upstream; struct razor_transaction *trans; + int errors; set = razor_set_open(repo_filename); upstream = razor_set_open(rawhide_repo_filename); if (set == NULL || upstream == NULL) return 1; trans = razor_transaction_create(set, upstream, argc, argv, 0, NULL); - razor_transaction_describe(trans); - if (trans->errors) + errors = razor_transaction_describe(trans); + if (errors) return 1; set = razor_transaction_run(trans); @@ -363,13 +364,14 @@ command_remove(int argc, const char *argv[]) { struct razor_set *set; struct razor_transaction *trans; + int errors; set = razor_set_open(repo_filename); if (set == NULL) return 1; trans = razor_transaction_create(set, NULL, 0, NULL, argc, argv); - razor_transaction_describe(trans); - if (trans->errors) + errors = razor_transaction_describe(trans); + if (errors) return 1; set = razor_transaction_run(trans); @@ -519,7 +521,7 @@ command_install(int argc, const char *argv[]) struct razor_rpm *rpm; const char *filename; char path[PATH_MAX], new_path[PATH_MAX], **packages; - int i; + int errors, i; upstream = create_set_from_rpms(argc, argv); snprintf(path, sizeof path, @@ -535,8 +537,8 @@ command_install(int argc, const char *argv[]) argc, (const char **)packages, 0, NULL); free(packages); - razor_transaction_describe(trans); - if (trans->errors) + errors = razor_transaction_describe(trans); + if (errors) return 1; /* FIXME: Use _finish() convention here? That is, a function diff --git a/razor.c b/razor.c index 1a19e35..48a9de2 100644 --- a/razor.c +++ b/razor.c @@ -1716,6 +1716,51 @@ razor_set_diff(struct razor_set *set, struct razor_set *upstream, razor_package_iterator_destroy(pi2); } +struct razor_transaction; +struct razor_transaction_package; +struct razor_transaction_resolver; + +struct razor_transaction { + int package_count, errors; + struct razor_transaction_package *packages; + + struct razor_set *system, *upstream; +}; + +struct razor_transaction_package { + const char *name, *old_version, *new_version; + struct razor_package *old_package, *new_package; + enum razor_transaction_package_state state; + + /* dep_package is the name of the package that resulted in + * this entry being created (or NULL if the user requested the + * install/remove), with the other dep_ fields providing + * additional information. + * + * For INSTALL, if dep_type is REQUIRES, then dep_package + * required something that this package provides. If dep_type + * is CONFLICTS, then dep_package is a package that conflicted + * with an older version of this package, forcing an upgrade. + * + * For REMOVE, if dep_type is REQUIRES, then dep_package is a + * package that is being removed. If dep_type is OBSOLETES, + * then dep_package is a package that obsoletes this one. + * + * For OLD_CONFLICT or NEW_CONFLICT, dep_package is an + * existing package that conflicts with this one. The + * conflicting property comes from the already-installed + * package for OLD_CONFLICT, or the to-be-installed package + * for NEW_CONFLICT. + * + * For UNSATISFIABLE, the dep_ fields are as for an INSTALL, + * but the name field will be NULL. + */ + const char *dep_package; + enum razor_property_type dep_type; + const char *dep_property; + enum razor_version_relation dep_relation; + const char *dep_version; +}; struct razor_transaction_resolver { struct razor_set *system, *upstream; @@ -2637,7 +2682,7 @@ print_requirement(struct razor_transaction_package *p) } } -void +int razor_transaction_describe(struct razor_transaction *trans) { struct razor_transaction_package *p, *pend, *tps; @@ -2769,6 +2814,31 @@ razor_transaction_describe(struct razor_transaction *trans) break; } } + + return trans->errors; +} + +int +razor_transaction_unsatisfied_property(struct razor_transaction *trans, + const char *name, + enum razor_version_relation rel, + const char *version) +{ + struct razor_transaction_package *p, *end; + + end = trans->packages + trans->package_count; + for (p = trans->packages; p < end; p++) { + if (p->state != RAZOR_PACKAGE_UNSATISFIABLE) + continue; + if (strcmp(name, p->dep_property) != 0 || + rel != p->dep_relation || + strcmp(version, p->dep_version) != 0) + continue; + + return 1; + } + + return 0; } struct razor_set * diff --git a/razor.h b/razor.h index ac439c4..7f17fd5 100644 --- a/razor.h +++ b/razor.h @@ -107,56 +107,20 @@ enum razor_transaction_package_state { RAZOR_PACKAGE_UNSATISFIABLE, }; -struct razor_transaction_package { - const char *name, *old_version, *new_version; - struct razor_package *old_package, *new_package; - enum razor_transaction_package_state state; - - /* dep_package is the name of the package that resulted in - * this entry being created (or NULL if the user requested the - * install/remove), with the other dep_ fields providing - * additional information. - * - * For INSTALL, if dep_type is REQUIRES, then dep_package - * required something that this package provides. If dep_type - * is CONFLICTS, then dep_package is a package that conflicted - * with an older version of this package, forcing an upgrade. - * - * For REMOVE, if dep_type is REQUIRES, then dep_package is a - * package that is being removed. If dep_type is OBSOLETES, - * then dep_package is a package that obsoletes this one. - * - * For OLD_CONFLICT or NEW_CONFLICT, dep_package is an - * existing package that conflicts with this one. The - * conflicting property comes from the already-installed - * package for OLD_CONFLICT, or the to-be-installed package - * for NEW_CONFLICT. - * - * For UNSATISFIABLE, the dep_ fields are as for an INSTALL, - * but the name field will be NULL. - */ - const char *dep_package; - enum razor_property_type dep_type; - const char *dep_property; - enum razor_version_relation dep_relation; - const char *dep_version; -}; - -struct razor_transaction { - int package_count, errors; - struct razor_transaction_package *packages; - - struct razor_set *system, *upstream; -}; - struct razor_transaction * razor_transaction_create(struct razor_set *system, struct razor_set *upstream, int update_count, const char **update_packages, int remove_count, const char **remove_packages); -void razor_transaction_describe(struct razor_transaction *trans); +int razor_transaction_describe(struct razor_transaction *trans); struct razor_set *razor_transaction_run(struct razor_transaction *trans); void razor_transaction_destroy(struct razor_transaction *trans); +/* Temporary helper for test suite. */ +int razor_transaction_unsatisfied_property(struct razor_transaction *trans, + const char *name, + enum razor_version_relation rel, + const char *version); + /* Importer interface; for building a razor set from external sources, * like yum, rpmdb or razor package files. */ diff --git a/test-driver.c b/test-driver.c index 3a99150..6eeb5ac 100644 --- a/test-driver.c +++ b/test-driver.c @@ -59,11 +59,11 @@ struct test_context { struct razor_set **importer_set; struct razor_transaction *trans; - struct razor_transaction_package *unsat; char *install_pkgs[3], *remove_pkgs[3]; int n_install_pkgs, n_remove_pkgs; + int unsat; int in_result; int debug, errors; @@ -194,23 +194,18 @@ add_property(struct test_context *ctx, enum razor_property_type type, const char } static void -check_unsatisfiable_property(struct test_context *ctx, enum razor_property_type type, const char *name, enum razor_version_relation rel, const char *version) +check_unsatisfiable_property(struct test_context *ctx, + enum razor_property_type type, + const char *name, + enum razor_version_relation rel, + const char *version) { if (!version) version = ""; - for (; ctx->unsat < ctx->trans->packages + ctx->trans->package_count; ctx->unsat++) { - if (ctx->unsat->state != RAZOR_PACKAGE_UNSATISFIABLE) - continue; - if (strcmp(name, ctx->unsat->dep_property) != 0 || - rel != ctx->unsat->dep_relation || - strcmp(version, ctx->unsat->dep_version) != 0) - continue; - - /* OK, found it, so skip over it and continue */ - ctx->unsat++; + if (razor_transaction_unsatisfied_property(ctx->trans, + name, rel, version)) return; - } fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n", name, razor_version_relations[rel], version); @@ -253,22 +248,22 @@ start_transaction(struct test_context *ctx, const char **atts) static void end_transaction(struct test_context *ctx) { + int errors; + ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set, ctx->n_install_pkgs, (const char **)ctx->install_pkgs, ctx->n_remove_pkgs, (const char **)ctx->remove_pkgs); - if (ctx->debug) { - razor_transaction_describe(ctx->trans); - printf("\n"); - } + errors = razor_transaction_describe(ctx->trans); + printf("\n"); while (ctx->n_install_pkgs--) free(ctx->install_pkgs[ctx->n_install_pkgs]); while (ctx->n_remove_pkgs--) free(ctx->remove_pkgs[ctx->n_remove_pkgs]); - if (!ctx->trans->errors) { + if (!errors) { struct razor_set *new; new = razor_transaction_run(ctx->trans); razor_set_destroy(ctx->system_set); @@ -348,13 +343,13 @@ start_unsatisfiable(struct test_context *ctx, const char **atts) exit(1); } - ctx->unsat = ctx->trans->packages; + ctx->unsat = 1; } static void end_unsatisfiable(struct test_context *ctx) { - ctx->unsat = NULL; + ctx->unsat = 0; } static void