Commit c11b70c7 authored by Timo Teräs's avatar Timo Teräs

db: track reverse dependencies

This will be used later by the commit change calculator (for improved
changeset calculation, ref #7). Will be also used by "apk info" to show
reverse dependencies or "required by" information.
parent f4210298
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#define APK_MAX_REPOS 32 #define APK_MAX_REPOS 32
struct apk_name;
APK_ARRAY(apk_name_array, struct apk_name *);
struct apk_db_file { struct apk_db_file {
struct hlist_node hash_node; struct hlist_node hash_node;
struct hlist_node diri_files_list; struct hlist_node diri_files_list;
...@@ -55,6 +58,7 @@ struct apk_name { ...@@ -55,6 +58,7 @@ struct apk_name {
apk_hash_node hash_node; apk_hash_node hash_node;
char *name; char *name;
struct apk_package_array *pkgs; struct apk_package_array *pkgs;
struct apk_name_array *rdepends;
}; };
struct apk_repository { struct apk_repository {
......
...@@ -329,6 +329,25 @@ static void apk_db_file_change_owner(struct apk_database *db, ...@@ -329,6 +329,25 @@ static void apk_db_file_change_owner(struct apk_database *db,
*after = &file->diri_files_list.next; *after = &file->diri_files_list.next;
} }
static void apk_db_pkg_rdepends(struct apk_database *db, struct apk_package *pkg)
{
int i, j;
if (pkg->depends == NULL)
return;
for (i = 0; i < pkg->depends->num; i++) {
struct apk_name *rname = pkg->depends->item[i].name;
if (rname->rdepends) {
for (j = 0; j < rname->rdepends->num; j++)
if (rname->rdepends->item[j] == pkg->name)
return;
}
*apk_name_array_add(&rname->rdepends) = pkg->name;
}
}
static struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg) static struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg)
{ {
struct apk_package *idb; struct apk_package *idb;
...@@ -339,6 +358,7 @@ static struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_pa ...@@ -339,6 +358,7 @@ static struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_pa
pkg->id = db->pkg_id++; pkg->id = db->pkg_id++;
apk_hash_insert(&db->available.packages, pkg); apk_hash_insert(&db->available.packages, pkg);
*apk_package_array_add(&pkg->name->pkgs) = pkg; *apk_package_array_add(&pkg->name->pkgs) = pkg;
apk_db_pkg_rdepends(db, pkg);
} else { } else {
idb->repos |= pkg->repos; idb->repos |= pkg->repos;
apk_pkg_free(pkg); apk_pkg_free(pkg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment