Add REPOKEY_TYPE_COUNTED type (for arrays of structures).
authorMichael Matz <matz@suse.de>
Mon, 14 Apr 2008 12:58:23 +0000 (12:58 +0000)
committerMichael Matz <matz@suse.de>
Mon, 14 Apr 2008 12:58:23 +0000 (12:58 +0000)
We can add substructures now, but can't write or read them :)
Add version for the attributes to SOLV_VERSION_7 (not yet written).
Some cleanups.

src/knownid.h
src/pooltypes.h
src/repo.h
src/repo_solv.c
src/repodata.c
src/repodata.h
tools/repo_write.c

index f658f10..ce0876f 100644 (file)
@@ -75,6 +75,7 @@ KNOWNID(REPOKEY_TYPE_DIRNUMNUMARRAY,  "repokey:type:dirnumnumarray"),
 KNOWNID(REPOKEY_TYPE_MD5,              "repokey:type:md5"),
 KNOWNID(REPOKEY_TYPE_SHA1,             "repokey:type:sha1"),
 KNOWNID(REPOKEY_TYPE_SHA256,           "repokey:type:sha256"),
+KNOWNID(REPOKEY_TYPE_COUNTED,          "repokey:type:counted"),
 
 KNOWNID(SOLVABLE_SUMMARY,              "solvable:summary"),
 KNOWNID(SOLVABLE_DESCRIPTION,          "solvable:description"),
index 836bc9b..c1abe5a 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef SATSOLVER_POOLTYPES_H
 #define SATSOLVER_POOLTYPES_H
 
-/* version number for .solv files */
+/* format version number for .solv files */
 #define SOLV_VERSION_0 0
 #define SOLV_VERSION_1 1
 #define SOLV_VERSION_2 2
 #define SOLV_VERSION_6 6
 #define SOLV_VERSION_7 7
 
+/* The format of .solv files might change incompatibly, and that is described
+   by the above version number.  But sometimes we also extend the emitted
+   attributes (e.g. by adding a new one for solvables, for instance patch
+   category).  Consumers need to know if the .solv file they have needs to
+   be regenerated by newer converters or not (or better, if regenerating them
+   would give a different .solv file).  We use this serial number for that.
+   We increase it every time we add or remove attributes (or change the
+   interpretation of them).  Tools installed by the user will have their
+   version compiled in, so they can detect mismatches between .solv files
+   they see and themself.  */
+#define SOLV_CONTENT_VERSION 1
+
 #define SOLV_FLAG_PREFIX_POOL 4
 
 struct _Stringpool;
index 435c706..cc85d3c 100644 (file)
@@ -17,9 +17,6 @@
 
 #include "pooltypes.h"
 #include "pool.h"
-#if 0
-#include "attr_store.h"
-#endif
 #include "repodata.h"
 
 typedef struct _Repokey {
index 119a0db..6ff57a3 100644 (file)
@@ -722,7 +722,7 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
   Pool *pool = repo->pool;
   int i, l;
   unsigned int numid, numrel, numdir, numsolv;
-  unsigned int numkeys, numschemata, numinfo, numextra;
+  unsigned int numkeys, numschemata, numinfo, numextra, contentver;
 
   Offset sizeid;
   Offset *str;                        /* map Id -> Offset into string space */
@@ -789,9 +789,12 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
   numschemata = read_u32(&data);
   numinfo = read_u32(&data);
   if (solvversion > SOLV_VERSION_6)
-    numextra = read_u32(&data);
+    {
+      numextra = read_u32(&data);
+      contentver = read_u32(&data);
+    }
   else
-    numextra = 0;
+    numextra = 0, contentver = 1;
   solvflags = read_u32(&data);
 
   if (numdir && numdir < 2)
index 947ec4b..81d73f4 100644 (file)
@@ -1167,11 +1167,8 @@ repodata_insert_keyid(Repodata *data, Id handle, Id keyid, Id val, int overwrite
 {
   Id *pp;
   Id *ap;
-  Id sid;
   int i;
-  //sid = repodata_get_handle(data, handle);
-  sid = handle;
-  ap = data->structs[sid];
+  ap = data->structs[handle];
   i = 0;
   if (ap)
     {
@@ -1192,7 +1189,7 @@ repodata_insert_keyid(Repodata *data, Id handle, Id keyid, Id val, int overwrite
       i = pp - ap;
     }
   ap = sat_extend(ap, i, 3, sizeof(Id), REPODATA_ATTRS_BLOCK);
-  data->structs[sid] = ap;
+  data->structs[handle] = ap;
   pp = ap + i;
   *pp++ = keyid;
   *pp++ = val;
@@ -1315,7 +1312,7 @@ repodata_set_str(Repodata *data, Id handle, Id keyname, const char *str)
 }
 
 static void
-repoadata_add_array(Repodata *data, Id handle, Id keyname, Id keytype, int entrysize)
+repodata_add_array(Repodata *data, Id handle, Id keyname, Id keytype, int entrysize)
 {
   int oldsize;
   Id *ida, *pp;
@@ -1470,7 +1467,7 @@ repodata_add_dirnumnum(Repodata *data, Id handle, Id keyname, Id dir, Id num, Id
 #if 0
 fprintf(stderr, "repodata_add_dirnumnum %d %d %d %d (%d)\n", handle, dir, num, num2, data->attriddatalen);
 #endif
-  repoadata_add_array(data, handle, keyname, REPOKEY_TYPE_DIRNUMNUMARRAY, 3);
+  repodata_add_array(data, handle, keyname, REPOKEY_TYPE_DIRNUMNUMARRAY, 3);
   data->attriddata[data->attriddatalen++] = dir;
   data->attriddata[data->attriddatalen++] = num;
   data->attriddata[data->attriddatalen++] = num2;
@@ -1492,7 +1489,7 @@ repodata_add_dirstr(Repodata *data, Id handle, Id keyname, Id dir, const char *s
 #if 0
 fprintf(stderr, "repodata_add_dirstr %d %d %s (%d)\n", handle, dir, str,  data->attriddatalen);
 #endif
-  repoadata_add_array(data, handle, keyname, REPOKEY_TYPE_DIRSTRARRAY, 2);
+  repodata_add_array(data, handle, keyname, REPOKEY_TYPE_DIRSTRARRAY, 2);
   data->attriddata[data->attriddatalen++] = dir;
   data->attriddata[data->attriddatalen++] = stroff;
   data->attriddata[data->attriddatalen++] = 0;
@@ -1504,7 +1501,7 @@ repodata_add_idarray(Repodata *data, Id handle, Id keyname, Id id)
 #if 0
 fprintf(stderr, "repodata_add_idarray %d %d (%d)\n", handle, id, data->attriddatalen);
 #endif
-  repoadata_add_array(data, handle, keyname, REPOKEY_TYPE_IDARRAY, 1);
+  repodata_add_array(data, handle, keyname, REPOKEY_TYPE_IDARRAY, 1);
   data->attriddata[data->attriddatalen++] = id;
   data->attriddata[data->attriddatalen++] = 0;
 }
@@ -1521,17 +1518,13 @@ repodata_add_poolstr_array(Repodata *data, Id handle, Id keyname,
   repodata_add_idarray(data, handle, keyname, id);
 }
 
-#if 0
-void
-repodata_open_struct(Repodata *data, Id handle, Id keyname)
-{
-}
-
-void
-repodata_close_struct(Repodata *data, Id entry, Id keyname)
+Id
+repodata_create_struct(Repodata *data, Id handle, Id keyname)
 {
+  Id newhandle = get_new_struct(data);
+  repodata_add_idarray(data, handle, keyname, newhandle);
+  return newhandle;
 }
-#endif
 
 void
 repodata_merge_attrs(Repodata *data, Id dest, Id src)
@@ -1685,7 +1678,7 @@ repodata_internalize(Repodata *data)
     nentry = 0;
   for (entry = data->extraattrs ? -data->nextra : 0; entry < nentry; entry++)
     {
-      Id sid;
+      Id handle;
       memset(seen, 0, data->nkeys * sizeof(Id));
       sp = schema;
       dp = entry2data(data, entry);
@@ -1712,8 +1705,8 @@ fprintf(stderr, "schemadata %p\n", data->schemadata);
          *sp++ = *keyp;
          oldcount++;
        }
-      sid = entry < 0 ? data->extraattrs[-1 - entry] : data->attrs[entry];
-      keyp = data->structs[sid];
+      handle = entry < 0 ? data->extraattrs[-1 - entry] : data->attrs[entry];
+      keyp = data->structs[handle];
       if (keyp)
         for (; *keyp; keyp += 2)
          {
@@ -1840,8 +1833,8 @@ fprintf(stderr, "schemadata %p\n", data->schemadata);
            }
          dp = ndp;
        }
-      if (data->structs[sid])
-       data->structs[sid] = sat_free(data->structs[sid]);
+      if (data->structs[handle])
+       data->structs[handle] = sat_free(data->structs[handle]);
     }
   for (entry = 0; entry < data->nstructs; entry++)
     if (data->structs[entry])
index 8d94930..abf611f 100644 (file)
@@ -188,6 +188,9 @@ void repodata_add_dirstr(Repodata *data, Id handle, Id keyname, Id dir, const ch
 void repodata_add_idarray(Repodata *data, Id handle, Id keyname, Id id);
 void repodata_add_poolstr_array(Repodata *data, Id handle, Id keyname,
                                const char *str);
+/* Creates a new substructure.  Returns a handle for it (usable with the
+   other repodata_{set,add}_* functions.  */
+Id repodata_create_struct(Repodata *data, Id handle, Id keyname);
 
 /*-----
  * data management
index 81e2e3a..ed5e824 100644 (file)
@@ -1536,7 +1536,10 @@ fprintf(stderr, "dir %d used %d\n", i, cbdata.dirused ? cbdata.dirused[i] : 1);
   write_u32(fp, cbdata.nmyschemata);
   write_u32(fp, nsubfiles);    /* info blocks.  */
   if (repo->nextra)
-    write_u32(fp, repo->nextra);
+    {
+      write_u32(fp, repo->nextra);
+      write_u32(fp, SOLV_CONTENT_VERSION);
+    }
   solv_flags = 0;
   solv_flags |= SOLV_FLAG_PREFIX_POOL;
   write_u32(fp, solv_flags);