- changed repo interface a bit, now alloc/free handle repo pointer and
authorMichael Schroeder <mls@suse.de>
Sat, 17 Nov 2007 18:26:28 +0000 (18:26 +0000)
committerMichael Schroeder <mls@suse.de>
Sat, 17 Nov 2007 18:26:28 +0000 (18:26 +0000)
  nsolvables
- fixed yps and deptestomatic to use new interface

16 files changed:
src/pool.c
src/pool.h
src/repo.h
src/repo_solv.c
src/solvable.h
tools/content2solv.c
tools/patchxml2solv.c
tools/repo_content.c
tools/repo_helix.c
tools/repo_patchxml.c
tools/repo_rpmdb.c
tools/repo_rpmmd.c
tools/repo_susetags.c
tools/rpmdb2solv.c
tools/rpmmd2solv.c
tools/susetags2solv.c

index 2e79b43945bbb4d09cd05d8a1e02f1f0525d1f6f..553f698ee67012592675b795a4bdd6e66401aafc 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "poolid.h"
 #include "poolid_private.h"
 #include "poolarch.h"
index 84a40eb4d83096d163cc2e02148ae6645b7dab46..82310553104ff5feed3bdbc158775ace92cf1517 100644 (file)
@@ -19,7 +19,6 @@ extern "C" {
 
 #include "pooltypes.h"
 #include "poolid.h"
-#include "repo.h"
 #include "solvable.h"
 #include "queue.h"
 #include "strpool.h"
@@ -61,6 +60,8 @@ extern "C" {
 
 //-----------------------------------------------
 
+struct _Repo;
+
 struct _Pool {
   int verbose;         // pool is used everywhere, so put the verbose flag here
 
@@ -71,7 +72,7 @@ struct _Pool {
   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
   Hashmask relhashmask;
 
-  Repo **repos;
+  struct _Repo **repos;
   int nrepos;
 
   Solvable *solvables;
@@ -150,10 +151,18 @@ extern Pool *pool_create(void);
  */
 extern void pool_free(Pool *pool);
 
+/**
+ * Solvable management
+ */
 extern Id pool_add_solvable(Pool *pool);
 extern Id pool_add_solvable_block(Pool *pool, int count);
 
 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
+static inline Solvable *pool_id2solvable(Pool *pool, Id p)
+{
+  return pool->solvables + p;
+}
+
 
 /**
  * Prepares a pool for solving
index 381cc7337485894d44a1a464b517d5f84c575cdc..82ac9f206c937f323508ce2bc6410e979e8d51f8 100644 (file)
@@ -14,6 +14,7 @@
 #define REPO_H
 
 #include "pooltypes.h"
+#include "pool.h"
 
 typedef struct _Repo {
   const char *name;
@@ -54,12 +55,16 @@ static inline Id repo_add_solvable(Repo *repo)
     {
       repo->start = p;
       repo->end = p + 1;
-      return p;
     }
-  if (p < repo->start)
-    repo->start = p;
-  if (p + 1 > repo->end)
-    repo->end = p + 1;
+  else
+    {
+      if (p < repo->start)
+       repo->start = p;
+      if (p + 1 > repo->end)
+       repo->end = p + 1;
+    }
+  repo->nsolvables++;
+  repo->pool->solvables[p].repo = repo;
   return p;
 }
 
@@ -67,6 +72,7 @@ static inline Id repo_add_solvable_block(Repo *repo, int count)
 {
   extern Id pool_add_solvable_block(Pool *pool, int count);
   Id p;
+  Solvable *s;
   if (!count)
     return 0;
   p = pool_add_solvable_block(repo->pool, count);
@@ -74,21 +80,30 @@ static inline Id repo_add_solvable_block(Repo *repo, int count)
     {
       repo->start = p;
       repo->end = p + count;
-      return p;
     }
-  if (p < repo->start)
-    repo->start = p;
-  if (p + count > repo->end)
-    repo->end = p + count;
+  else
+    {
+      if (p < repo->start)
+       repo->start = p;
+      if (p + count > repo->end)
+       repo->end = p + count;
+    }
+  repo->nsolvables += count;
+  for (s = repo->pool->solvables + p; count--; s++)
+    s->repo = repo;
   return p;
 }
 
-/* does not modify repo->nsolvables! */
 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
 {
   extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
+  Solvable *s;
+  int i;
   if (start + count == repo->end)
     repo->end -= count;
+  repo->nsolvables -= count;
+  for (s = repo->pool->solvables + start, i = count; i--; s++)
+    s->repo = 0;
   pool_free_solvable_block(repo->pool, start, count, reuseids);
 }
 
index a7263ef2ab6dea63656fb4eec481caee3630105a..2a3826426abd7b438c8fbb6337b0e60161dada31 100644 (file)
@@ -506,11 +506,9 @@ repo_add_solv(Repo *repo, FILE *fp)
 #if 0
   printf("read solvables\n");
 #endif
-  id = repo_add_solvable_block(repo, numsolv);
-  s = pool->solvables + id;
+  s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
   for (i = 0; i < numsolv; i++, s++)
     {
-      s->repo = repo;
       databits = 0;
       if (numsolvdatabits)
        {
@@ -600,8 +598,6 @@ repo_add_solv(Repo *repo, FILE *fp)
            }
        }
     }
-  repo->nsolvables += numsolv;
-
   xfree(idmap);
   xfree(solvdata);
 }
index f1e3c0aee36ed3f823ff4c01848f43fde099349a..28d93ab138a98cb1551e5ba4f95d04b92cb2c7c0 100644 (file)
@@ -15,7 +15,8 @@
 #define SOLVABLE_H
 
 #include "pooltypes.h"
-#include "repo.h"
+
+struct _Repo;
 
 typedef struct _Solvable {
   Id name;
@@ -23,7 +24,7 @@ typedef struct _Solvable {
   Id evr;                      /* epoch:version-release */
   Id vendor;
 
-  Repo *repo;          /* repo we belong to */
+  struct _Repo *repo;          /* repo we belong to */
 
   /* dependencies are offsets into idarray of repo */
   Offset provides;                     /* terminated with Id 0 */
index ad69ef94a49e79710b929fff00a1282cc05b6848..30a6350fa5d222b036929e393c0b6b6fabe9cf26 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_content.h"
 #include "repo_write.h"
 
index 21dc0ff9ea6c9f774f06ef8330a53ed1f581fa3b..6555af4073975dd9be218b2cb7440b9b2c31c16b 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_patchxml.h"
 #include "repo_write.h"
 
index a6d74d44d53fa23f26ef5dd2f58da9adbe085f5b..f31900becb340879a9c94da5051d9fa473b0b5af 100644 (file)
@@ -14,6 +14,7 @@
 #include <assert.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "util.h"
 #include "repo_content.h"
 
@@ -165,7 +166,6 @@ repo_add_content(Repo *repo, FILE *fp)
   char *line, *linep;
   int aline;
   Solvable *s;
-  Id id;
   struct parsedata pd;
 
   memset(&pd, 0, sizeof(pd));
@@ -217,10 +217,7 @@ repo_add_content(Repo *repo, FILE *fp)
                s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
              /* Only support one product.  */
              pd.kind = "product";
-             id = repo_add_solvable(repo);
-             s = pool->solvables + id;
-             s->repo = repo;
-             repo->nsolvables++;
+             s = pool_id2solvable(pool, repo_add_solvable(repo));
              s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1);
            }
          else if (istag ("VERSION"))
index 33bce55b7dbfb766576b2e75579ecc7cca3a5160..f6df2b29a3f15bb3e23dab3a2cce0953c4ad3d30 100644 (file)
@@ -376,7 +376,6 @@ startElement(void *userData, const char *name, const char **atts)
   struct stateswitch *sw;
   Pool *pool = pd->pool;
   Solvable *s = pd->solvable;
-  Id id;
 
   if (pd->depth != pd->statedepth)
     {
@@ -431,8 +430,7 @@ startElement(void *userData, const char *name, const char **atts)
       break;
 
     case STATE_PACKAGE:                       /* solvable name */
-      id = repo_add_solvable(pd->repo);
-      pd->solvable = pool->solvables + id;
+      pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
       if (!strcmp(name, "selection"))
         pd->kind = "selection";
       else if (!strcmp(name, "pattern"))
@@ -450,7 +448,7 @@ startElement(void *userData, const char *name, const char **atts)
       pd->version = 0;
       pd->release = 0;
 #if 0
-      fprintf(stderr, "package #%d\n", id);
+      fprintf(stderr, "package #%d\n", s - pool->solvables);
 #endif
       break;
 
@@ -602,9 +600,6 @@ endElement(void *userData, const char *name)
     {
 
     case STATE_PACKAGE:                       /* package complete */
-      s->repo = pd->repo;
-      pd->repo->nsolvables++;
-
       if (!s->arch)                    /* default to "noarch" */
        s->arch = ARCH_NOARCH;
 
index 29303133ed304dd61ced2975dc42306165e24b2b..d2708108f51f76b8671c3bf6caaf9d7429566850 100644 (file)
@@ -14,6 +14,7 @@
 #include <expat.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_patchxml.h"
 #include "repo_rpmmd.h"
 
@@ -242,7 +243,6 @@ startElement(void *userData, const char *name, const char **atts)
   Pool *pool = pd->pool;
   Solvable *s = pd->solvable;
   struct stateswitch *sw;
-  Id id;
 
   if (pd->depth != pd->statedepth)
     {
@@ -287,8 +287,6 @@ startElement(void *userData, const char *name, const char **atts)
          /* HACK: close patch */
          if (pd->kind && !strcmp(pd->kind, "patch"))
            {
-             s->repo = pd->repo;
-             pd->repo->nsolvables++;
              if (!s->arch)
                s->arch = ARCH_NOARCH;
              s->provides = repo_addid_dep(pd->repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
@@ -298,10 +296,10 @@ startElement(void *userData, const char *name, const char **atts)
        }
       else
         pd->kind = "patch";
-      id = repo_add_solvable(pd->repo);
-      pd->solvable = pool->solvables + id;
+      
+      pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
 #if 0
-      fprintf(stderr, "package #%d\n", id);
+      fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
 #endif
       break;
     case STATE_VERSION:
@@ -390,8 +388,6 @@ endElement(void *userData, const char *name)
     case STATE_PATCH:
       if (!strcmp(name, "patch") && strcmp(pd->kind, "patch"))
        break;  /* already closed */
-      s->repo = pd->repo;
-      pd->repo->nsolvables++;
       if (!s->arch)
        s->arch = ARCH_NOARCH;
       if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
index d4eb8be240806bc7eab1fe5cf5b12bd183fcae9f..c70ab6de5f67e51b035d8793fd08130d52261246 100644 (file)
@@ -22,6 +22,7 @@
 #include <db43/db.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "hash.h"
 #include "util.h"
 #include "repo_rpmdb.h"
@@ -568,10 +569,7 @@ repo_add_rpmdb(Repo *repo, Repo *ref)
       while (dbc->c_get(dbc, &key, &data, DB_NEXT) == 0)
        {
          if (!s)
-           {
-             id = repo_add_solvable(repo);
-             s = pool->solvables + id;
-           }
+           s = pool_id2solvable(pool, repo_add_solvable(repo));
          if (i >= asolv)
            {
              repo->rpmdbid = xrealloc(repo->rpmdbid, (asolv + 256) * sizeof(unsigned int));
@@ -615,8 +613,6 @@ repo_add_rpmdb(Repo *repo, Repo *ref)
          repo->rpmdbid[i] = dbid;
          if (rpm2solv(pool, repo, s, rpmhead))
            {
-             s->repo = repo;
-             repo->nsolvables++;
              i++;
              s = 0;
            }
@@ -708,13 +704,11 @@ repo_add_rpmdb(Repo *repo, Repo *ref)
        }
 
       repo->rpmdbid = xcalloc(nrpmids, sizeof(unsigned int));
-      id = repo_add_solvable_block(repo, nrpmids);
-      s = pool->solvables + id;
+
+      s = pool_id2solvable(pool, repo_add_solvable_block(repo, nrpmids));
 
       for (i = 0; i < nrpmids; i++, rp++, s++)
        {
-         s->repo = repo;
-         repo->nsolvables++;
          dbid = rp->dbid;
          repo->rpmdbid[i] = dbid;
          if (refhash)
index 1f9096278e6e31b7850ac4b08d91cc52945f2472..877f7935dcdc3d0b0f99d2f6464907f5a051dc5e 100644 (file)
@@ -14,6 +14,7 @@
 #include <expat.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "util.h"
 #include "repo_rpmmd.h"
 
@@ -239,7 +240,6 @@ startElement(void *userData, const char *name, const char **atts)
   Pool *pool = pd->pool;
   Solvable *s = pd->solvable;
   struct stateswitch *sw;
-  Id id;
 
   if (pd->depth != pd->statedepth)
     {
@@ -275,19 +275,18 @@ startElement(void *userData, const char *name, const char **atts)
 #if 0
              fprintf(stderr, "numpacks: %d\n", pd->numpacks);
 #endif
-             id = repo_add_solvable_block(pd->repo, pd->numpacks);
-             pd->solvable = pool->solvables + id;
+             pd->solvable = pool_id2solvable(pool, repo_add_solvable_block(pd->repo, pd->numpacks));
            }
        }
       break;
     case STATE_PACKAGE:
       if (pd->numpacks > 0)
-       pd->numpacks--;
-      else
        {
-         id = repo_add_solvable(pd->repo);
-         pd->solvable = pool->solvables + id;
+         pd->numpacks--;
+         pd->solvable++;
        }
+      else
+       pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
 #if 0
       fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
 #endif
@@ -373,14 +372,11 @@ endElement(void *userData, const char *name)
   switch (pd->state)
     {
     case STATE_PACKAGE:
-      s->repo = pd->repo;
-      pd->repo->nsolvables++;
       if (!s->arch)
         s->arch = ARCH_NOARCH;
       if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
         s->provides = repo_addid_dep(pd->repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
       s->supplements = repo_fix_legacy(pd->repo, s->provides, s->supplements);
-      pd->solvable++;
       break;
     case STATE_NAME:
       s->name = str2id(pool, pd->content, 1);
index 11cab744322dddc1a235c82dab5aa3f356f6bc4b..130183b6d85a3a35e00b1a211d69a80c9f277b12 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "attr_store.h"
 #include "repo_susetags.h"
 
@@ -148,7 +149,6 @@ repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr)
   int pack;
   char *sp[5];
   struct parsedata pd;
-  Id id;
 
   if (with_attr)
     attr = new_store(pool);
@@ -236,12 +236,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr)
          pd.kind = 0;
          if (line[3] == 't')
            pd.kind = "pattern";
-         id = repo_add_solvable(repo);
-         s = pool->solvables + id;
-         s->repo = repo;
-         repo->nsolvables++;
-         last_found_pack = pack;
-         pack++;
+         s = pool_id2solvable(pool, repo_add_solvable(repo));
+         last_found_pack = (s - pool->solvables) - repo->start;
           if (split(line + 5, sp, 5) != 4)
            {
              fprintf(stderr, "Bad line: %s\n", line);
@@ -285,18 +281,18 @@ repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr)
             lines comes in roughly the same order as the first set, so we 
             have a hint at where to start our search, namely were we found
             the last entry.  */
-         for (n = 0, nn = last_found_pack; n < pack; n++, nn++)
+         for (n = repo->start, nn = n + last_found_pack; n < repo->end; n++, nn++)
            {
-             if (nn >= pack)
-               nn = 0;
-             s = pool->solvables + pool->nsolvables + nn;
-             if (s->name == name && s->evr == evr && s->arch == arch)
+             if (nn >= repo->end)
+               nn = repo->start;
+             s = pool->solvables + nn;
+             if (s->repo == repo && s->name == name && s->evr == evr && s->arch == arch)
                break;
            }
          if (n == pack)
            s = 0;
          else
-           last_found_pack = nn;
+           last_found_pack = nn - repo->start;
          continue;
        }
       /* If we have no current solvable to add to, ignore all further lines
index 8ce42cb5c46a398d02107e1d74b2d22468505bb5..abdfc0073f3108763bbf220da114b7309d7fbbbf 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_rpmdb.h"
 #include "repo_solv.h"
 #include "repo_write.h"
index ad7638a1351b41b800282a40a331563f94bcaf8d..f494106f002a7612d51ba0d6a421f4ad7c5ae637 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_rpmmd.h"
 #include "repo_write.h"
 
index 321a51e27cc7386b83db50a1a8760f84ef21b610..09e7b51d574b187d97f1a78788ed6e8888ba465a 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_susetags.h"
 #include "repo_write.h"
 #include "attr_store.h"