- 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 2e79b43..553f698 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 84a40eb..8231055 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 381cc73..82ac9f2 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 a7263ef..2a38264 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 f1e3c0a..28d93ab 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 ad69ef9..30a6350 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_content.h"
 #include "repo_write.h"
 
index 21dc0ff..6555af4 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_patchxml.h"
 #include "repo_write.h"
 
index a6d74d4..f31900b 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 33bce55..f6df2b2 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 2930313..d270810 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 d4eb8be..c70ab6d 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 1f90962..877f793 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 11cab74..130183b 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 8ce42cb..abdfc00 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 ad7638a..f494106 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "pool.h"
+#include "repo.h"
 #include "repo_rpmmd.h"
 #include "repo_write.h"
 
index 321a51e..09e7b51 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"