It's nicer to represent the special numbers as TYPE_VOID with the actual
authorMichael Matz <matz@suse.de>
Mon, 14 Jan 2008 16:25:33 +0000 (16:25 +0000)
committerMichael Matz <matz@suse.de>
Mon, 14 Jan 2008 16:25:33 +0000 (16:25 +0000)
value sitting in key->size.

src/attr_store.c
src/attr_store_p.h
src/pool.h
src/repo_solv.c
tools/dumpattr.c

index a9fc2d6..3deb7ca 100644 (file)
@@ -352,14 +352,9 @@ add_attr_int (Attrstore *s, unsigned int entry, Id name, unsigned int val)
 void
 add_attr_special_int (Attrstore *s, unsigned int entry, Id name, unsigned int val)
 {
-  if (val > (TYPE_ATTR_SPECIAL_END - TYPE_ATTR_SPECIAL_START))
-    add_attr_int (s, entry, name, val);
-  else
-    {
-      LongNV nv;
-      nv.key = add_key (s, name, TYPE_ATTR_SPECIAL_START + val, 0);
-      add_attr (s, entry, nv);
-    }
+  LongNV nv;
+  nv.key = add_key (s, name, TYPE_VOID, val);
+  add_attr (s, entry, nv);
 }
 
 static void
@@ -505,14 +500,17 @@ static Id read_id (FILE *fp, Id max);
 /* This routine is used only when attributes are embedded into the
    normal repo SOLV file.  */
 void
-add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, unsigned maxid, FILE *fp)
+add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, unsigned maxid, FILE *fp, unsigned size)
 {
   Pool *pool = s->pool;
   //fprintf (stderr, "%s: attribute in a repo SOLV?\n", id2str (pool, name));
   switch (type)
     {
       case TYPE_VOID:
-        add_attr_void (s, entry, name);
+       if (size)
+         add_attr_special_int (s, entry, name, size);
+       else
+          add_attr_void (s, entry, name);
        break;
       case TYPE_ATTR_CHUNK:
        {
@@ -582,11 +580,6 @@ add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap,
        }
        break;
       default:
-        if (type >= TYPE_ATTR_SPECIAL_START && type <= TYPE_ATTR_SPECIAL_END)
-         {
-           add_attr_special_int (s, entry, name, type - TYPE_ATTR_SPECIAL_START);
-           break;
-         }
        pool_debug(pool, SAT_FATAL, "unknown type %d\n", type);
        exit(0);
     }
@@ -816,11 +809,13 @@ add_key (Attrstore *s, Id name, unsigned type, unsigned size)
 {
   unsigned i;
   for (i = 0; i < s->nkeys; i++)
-    if (s->keys[i].name == name && s->keys[i].type == type)
+    if (s->keys[i].name == name && s->keys[i].type == type
+       && (type != TYPE_VOID || s->keys[i].size == size))
       break;
   if (i < s->nkeys)
     {
-      s->keys[i].size += size;
+      if (type != TYPE_VOID)
+        s->keys[i].size += size;
       return i;
     }
   if ((s->nkeys & KEY_BLOCK) == 0)
@@ -1058,7 +1053,10 @@ attr_store_unpack (Attrstore *s)
          switch (ai.type)
            {
            case TYPE_VOID:
-             add_attr_void (s, i, ai.name);
+             if (ai.as_int)
+               add_attr_special_int (s, i, ai.name, ai.as_int);
+             else
+               add_attr_void (s, i, ai.name);
              break;
            case TYPE_ATTR_INT:
              add_attr_int (s, i, ai.name, ai.as_int); 
@@ -1094,9 +1092,6 @@ attr_store_unpack (Attrstore *s)
                break;
              }
            default:
-             if (ai.type >= TYPE_ATTR_SPECIAL_START
-                 && ai.type <= TYPE_ATTR_SPECIAL_END)
-               add_attr_special_int (s, i, ai.name, ai.type - TYPE_ATTR_SPECIAL_START);
              break;
            }
        }
index d8b007c..cbadf55 100644 (file)
@@ -98,7 +98,7 @@ struct _Attrstore
   unsigned int packed:1;
 };
 
-void add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, unsigned maxid, FILE *fp);
+void add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, unsigned maxid, FILE *fp, unsigned size);
 void read_or_setup_pages (FILE *fp, Attrstore *s);
 
 #define get_num(ptr,val) do { \
@@ -159,7 +159,8 @@ ai_step (Attrstore *s, attr_iterator *ai)
   switch (ai->type)
     {
     case TYPE_VOID:
-      /* No data.  */
+      /* No data, except perhaps a constant value.  */
+      ai->as_int = s->keys[key].size;
       break;
     case TYPE_ATTR_INT:
       {
@@ -208,7 +209,6 @@ ai_step (Attrstore *s, attr_iterator *ai)
        break;
       }
     default:
-      /* ??? Convert TYPE_ATTR_SPECIAL_* to _INT type with the right value? */
       break;
     }
   return 1;
index 1e0b58a..a4f42c1 100644 (file)
@@ -128,6 +128,12 @@ struct _Pool {
 #define SAT_DEBUG_JOB                  (1<<11)
 #define SAT_DEBUG_SCHUBI               (1<<12)
 
+/* The void type is usable to encode one-valued attributes, they have
+   no associated data.  This is useful to encode values which many solvables
+   have in common, and whose overall set is relatively limited.  A prime
+   example would be the media number.  The actual value is encoded in the
+   SIZE member of the key structure.  Be warned: careless use of this
+   leads to combinatoric explosion of number of schemas.  */
 #define TYPE_VOID               0
 #define TYPE_ID                        1
 #define TYPE_IDARRAY           2
@@ -147,14 +153,7 @@ struct _Pool {
 #define TYPE_IDVALUEARRAY      13
 #define TYPE_IDVALUEVALUEARRAY 14
 
-/* The special types are usable to encode one-valued attributes, they have
-   no associated data.  This is useful to encode values which many solvables
-   have in common, and whose overall set is relatively limited.  A prime
-   example would be the media number.  Be warned: careless use of this
-   leads to combinatoric explosion of number of schemas.  */
-#define TYPE_ATTR_SPECIAL_START        15
-#define TYPE_ATTR_SPECIAL_END  (TYPE_ATTR_SPECIAL_START + 31)
-#define TYPE_ATTR_TYPE_MAX     TYPE_ATTR_SPECIAL_END
+#define TYPE_ATTR_TYPE_MAX     TYPE_IDVALUEVALUEARRAY
 
 //-----------------------------------------------
 
index 4ccb8c8..e09946b 100644 (file)
@@ -1040,7 +1040,7 @@ repo_add_solv(Repo *repo, FILE *fp)
            case TYPE_ATTR_LOCALIDS:
              if (!embedded_store)
                embedded_store = new_store (pool);
-             add_attr_from_file (embedded_store, i, id, keys[key].type, idmap, numid, &data);
+             add_attr_from_file (embedded_store, i, id, keys[key].type, idmap, numid, &data, keys[key].size);
              break;
 #endif
            default:
index 87657d3..19b3ab9 100644 (file)
@@ -59,6 +59,9 @@ dump_attrs (Attrstore *s, unsigned int entry)
       fprintf (stdout, "%s:", id2str (s->pool, ai.name));
       switch (ai.type)
        {
+       case TYPE_VOID:
+         fprintf (stdout, "spec %d\n", ai.as_int);
+         break;
        case TYPE_ATTR_INT:
          fprintf (stdout, "int  %u\n", ai.as_int);
          break;
@@ -106,10 +109,6 @@ dump_attrs (Attrstore *s, unsigned int entry)
            break;
          }
        default:
-         if (ai.type >= TYPE_ATTR_SPECIAL_START
-             && ai.type <= TYPE_ATTR_SPECIAL_END)
-           fprintf (stdout, "spec %d", ai.type - TYPE_ATTR_SPECIAL_START);
-         fprintf (stdout, "\n");
          break;
        }
     }