One-valued types for media number. They can be encoded in the schema,
authorMichael Matz <matz@suse.de>
Tue, 18 Dec 2007 21:09:58 +0000 (21:09 +0000)
committerMichael Matz <matz@suse.de>
Tue, 18 Dec 2007 21:09:58 +0000 (21:09 +0000)
no need for storing 1, 2 or 3 all the time.

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

index 3d9e2d5..85978dd 100644 (file)
@@ -154,6 +154,19 @@ add_attr_int (Attrstore *s, unsigned int entry, Id name, unsigned int val)
   add_attr (s, entry, nv);
 }
 
+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);
+    }
+}
+
 static void
 add_attr_chunk (Attrstore *s, unsigned int entry, Id name, unsigned int ofs, unsigned int len)
 {
@@ -342,6 +355,11 @@ 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);
     }
@@ -781,6 +799,9 @@ 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 61ab5b1..657b5b6 100644 (file)
@@ -33,6 +33,7 @@ LocalId str2localid (Attrstore *s, const char *str, int create);
 const char * localid2str(Attrstore *s, LocalId id);
 
 void 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);
 void add_attr_blob (Attrstore *s, unsigned int entry, Id name, const void *ptr, unsigned int len);
 void add_attr_string (Attrstore *s, unsigned int entry, Id name, const char *val);
 void add_attr_intlist_int (Attrstore *s, unsigned int entry, Id name, int val);
index 4760af0..6258aed 100644 (file)
@@ -185,6 +185,7 @@ ai_step (Attrstore *s, attr_iterator *ai)
        break;
       }
     default:
+      /* ??? Convert TYPE_ATTR_SPECIAL_* to _INT type with the right value? */
       break;
     }
   return 1;
index 4042a04..261c7c2 100644 (file)
@@ -142,11 +142,19 @@ struct _Pool {
 
 #define TYPE_COUNT_NAMED       11
 #define TYPE_COUNTED           12
-#define TYPE_ATTR_TYPE_MAX     12
 
 #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
+
 //-----------------------------------------------
 
 
index b59400b..5930f1c 100644 (file)
@@ -71,6 +71,9 @@ 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;
        }
index 932d881..b4c9fc3 100644 (file)
@@ -159,7 +159,7 @@ add_location (char *line, Solvable *s, unsigned entry)
     {
       /* medianr filename dir
          don't optimize this one */
-      add_attr_int (attr, entry, str2id (pool, "medianr", 1), atoi (sp[0]));
+      add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), atoi (sp[0]));
       add_attr_localids_id (attr, entry, str2id (pool, "mediadir", 1), str2localid (attr, sp[2], 1));
       add_attr_string (attr, entry, str2id (pool, "mediafile", 1), sp[1]);
       return;
@@ -190,12 +190,12 @@ add_location (char *line, Solvable *s, unsigned entry)
          break;
       if (*n2 || strcmp (n1, ".rpm"))
         goto nontrivial;
-      add_attr_int (attr, entry, str2id (pool, "medianr", 1), medianr);
+      add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), medianr);
       add_attr_void (attr, entry, str2id (pool, "mediafile", 1));
       return;
 
 nontrivial:
-      add_attr_int (attr, entry, str2id (pool, "medianr", 1), medianr);
+      add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), medianr);
       add_attr_string (attr, entry, str2id (pool, "mediafile", 1), sp[1]);
       return;
     }