- add lookup_id function
authorMichael Schroeder <mls@suse.de>
Thu, 20 Mar 2008 16:59:17 +0000 (16:59 +0000)
committerMichael Schroeder <mls@suse.de>
Thu, 20 Mar 2008 16:59:17 +0000 (16:59 +0000)
src/pool.h
src/repodata.c
src/repodata.h
src/solvable.c

index 374ad81..dde9587 100644 (file)
@@ -166,6 +166,7 @@ extern const char *solvable2str(Pool *pool, Solvable *s);
 
 void pool_set_languages(Pool *pool, const char **languages, int nlanguages);
 
+Id solvable_lookup_id(Solvable *s, Id keyname);
 unsigned int solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound);
 const char *solvable_lookup_str(Solvable *s, Id keyname);
 const char *solvable_lookup_str_poollang(Solvable *s, Id keyname);
index e4b0794..ddcc767 100644 (file)
@@ -363,6 +363,35 @@ maybe_load_repodata(Repodata *data, Id *keyid)
   return 0;
 }
 
+Id
+repodata_lookup_id(Repodata *data, Id entry, Id keyid)
+{
+  Id schema;
+  Repokey *key;
+  Id id, *keyp;
+  unsigned char *dp;
+
+  if (!maybe_load_repodata(data, &keyid))
+    return 0;
+  dp = data->incoredata + data->incoreoffset[entry];
+  dp = data_read_id(dp, &schema);
+  /* make sure the schema of this solvable contains the key */
+  for (keyp = data->schemadata + data->schemata[schema]; *keyp != keyid; keyp++)
+    if (!*keyp)
+      return 0;
+  dp = forward_to_key(data, keyid, schema, dp);
+  key = data->keys + keyid;
+  dp = get_data(data, key, &dp);
+  if (!dp)
+    return 0;
+  if (key->type == REPOKEY_TYPE_CONSTANTID)
+    return key->size;
+  if (key->type != REPOKEY_TYPE_ID)
+    return 0;
+  dp = data_read_id(dp, &id);
+  return id;
+}
+
 const char *
 repodata_lookup_str(Repodata *data, Id entry, Id keyid)
 {
index 715a28a..6139db9 100644 (file)
@@ -108,29 +108,26 @@ typedef struct _Repodata {
   Id *addedfileprovides;
 } Repodata;
 
+/* management functions */
+void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
+void repodata_extend(Repodata *data, Id p);
+void repodata_extend_block(Repodata *data, Id p, int num);
+void repodata_free(Repodata *data);
+
 /* Search key <keyname> (all keys, if keyname == 0) for Id <entry>
  * <entry> is _relative_ Id for <data>
  * Call <callback> for each match
  */
 void repodata_search(Repodata *data, Id entry, Id keyname, int (*callback)(void *cbdata, Solvable *s, Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
 
-/*
- * lookup string type attribute
- */
+/* lookup functions */
+Id repodata_lookup_id(Repodata *data, Id entry, Id keyid);
 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyid);
-
-/*
- * lookup integer type attribute
- */
 int repodata_lookup_num(Repodata *data, Id entry, Id keyid, unsigned *value);
 int repodata_lookup_void(Repodata *data, Id entry, Id keyid);
 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id entry, Id keyid, Id *typep);
 
-void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
-void repodata_extend(Repodata *data, Id p);
-void repodata_extend_block(Repodata *data, Id p, int num);
-void repodata_free(Repodata *data);
-
+/* data assignment */
 void repodata_set_id(Repodata *data, Id entry, Id keyname, Id id);
 void repodata_set_num(Repodata *data, Id entry, Id keyname, Id num);
 void repodata_set_poolstr(Repodata *data, Id entry, Id keyname, const char *str);
@@ -152,13 +149,15 @@ void repodata_merge_attrs (Repodata *data, Id dest, Id src);
 void repodata_internalize(Repodata *data);
 void repodata_disable_paging(Repodata *data);
 
+/* helper functions */
+Id repodata_globalize_id(Repodata *data, Id id);
 Id repodata_str2dir(Repodata *data, const char *dir, int create);
 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
 
+/* internal */
 unsigned int repodata_compress_page(unsigned char *, unsigned int, unsigned char *, unsigned int);
 void repodata_read_or_setup_pages(Repodata *data, unsigned int pagesz, unsigned int blobsz);
 
-Id repodata_globalize_id(Repodata *data, Id id);
 
 #endif /* SATSOLVER_REPODATA_H */
index cef1eba..75587e4 100644 (file)
@@ -34,6 +34,50 @@ solvable2str(Pool *pool, Solvable *s)
   return p;
 }
 
+Id
+solvable_lookup_id(Solvable *s, Id keyname)
+{
+  Repo *repo = s->repo;
+  Pool *pool;
+  Repodata *data;
+  int i, j, n;
+
+  if (!repo)
+    return 0;
+  pool = repo->pool;
+  switch(keyname)
+    {   
+    case SOLVABLE_NAME:
+      return s->name;
+    case SOLVABLE_ARCH:
+      return s->arch;
+    case SOLVABLE_EVR:
+      return s->evr;
+    case SOLVABLE_VENDOR:
+      return s->vendor;
+    }   
+  n = s - pool->solvables;
+  for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+    {   
+      if (n < data->start || n >= data->end)
+        continue;
+      for (j = 1; j < data->nkeys; j++)
+        {
+          if (data->keys[j].name == keyname && (data->keys[j].type == REPOKEY_TYPE_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID))
+           {
+              Id id = repodata_lookup_id(data, n - data->start, j); 
+             if (id)
+               {
+                 if (data->localpool)
+                   id = repodata_globalize_id(data, id);
+                 return id;
+               }
+           }
+        }
+    }
+  return 0;
+}
+
 const char *
 solvable_lookup_str(Solvable *s, Id keyname)
 {