]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add repodata_lookup_count function
authorMichael Schroeder <mls@suse.de>
Thu, 16 Apr 2020 21:26:46 +0000 (23:26 +0200)
committerMichael Schroeder <mls@suse.de>
Thu, 16 Apr 2020 21:32:40 +0000 (23:32 +0200)
This is currently internal only. It will be used to compare the
numbers of track_features entries in conda.

src/repodata.c
src/repodata.h

index 3cae0fe4c36e47c5909a08e4f28364d1e0016601..0580cff6f36dc1e0a45d64524763f565c235f9a6 100644 (file)
@@ -841,6 +841,57 @@ repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp)
   return dp;
 }
 
+unsigned int
+repodata_lookup_count(Repodata *data, Id solvid, Id keyname)
+{
+  unsigned char *dp;
+  Repokey *key;
+  unsigned int cnt = 0;
+
+  dp = find_key_data(data, solvid, keyname, &key);
+  if (!dp)
+    return 0;
+  switch (key->type)
+    {
+    case REPOKEY_TYPE_IDARRAY:
+    case REPOKEY_TYPE_REL_IDARRAY:
+      for (cnt = 1; (*dp & 0xc0) != 0; dp++)
+       if ((*dp & 0xc0) == 0x40)
+         cnt++;
+      return cnt;
+    case REPOKEY_TYPE_FIXARRAY:
+    case REPOKEY_TYPE_FLEXARRAY:
+      data_read_id(dp, (int *)&cnt);
+      return cnt;
+    case REPOKEY_TYPE_DIRSTRARRAY:
+      for (;;)
+       {
+         cnt++;
+         while (*dp & 0x80)
+           dp++;
+         if (!(*dp++ & 0x40))
+           return cnt;
+         dp += strlen((const char *)dp) + 1;
+       }
+    case REPOKEY_TYPE_DIRNUMNUMARRAY:
+      for (;;)
+       {
+         cnt++;
+         while (*dp++ & 0x80)
+           ;
+         while (*dp++ & 0x80)
+           ;
+         while (*dp & 0x80)
+           dp++;
+         if (!(*dp++ & 0x40))
+           return cnt;
+       }
+      default:
+       break;
+    }
+  return 1;
+}
+
 /* highly specialized function to speed up fileprovides adding.
  * - repodata must be available
  * - solvid must be >= data->start and < data->end
index f204e34f9bfbddbfb2fa56dec4de73510fcc7156..7dd5259d071dc803b5df5e95cfeb0f8c1d1a5c11 100644 (file)
@@ -229,6 +229,7 @@ int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
 const void *repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp);
+unsigned int repodata_lookup_count(Repodata *data, Id solvid, Id keyname);     /* internal */
 
 /* internal, used in fileprovides code */
 const unsigned char *repodata_lookup_packed_dirstrarray(Repodata *data, Id solvid, Id keyname);