- make repodata also start with id 1
authorMichael Schroeder <mls@suse.de>
Thu, 22 Dec 2011 15:45:05 +0000 (16:45 +0100)
committerMichael Schroeder <mls@suse.de>
Thu, 22 Dec 2011 15:45:05 +0000 (16:45 +0100)
bindings/solv.i
examples/solv.c
src/repo.c
src/repo.h
src/repo_solv.c
src/repodata.c

index 16e60d0..39c2ee0 100644 (file)
@@ -1164,7 +1164,7 @@ typedef struct {
   # HACK, remove if no longer needed!
   bool write_first_repodata(FILE *fp) {
     int oldnrepodata = $self->nrepodata;
-    $self->nrepodata = 1;
+    $self->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata;
     repo_write($self, fp, repo_write_stdkeyfilter, 0, 0);
     $self->nrepodata = oldnrepodata;
     return 1;
@@ -1217,15 +1217,15 @@ typedef struct {
   }
   XRepodata *first_repodata() {
      int i;
-     if (!$self->nrepodata)
+     if ($self->nrepodata < 2)
        return 0;
      /* make sure all repodatas but the first are extensions */
-     if ($self->repodata[0].loadcallback)
+     if ($self->repodata[1].loadcallback)
         return 0;
-     for (i = 1; i < $self->nrepodata; i++)
+     for (i = 2; i < $self->nrepodata; i++)
        if (!$self->repodata[i].loadcallback)
          return 0;       /* oops, not an extension */
-     return new_XRepodata($self, 0);
+     return new_XRepodata($self, 1);
    }
 
   bool __eq__(Repo *repo) {
index a683387..cb5992c 100644 (file)
@@ -1115,7 +1115,7 @@ writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *
   else
     {
       int oldnrepodata = repo->nrepodata;
-      repo->nrepodata = 1;     /* XXX: do this right */
+      repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata;   /* XXX: do this right */
       repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
       repo->nrepodata = oldnrepodata;
       onepiece = 0;
@@ -2478,7 +2478,7 @@ rewrite_repos(Pool *pool, Id *addedfileprovides)
       if (!repo->nrepodata)
        continue;
       cinfo = repo->appdata;
-      data = repo->repodata + 0;
+      data = repo->repodata + 1;
       if (data->store.pagefd == -1)
        continue;
       if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
index 75f6f37..418ba7f 100644 (file)
@@ -64,7 +64,7 @@ void
 repo_freedata(Repo *repo)
 {
   int i;
-  for (i = 0; i < repo->nrepodata; i++)
+  for (i = 1; i < repo->nrepodata; i++)
     repodata_freedata(repo->repodata + i);
   solv_free(repo->repodata);
   solv_free(repo->idarraydata);
@@ -104,7 +104,7 @@ repo_empty(Repo *repo, int reuseids)
   repo->idarraysize = 0;
   repo->lastoff = 0;
   repo->rpmdbid = solv_free(repo->rpmdbid);
-  for (i = 0; i < repo->nrepodata; i++)
+  for (i = 1; i < repo->nrepodata; i++)
     repodata_freedata(repo->repodata + i);
   solv_free(repo->repodata);
   repo->repodata = 0;
@@ -1287,7 +1287,7 @@ repo_add_repodata(Repo *repo, int flags)
   int i;
   if ((flags & REPO_USE_LOADING) != 0)
     {
-      for (i = repo->nrepodata - 1; i >= 0; i--)
+      for (i = repo->nrepodata - 1; i > 0; i--)
        if (repo->repodata[i].state == REPODATA_LOADING)
          {
            Repodata *data = repo->repodata + i;
@@ -1301,7 +1301,7 @@ repo_add_repodata(Repo *repo, int flags)
     }
   if ((flags & REPO_REUSE_REPODATA) != 0)
     {
-      for (i = repo->nrepodata - 1; i >= 0; i--)
+      for (i = repo->nrepodata - 1; i > 0; i--)
        if (repo->repodata[i].state != REPODATA_STUB)
          return repo->repodata + i;
     }
@@ -1312,7 +1312,7 @@ Repodata *
 repo_last_repodata(Repo *repo)
 {
   int i;
-  for (i = repo->nrepodata - 1; i >= 0; i--)
+  for (i = repo->nrepodata - 1; i > 0; i--)
     if (repo->repodata[i].state != REPODATA_STUB)
       return repo->repodata + i;
   return repo_add_repodata(repo, 0);
index e96751d..52bec4a 100644 (file)
@@ -290,6 +290,6 @@ void repo_internalize(Repo *repo);
 void repo_disable_paging(Repo *repo);
 
 #define FOR_REPODATAS(repo, rdid, data)        \
-       for (rdid = 0, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
+       for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
 
 #endif /* LIBSOLV_REPO_H */
index 6c21584..cbc6c93 100644 (file)
@@ -1295,7 +1295,13 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
   else
     {
       /* make it available as new repodata */
-      repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
+      if (!repo->nrepodata)
+       {
+         repo->nrepodata = 1;
+         repo->repodata = solv_calloc(2, sizeof(data));
+       }
+      else
+        repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
       repo->repodata[repo->nrepodata++] = data;
     }
 
index c9dd25e..3753a26 100644 (file)
@@ -97,8 +97,16 @@ repodata_create(Repo *repo, int localpool)
 {
   Repodata *data;
 
-  repo->nrepodata++;
-  repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
+  if (!repo->nrepodata)
+    {
+      repo->nrepodata = 2;     /* start with id 1 */
+      repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
+    }
+  else
+    {
+      repo->nrepodata++;
+      repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
+    }
   data = repo->repodata + repo->nrepodata - 1;
   repodata_initdata(data, repo, localpool);
   return data;
@@ -113,6 +121,11 @@ repodata_free(Repodata *data)
   if (i < repo->nrepodata - 1)
     memmove(repo->repodata + i, repo->repodata + i + 1, (repo->nrepodata - 1 - i) * sizeof(Repodata));
   repo->nrepodata--;
+  if (repo->nrepodata == 1)
+    {
+      repo->repodata = solv_free(repo->repodata);
+      repo->nrepodata = 0;
+    }
 }
 
 void
@@ -1180,7 +1193,7 @@ dataiterator_set_search(Dataiterator *di, Repo *repo, Id p)
   di->flags &= ~SEARCH_THISSOLVID;
   di->nparents = 0;
   di->rootlevel = 0;
-  di->repodataid = 0;
+  di->repodataid = 1;
   if (!di->pool->urepos)
     {
       di->state = di_bye;
@@ -1287,9 +1300,9 @@ dataiterator_step(Dataiterator *di)
          /* FALLTHROUGH */
 
        case di_entersolvable: di_entersolvable:
-         if (di->repodataid >= 0)
+         if (di->repodataid)
            {
-             di->repodataid = 0;       /* reset repodata iterator */
+             di->repodataid = 1;       /* reset repodata iterator */
              if (di->solvid > 0 && !(di->flags & SEARCH_NO_STORAGE_SOLVABLE) && (!di->keyname || (di->keyname >= SOLVABLE_NAME && di->keyname <= RPM_RPMDBID)) && di->nparents - di->rootlevel == di->nkeynames)
                {
                  di->key = solvablekeys + (di->keyname ? di->keyname - SOLVABLE_NAME : 0);
@@ -1300,13 +1313,13 @@ dataiterator_step(Dataiterator *di)
          /* FALLTHROUGH */
 
        case di_enterrepodata: di_enterrepodata:
-         if (di->repodataid >= 0)
+         if (di->repodataid)
            {
              if (di->repodataid >= di->repo->nrepodata)
                goto di_nextsolvable;
              di->data = di->repo->repodata + di->repodataid;
            }
-         if (di->repodataid >= 0 && di->keyname == SOLVABLE_FILELIST && !dataiterator_filelistcheck(di))
+         if (di->repodataid && di->keyname == SOLVABLE_FILELIST && !dataiterator_filelistcheck(di))
            goto di_nextrepodata;
          if (!maybe_load_repodata(di->data, di->keyname))
            goto di_nextrepodata;
@@ -1361,7 +1374,7 @@ dataiterator_step(Dataiterator *di)
          /* FALLTHROUGH */
 
        case di_nextrepodata: di_nextrepodata:
-         if (di->repodataid >= 0 && ++di->repodataid < di->repo->nrepodata)
+         if (di->repodataid && ++di->repodataid < di->repo->nrepodata)
              goto di_enterrepodata;
          /* FALLTHROUGH */
 
@@ -1384,7 +1397,7 @@ dataiterator_step(Dataiterator *di)
          if (di->repoid > 0)
            {
              di->repoid++;
-             di->repodataid = 0;
+             di->repodataid = 1;
              if (di->repoid < di->pool->nrepos)
                {
                  di->repo = di->pool->repos[di->repoid];
@@ -1676,7 +1689,7 @@ dataiterator_jump_to_solvid(Dataiterator *di, Id solvid)
        }
       di->repoid = 0;
       di->data = di->repo->repodata + di->pool->pos.repodataid;
-      di->repodataid = -1;
+      di->repodataid = 0;
       di->solvid = solvid;
       di->state = di_enterrepo;
       di->flags |= SEARCH_THISSOLVID;
@@ -1697,7 +1710,7 @@ dataiterator_jump_to_solvid(Dataiterator *di, Id solvid)
       di->repoid = 1;
       di->repo = di->pool->repos[di->repoid];
     }
-  di->repodataid = 0;
+  di->repodataid = 1;
   di->solvid = solvid;
   if (solvid)
     di->flags |= SEARCH_THISSOLVID;
@@ -1712,7 +1725,7 @@ dataiterator_jump_to_repo(Dataiterator *di, Repo *repo)
   di->rootlevel = 0;
   di->repo = repo;
   di->repoid = 0;      /* 0 means stay at repo */
-  di->repodataid = 0;
+  di->repodataid = 1;
   di->solvid = 0;
   di->flags &= ~SEARCH_THISSOLVID;
   di->state = di_enterrepo;