- fix bug in solv loading callback
authorMichael Schroeder <mls@suse.de>
Mon, 3 Mar 2008 17:08:41 +0000 (17:08 +0000)
committerMichael Schroeder <mls@suse.de>
Mon, 3 Mar 2008 17:08:41 +0000 (17:08 +0000)
- add pool_set_languages and solvable_lookup_str_lang

src/pool.c
src/pool.h
src/repo.c
src/repo.h
src/repodata.c

index 8dc56c2..a7298b2 100644 (file)
@@ -160,6 +160,9 @@ pool_free(Pool *pool)
   queue_free(&pool->vendormap);
   for (i = 0; i < DEP2STRBUF; i++)
     sat_free(pool->dep2strbuf[i]);
+  for (i = 0; i < pool->nlanguages; i++)
+    free((char *)pool->languages[i]);
+  sat_free(pool->languages);
   sat_free(pool);
 }
 
@@ -892,7 +895,8 @@ pool_addfileprovides(Pool *pool, Repo *installed)
   pool_freewhatprovides(pool); /* as we have added provides */
 }
 
-void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata)
+void
+pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata)
 {
   if (p)
     {
@@ -906,4 +910,80 @@ void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*c
       repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
 }
 
+
+void
+pool_set_languages(Pool *pool, const char **languages, int nlanguages)
+{
+  int i;
+
+  pool->languagecache = sat_free(pool->languagecache);
+  pool->languagecacheother = 0;
+  if (pool->nlanguages)
+    {
+      for (i = 0; i < pool->nlanguages; i++)
+       free((char *)pool->languages[i]);
+      free(pool->languages);
+    }
+  pool->nlanguages = nlanguages;
+  if (!nlanguages)
+    return;
+  pool->languages = sat_calloc(nlanguages, sizeof(const char **));
+  for (i = 0; i < pool->nlanguages; i++)
+    pool->languages[i] = strdup(languages[i]);
+}
+
+const char *
+solvable_lookup_str_lang(Solvable *s, Id keyname)
+{
+  Pool *pool;
+  int i, cols;
+  const char *str;
+  Id *row;
+
+  if (!s->repo)
+    return repo_lookup_str(s, keyname);
+  pool = s->repo->pool;
+  if (!pool->nlanguages)
+    return repo_lookup_str(s, keyname);
+  cols = pool->nlanguages + 1;
+  if (!pool->languagecache)
+    {
+      pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
+      pool->languagecacheother = 0;
+    }
+  if (keyname >= ID_NUM_INTERNAL)
+    {
+      row = pool->languagecache + ID_NUM_INTERNAL * cols;
+      for (i = 0; i < pool->languagecacheother; i++, row += cols)
+       if (*row == keyname)
+         break;
+      if (i >= pool->languagecacheother)
+       {
+         pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
+         pool->languagecacheother++;
+         row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
+       }
+    }
+  else
+    row = pool->languagecache + keyname * cols;
+  row++;       /* skip keyname */
+  for (i = 0; i < pool->nlanguages; i++, row++)
+    {
+      if (!*row)
+       {
+         char *p;
+         const char *kn;
+
+         kn = id2str(pool, keyname);
+          p = sat_malloc(strlen(kn) + strlen(pool->languages[i]) + 2);
+         sprintf(p, "%s:%s", kn, pool->languages[i]);
+         *row = str2id(pool, p, 1);
+       }
+      str = repo_lookup_str(s, *row);
+      if (str)
+       return str;
+    }
+  return repo_lookup_str(s, keyname);
+}
+
 // EOF
index 99d1e57..be6e76a 100644 (file)
@@ -134,6 +134,11 @@ struct _Pool {
   Solvable *solvables;
   int nsolvables;
 
+  const char **languages;
+  int nlanguages;
+  Id *languagecache;
+  int languagecacheother;
+
   int promoteepoch;             /* 0/1  */
 
   Id *id2arch;                 /* map arch ids to scores */
@@ -234,6 +239,9 @@ static inline Solvable *pool_id2solvable(Pool *pool, Id p)
 }
 extern const char *solvable2str(Pool *pool, Solvable *s);
 
+void pool_set_languages(Pool *pool, const char **languages, int nlanguages);
+const char *solvable_lookup_str_lang(Solvable *s, Id keyname);
+
 
 /**
  * Prepares a pool for solving
index 208d954..bd9cb21 100644 (file)
@@ -814,6 +814,7 @@ repo_lookup_num(Solvable *s, Id key)
  * generic attribute lookup
  * returns non-zero if found
  * zero if not found
+ * (XXX: return value is broken atm!)
  */
 
 int
@@ -829,13 +830,15 @@ repo_lookup(Solvable *s, Id key, int (*callback)(void *cbdata, Solvable *s, Repo
     {
       if (s_id < data->start || s_id >= data->end)
        continue;
-      repodata_search (data, s_id - data->start, key, callback, cbdata);
+      repodata_search(data, s_id - data->start, key, callback, cbdata);
       return 1;
     }
   return 0;
 }
 
 
+/***********************************************************************/
+
 Repodata *
 repo_add_repodata(Repo *repo)
 {
@@ -908,57 +911,6 @@ repo_internalize(Repo *repo)
       repodata_internalize(data);
 }
 
-
-#if 0
-
-static int
-key_cmp (const void *pa, const void *pb)
-{
-  Repokey *a = (Repokey *)pa;
-  Repokey *b = (Repokey *)pb;
-  return a->name - b->name;
-}
-
-void
-repo_add_attrstore (Repo *repo, Attrstore *s, const char *location)
-{
-  unsigned i;
-  Repodata *data;
-  /* If this is meant to be the embedded attributes, make sure we don't
-     have them already.  */
-  if (!location)
-    {
-      for (i = 0; i < repo->nrepodata; i++)
-        if (repo->repodata[i].location == 0)
-         break;
-      if (i != repo->nrepodata)
-        {
-         pool_debug (repo->pool, SAT_FATAL, "embedded attribs added twice\n");
-         exit (1);
-       }
-    }
-  repo->nrepodata++;
-  repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
-  data = repo->repodata + repo->nrepodata - 1;
-  memset (data, 0, sizeof (*data));
-  data->s = s;
-  data->nkeys = s->nkeys;
-  if (data->nkeys)
-    {
-      data->keys = sat_malloc2(data->nkeys, sizeof(data->keys[0]));
-      for (i = 1; i < data->nkeys; i++)
-        {
-          data->keys[i].name = s->keys[i].name;
-         data->keys[i].type = s->keys[i].type;
-       }
-      if (data->nkeys > 2)
-        qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
-    }
-  if (location)
-    data->location = strdup(location);
-}
-#endif
-
 // EOF
 /*
 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4:
index 4e4495c..b7b9549 100644 (file)
@@ -22,7 +22,7 @@
 
 typedef struct _Repokey {
   Id name;
-  unsigned int type; /* TYPE_xxx */
+  Id type;              /* REPOKEY_TYPE_xxx */
   unsigned int size;
   unsigned int storage; /* KEY_STORAGE_xxx */
 } Repokey;
@@ -62,10 +62,6 @@ extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
 extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements);
 
-#if 0
-extern void repo_add_attrstore (Repo *repo, Attrstore *s, const char *location);
-#endif
-
 static inline const char *repo_name(const Repo *repo)
 {
   return repo->name;
index 60fc61f..558a083 100644 (file)
@@ -301,12 +301,33 @@ get_data(Repodata *data, Repokey *key, unsigned char **dpp)
 }
 
 static inline int
-maybe_load_repodata(Repodata *data)
+maybe_load_repodata(Repodata *data, Id *keyid)
 {
   if (data->state == REPODATA_STUB)
     {
       if (data->loadcallback)
-       data->loadcallback(data);
+       {
+         if (keyid)
+           {
+             /* key order may change when loading */
+             int i;
+             Id name = data->keys[*keyid].name;
+             Id type = data->keys[*keyid].type;
+             data->loadcallback(data);
+             if (data->state == REPODATA_AVAILABLE)
+               {
+                 for (i = 1; i < data->nkeys; i++)
+                   if (data->keys[i].name == name && data->keys[i].type == type)
+                     break;
+                 if (i < data->nkeys)
+                   *keyid = i;
+                 else
+                   return 0;
+               }
+           }
+         else
+           data->loadcallback(data);
+       }
       else
        data->state = REPODATA_ERROR;
     }
@@ -324,7 +345,7 @@ repodata_lookup_str(Repodata *data, Id entry, Id keyid)
   Id id, *keyp;
   unsigned char *dp;
 
-  if (!maybe_load_repodata (data))
+  if (!maybe_load_repodata(data, &keyid))
     return 0;
 
   dp = data->incoredata + data->incoreoffset[entry];
@@ -362,7 +383,7 @@ repodata_lookup_num(Repodata *data, Id entry, Id keyid, unsigned *value)
 
   *value = 0;
 
-  if (!maybe_load_repodata (data))
+  if (!maybe_load_repodata(data, &keyid))
     return 0;
 
   dp = data->incoredata + data->incoreoffset[entry];
@@ -398,7 +419,7 @@ repodata_search(Repodata *data, Id entry, Id keyname, int (*callback)(void *cbda
   int stop;
   KeyValue kv;
 
-  if (!maybe_load_repodata (data))
+  if (!maybe_load_repodata(data, 0))
     return;
 
   dp = data->incoredata + data->incoreoffset[entry];