Add diff function to compute the difference between two package sets.
1.1 --- a/main.c Sun Sep 30 00:18:20 2007 -0400
1.2 +++ b/main.c Fri Oct 05 16:26:27 2007 -0400
1.3 @@ -7,7 +7,8 @@
1.4 #include "razor.h"
1.5
1.6 static const char *repo_filename = "system.repo";
1.7 -static const char rawhide_repo_filename[] = "rawhide.repo";
1.8 +static const char *rawhide_repo_filename = "rawhide.repo";
1.9 +static const char *updated_repo_filename = "system-updated.repo";
1.10
1.11 static int
1.12 command_list(int argc, const char *argv[])
1.13 @@ -123,7 +124,7 @@
1.14 if (set == NULL || upstream == NULL)
1.15 return 1;
1.16 set = razor_set_update(set, upstream, argc - 2, argv + 2);
1.17 - razor_set_write(set, "system-updated.repo");
1.18 + razor_set_write(set, updated_repo_filename);
1.19 razor_set_destroy(set);
1.20 razor_set_destroy(upstream);
1.21 printf("wrote system-updated.repo\n");
1.22 @@ -131,6 +132,34 @@
1.23 return 0;
1.24 }
1.25
1.26 +static void
1.27 +print_diff(const char *name,
1.28 + const char *old_version, const char *new_version, void *data)
1.29 +{
1.30 + if (old_version)
1.31 + printf("removing %s %s\n", name, old_version);
1.32 + else
1.33 + printf("install %s %s\n", name, new_version);
1.34 +}
1.35 +
1.36 +static int
1.37 +command_diff(int argc, const char *argv[])
1.38 +{
1.39 + struct razor_set *set, *updated;
1.40 +
1.41 + set = razor_set_open(repo_filename);
1.42 + updated = razor_set_open(updated_repo_filename);
1.43 + if (set == NULL || updated == NULL)
1.44 + return 1;
1.45 +
1.46 + razor_set_diff(set, updated, print_diff, NULL);
1.47 +
1.48 + razor_set_destroy(set);
1.49 + razor_set_destroy(updated);
1.50 +
1.51 + return 0;
1.52 +}
1.53 +
1.54 static struct {
1.55 const char *name;
1.56 const char *description;
1.57 @@ -144,7 +173,8 @@
1.58 { "import-yum", "import yum filelist.xml on stdin", command_import_yum },
1.59 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
1.60 { "validate", "validate a package set", command_validate },
1.61 - { "update", "update all or specified packages", command_update }
1.62 + { "update", "update all or specified packages", command_update },
1.63 + { "diff", "show diff between two package sets", command_diff }
1.64 };
1.65
1.66 static int
2.1 --- a/razor.c Sun Sep 30 00:18:20 2007 -0400
2.2 +++ b/razor.c Fri Oct 05 16:26:27 2007 -0400
2.3 @@ -1385,3 +1385,48 @@
2.4 return set;
2.5 }
2.6
2.7 +/* The diff order matters. We should sort the packages so that a
2.8 + * REMOVE of a package comes before the INSTALL, and so that all
2.9 + * requires for a package have been installed before the package.
2.10 + **/
2.11 +
2.12 +void
2.13 +razor_set_diff(struct razor_set *set, struct razor_set *upstream,
2.14 + razor_package_callback_t callback, void *data)
2.15 +{
2.16 + struct razor_package *p, *pend, *u, *uend;
2.17 + char *ppool, *upool;
2.18 + int res = 0;
2.19 +
2.20 + p = set->packages.data;
2.21 + pend = set->packages.data + set->packages.size;
2.22 + ppool = set->string_pool.data;
2.23 +
2.24 + u = upstream->packages.data;
2.25 + uend = upstream->packages.data + upstream->packages.size;
2.26 + upool = upstream->string_pool.data;
2.27 +
2.28 + while (p < pend || u < uend) {
2.29 + if (p < pend && u < uend) {
2.30 + res = strcmp(&ppool[p->name], &upool[u->name]);
2.31 + if (res == 0)
2.32 + res = versioncmp(&ppool[p->version],
2.33 + &upool[u->version]);
2.34 + }
2.35 +
2.36 + if (u == uend || res < 0) {
2.37 + callback(&ppool[p->name], &ppool[p->version],
2.38 + NULL, data);
2.39 + p++;
2.40 + continue;
2.41 + } else if (p == pend || res > 0) {
2.42 + callback(&upool[u->name], NULL, &upool[u->version],
2.43 + data);
2.44 + u++;
2.45 + continue;
2.46 + } else {
2.47 + p++;
2.48 + u++;
2.49 + }
2.50 + }
2.51 +}
3.1 --- a/razor.h Sun Sep 30 00:18:20 2007 -0400
3.2 +++ b/razor.h Fri Oct 05 16:26:27 2007 -0400
3.3 @@ -24,6 +24,18 @@
3.4 struct razor_set *upstream,
3.5 int count, const char **packages);
3.6
3.7 +typedef void (*razor_package_callback_t)(const char *name,
3.8 + const char *old_version,
3.9 + const char *new_version,
3.10 + void *data);
3.11 +void
3.12 +razor_set_diff(struct razor_set *set, struct razor_set *upstream,
3.13 + razor_package_callback_t callback, void *data);
3.14 +
3.15 +
3.16 +/* Importer interface; for building a razor set from external sources,
3.17 + * like yum, rpmdb or razor package files. */
3.18 +
3.19 struct razor_importer;
3.20
3.21 struct razor_importer *razor_importer_new(void);