Hide a bunch of depsolver internals in razor.c.
1.1 --- a/main.c Sun Apr 06 18:40:53 2008 -0400
1.2 +++ b/main.c Sun Apr 06 19:24:07 2008 -0400
1.3 @@ -338,14 +338,15 @@
1.4 {
1.5 struct razor_set *set, *upstream;
1.6 struct razor_transaction *trans;
1.7 + int errors;
1.8
1.9 set = razor_set_open(repo_filename);
1.10 upstream = razor_set_open(rawhide_repo_filename);
1.11 if (set == NULL || upstream == NULL)
1.12 return 1;
1.13 trans = razor_transaction_create(set, upstream, argc, argv, 0, NULL);
1.14 - razor_transaction_describe(trans);
1.15 - if (trans->errors)
1.16 + errors = razor_transaction_describe(trans);
1.17 + if (errors)
1.18 return 1;
1.19
1.20 set = razor_transaction_run(trans);
1.21 @@ -363,13 +364,14 @@
1.22 {
1.23 struct razor_set *set;
1.24 struct razor_transaction *trans;
1.25 + int errors;
1.26
1.27 set = razor_set_open(repo_filename);
1.28 if (set == NULL)
1.29 return 1;
1.30 trans = razor_transaction_create(set, NULL, 0, NULL, argc, argv);
1.31 - razor_transaction_describe(trans);
1.32 - if (trans->errors)
1.33 + errors = razor_transaction_describe(trans);
1.34 + if (errors)
1.35 return 1;
1.36
1.37 set = razor_transaction_run(trans);
1.38 @@ -519,7 +521,7 @@
1.39 struct razor_rpm *rpm;
1.40 const char *filename;
1.41 char path[PATH_MAX], new_path[PATH_MAX], **packages;
1.42 - int i;
1.43 + int errors, i;
1.44
1.45 upstream = create_set_from_rpms(argc, argv);
1.46 snprintf(path, sizeof path,
1.47 @@ -535,8 +537,8 @@
1.48 argc, (const char **)packages,
1.49 0, NULL);
1.50 free(packages);
1.51 - razor_transaction_describe(trans);
1.52 - if (trans->errors)
1.53 + errors = razor_transaction_describe(trans);
1.54 + if (errors)
1.55 return 1;
1.56
1.57 /* FIXME: Use _finish() convention here? That is, a function
2.1 --- a/razor.c Sun Apr 06 18:40:53 2008 -0400
2.2 +++ b/razor.c Sun Apr 06 19:24:07 2008 -0400
2.3 @@ -1716,6 +1716,51 @@
2.4 razor_package_iterator_destroy(pi2);
2.5 }
2.6
2.7 +struct razor_transaction;
2.8 +struct razor_transaction_package;
2.9 +struct razor_transaction_resolver;
2.10 +
2.11 +struct razor_transaction {
2.12 + int package_count, errors;
2.13 + struct razor_transaction_package *packages;
2.14 +
2.15 + struct razor_set *system, *upstream;
2.16 +};
2.17 +
2.18 +struct razor_transaction_package {
2.19 + const char *name, *old_version, *new_version;
2.20 + struct razor_package *old_package, *new_package;
2.21 + enum razor_transaction_package_state state;
2.22 +
2.23 + /* dep_package is the name of the package that resulted in
2.24 + * this entry being created (or NULL if the user requested the
2.25 + * install/remove), with the other dep_ fields providing
2.26 + * additional information.
2.27 + *
2.28 + * For INSTALL, if dep_type is REQUIRES, then dep_package
2.29 + * required something that this package provides. If dep_type
2.30 + * is CONFLICTS, then dep_package is a package that conflicted
2.31 + * with an older version of this package, forcing an upgrade.
2.32 + *
2.33 + * For REMOVE, if dep_type is REQUIRES, then dep_package is a
2.34 + * package that is being removed. If dep_type is OBSOLETES,
2.35 + * then dep_package is a package that obsoletes this one.
2.36 + *
2.37 + * For OLD_CONFLICT or NEW_CONFLICT, dep_package is an
2.38 + * existing package that conflicts with this one. The
2.39 + * conflicting property comes from the already-installed
2.40 + * package for OLD_CONFLICT, or the to-be-installed package
2.41 + * for NEW_CONFLICT.
2.42 + *
2.43 + * For UNSATISFIABLE, the dep_ fields are as for an INSTALL,
2.44 + * but the name field will be NULL.
2.45 + */
2.46 + const char *dep_package;
2.47 + enum razor_property_type dep_type;
2.48 + const char *dep_property;
2.49 + enum razor_version_relation dep_relation;
2.50 + const char *dep_version;
2.51 +};
2.52
2.53 struct razor_transaction_resolver {
2.54 struct razor_set *system, *upstream;
2.55 @@ -2637,7 +2682,7 @@
2.56 }
2.57 }
2.58
2.59 -void
2.60 +int
2.61 razor_transaction_describe(struct razor_transaction *trans)
2.62 {
2.63 struct razor_transaction_package *p, *pend, *tps;
2.64 @@ -2769,6 +2814,31 @@
2.65 break;
2.66 }
2.67 }
2.68 +
2.69 + return trans->errors;
2.70 +}
2.71 +
2.72 +int
2.73 +razor_transaction_unsatisfied_property(struct razor_transaction *trans,
2.74 + const char *name,
2.75 + enum razor_version_relation rel,
2.76 + const char *version)
2.77 +{
2.78 + struct razor_transaction_package *p, *end;
2.79 +
2.80 + end = trans->packages + trans->package_count;
2.81 + for (p = trans->packages; p < end; p++) {
2.82 + if (p->state != RAZOR_PACKAGE_UNSATISFIABLE)
2.83 + continue;
2.84 + if (strcmp(name, p->dep_property) != 0 ||
2.85 + rel != p->dep_relation ||
2.86 + strcmp(version, p->dep_version) != 0)
2.87 + continue;
2.88 +
2.89 + return 1;
2.90 + }
2.91 +
2.92 + return 0;
2.93 }
2.94
2.95 struct razor_set *
3.1 --- a/razor.h Sun Apr 06 18:40:53 2008 -0400
3.2 +++ b/razor.h Sun Apr 06 19:24:07 2008 -0400
3.3 @@ -107,56 +107,20 @@
3.4 RAZOR_PACKAGE_UNSATISFIABLE,
3.5 };
3.6
3.7 -struct razor_transaction_package {
3.8 - const char *name, *old_version, *new_version;
3.9 - struct razor_package *old_package, *new_package;
3.10 - enum razor_transaction_package_state state;
3.11 -
3.12 - /* dep_package is the name of the package that resulted in
3.13 - * this entry being created (or NULL if the user requested the
3.14 - * install/remove), with the other dep_ fields providing
3.15 - * additional information.
3.16 - *
3.17 - * For INSTALL, if dep_type is REQUIRES, then dep_package
3.18 - * required something that this package provides. If dep_type
3.19 - * is CONFLICTS, then dep_package is a package that conflicted
3.20 - * with an older version of this package, forcing an upgrade.
3.21 - *
3.22 - * For REMOVE, if dep_type is REQUIRES, then dep_package is a
3.23 - * package that is being removed. If dep_type is OBSOLETES,
3.24 - * then dep_package is a package that obsoletes this one.
3.25 - *
3.26 - * For OLD_CONFLICT or NEW_CONFLICT, dep_package is an
3.27 - * existing package that conflicts with this one. The
3.28 - * conflicting property comes from the already-installed
3.29 - * package for OLD_CONFLICT, or the to-be-installed package
3.30 - * for NEW_CONFLICT.
3.31 - *
3.32 - * For UNSATISFIABLE, the dep_ fields are as for an INSTALL,
3.33 - * but the name field will be NULL.
3.34 - */
3.35 - const char *dep_package;
3.36 - enum razor_property_type dep_type;
3.37 - const char *dep_property;
3.38 - enum razor_version_relation dep_relation;
3.39 - const char *dep_version;
3.40 -};
3.41 -
3.42 -struct razor_transaction {
3.43 - int package_count, errors;
3.44 - struct razor_transaction_package *packages;
3.45 -
3.46 - struct razor_set *system, *upstream;
3.47 -};
3.48 -
3.49 struct razor_transaction *
3.50 razor_transaction_create(struct razor_set *system, struct razor_set *upstream,
3.51 int update_count, const char **update_packages,
3.52 int remove_count, const char **remove_packages);
3.53 -void razor_transaction_describe(struct razor_transaction *trans);
3.54 +int razor_transaction_describe(struct razor_transaction *trans);
3.55 struct razor_set *razor_transaction_run(struct razor_transaction *trans);
3.56 void razor_transaction_destroy(struct razor_transaction *trans);
3.57
3.58 +/* Temporary helper for test suite. */
3.59 +int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
3.60 + const char *name,
3.61 + enum razor_version_relation rel,
3.62 + const char *version);
3.63 +
3.64 /* Importer interface; for building a razor set from external sources,
3.65 * like yum, rpmdb or razor package files. */
3.66
4.1 --- a/test-driver.c Sun Apr 06 18:40:53 2008 -0400
4.2 +++ b/test-driver.c Sun Apr 06 19:24:07 2008 -0400
4.3 @@ -59,11 +59,11 @@
4.4 struct razor_set **importer_set;
4.5
4.6 struct razor_transaction *trans;
4.7 - struct razor_transaction_package *unsat;
4.8
4.9 char *install_pkgs[3], *remove_pkgs[3];
4.10 int n_install_pkgs, n_remove_pkgs;
4.11
4.12 + int unsat;
4.13 int in_result;
4.14
4.15 int debug, errors;
4.16 @@ -194,23 +194,18 @@
4.17 }
4.18
4.19 static void
4.20 -check_unsatisfiable_property(struct test_context *ctx, enum razor_property_type type, const char *name, enum razor_version_relation rel, const char *version)
4.21 +check_unsatisfiable_property(struct test_context *ctx,
4.22 + enum razor_property_type type,
4.23 + const char *name,
4.24 + enum razor_version_relation rel,
4.25 + const char *version)
4.26 {
4.27 if (!version)
4.28 version = "";
4.29
4.30 - for (; ctx->unsat < ctx->trans->packages + ctx->trans->package_count; ctx->unsat++) {
4.31 - if (ctx->unsat->state != RAZOR_PACKAGE_UNSATISFIABLE)
4.32 - continue;
4.33 - if (strcmp(name, ctx->unsat->dep_property) != 0 ||
4.34 - rel != ctx->unsat->dep_relation ||
4.35 - strcmp(version, ctx->unsat->dep_version) != 0)
4.36 - continue;
4.37 -
4.38 - /* OK, found it, so skip over it and continue */
4.39 - ctx->unsat++;
4.40 + if (razor_transaction_unsatisfied_property(ctx->trans,
4.41 + name, rel, version))
4.42 return;
4.43 - }
4.44
4.45 fprintf(stderr, " didn't get unsatisfiable '%s %s %s'\n",
4.46 name, razor_version_relations[rel], version);
4.47 @@ -253,22 +248,22 @@
4.48 static void
4.49 end_transaction(struct test_context *ctx)
4.50 {
4.51 + int errors;
4.52 +
4.53 ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set,
4.54 ctx->n_install_pkgs,
4.55 (const char **)ctx->install_pkgs,
4.56 ctx->n_remove_pkgs,
4.57 (const char **)ctx->remove_pkgs);
4.58 - if (ctx->debug) {
4.59 - razor_transaction_describe(ctx->trans);
4.60 - printf("\n");
4.61 - }
4.62 + errors = razor_transaction_describe(ctx->trans);
4.63 + printf("\n");
4.64
4.65 while (ctx->n_install_pkgs--)
4.66 free(ctx->install_pkgs[ctx->n_install_pkgs]);
4.67 while (ctx->n_remove_pkgs--)
4.68 free(ctx->remove_pkgs[ctx->n_remove_pkgs]);
4.69
4.70 - if (!ctx->trans->errors) {
4.71 + if (!errors) {
4.72 struct razor_set *new;
4.73 new = razor_transaction_run(ctx->trans);
4.74 razor_set_destroy(ctx->system_set);
4.75 @@ -348,13 +343,13 @@
4.76 exit(1);
4.77 }
4.78
4.79 - ctx->unsat = ctx->trans->packages;
4.80 + ctx->unsat = 1;
4.81 }
4.82
4.83 static void
4.84 end_unsatisfiable(struct test_context *ctx)
4.85 {
4.86 - ctx->unsat = NULL;
4.87 + ctx->unsat = 0;
4.88 }
4.89
4.90 static void