39e3c49df00c87c03b72b478397e3ff9d9308fb7
[platform/upstream/libsolv.git] / src / repo.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * repo.h
10  * 
11  */
12
13 #ifndef SATSOLVER_REPO_H
14 #define SATSOLVER_REPO_H
15
16 #include "pooltypes.h"
17 #include "pool.h"
18 #include "attr_store.h"
19
20 typedef struct _Repodata {
21   /* Keys provided by this attribute store, sorted by name value.
22      The same keys may be provided by multiple attribute stores, but
23      then only for different solvables.  I.e. the relation
24        (solvable,name) -> store
25      has to be injective.  */
26   struct {
27     Id name;
28     unsigned type;
29   } *keys;
30   /* Length of names.  */
31   unsigned nkeys;
32   /* The attribute store itself.  */
33   Attrstore *s;
34   /* A filename where to find this attribute store, or where to store
35      it.  May be NULL, in which case we can't load it on demand or store
36      into it.  */
37   const char *name;
38   /* The SHA1 checksum of the file.  */
39   unsigned char checksum[20];
40 } Repodata;
41
42 typedef struct _Repo {
43   const char *name;
44   struct _Pool *pool;           /* pool containing repo data */
45   int start;                    /* start of this repo solvables within pool->solvables */
46   int end;                      /* last solvable + 1 of this repo */
47   int nsolvables;               /* number of solvables repo is contributing to pool */
48
49   int priority;                 /* priority of this repo */
50
51   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
52   int idarraysize;
53   Offset lastoff;
54
55   Id *rpmdbid;
56
57   /* The attribute stores we know about.  */
58   Repodata *repodata;
59   /* Number of attribute stores..  */
60   unsigned nrepodata;
61 } Repo;
62
63 extern Repo *repo_create(Pool *pool, const char *name);
64 extern void repo_free(Repo *repo, int reuseids);
65 extern void repo_freeallrepos(Pool *pool, int reuseids);
66
67 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
68 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, int isreq);
69 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
70 extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements);
71
72 extern void repo_add_attrstore (Repo *repo, Attrstore *s);
73
74 static inline const char *repo_name(const Repo *repo)
75 {
76   return repo->name;
77 }
78
79 static inline Id repo_add_solvable(Repo *repo)
80 {
81   extern Id pool_add_solvable(Pool *pool);
82   Id p = pool_add_solvable(repo->pool);
83   if (!repo->start || repo->start == repo->end)
84     {
85       repo->start = p;
86       repo->end = p + 1;
87     }
88   else
89     {
90       if (p < repo->start)
91         repo->start = p;
92       if (p + 1 > repo->end)
93         repo->end = p + 1;
94     }
95   repo->nsolvables++;
96   repo->pool->solvables[p].repo = repo;
97   return p;
98 }
99
100 static inline Id repo_add_solvable_block(Repo *repo, int count)
101 {
102   extern Id pool_add_solvable_block(Pool *pool, int count);
103   Id p;
104   Solvable *s;
105   if (!count)
106     return 0;
107   p = pool_add_solvable_block(repo->pool, count);
108   if (!repo->start || repo->start == repo->end)
109     {
110       repo->start = p;
111       repo->end = p + count;
112     }
113   else
114     {
115       if (p < repo->start)
116         repo->start = p;
117       if (p + count > repo->end)
118         repo->end = p + count;
119     }
120   repo->nsolvables += count;
121   for (s = repo->pool->solvables + p; count--; s++)
122     s->repo = repo;
123   return p;
124 }
125
126 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
127 {
128   extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
129   Solvable *s;
130   int i;
131   if (start + count == repo->end)
132     repo->end -= count;
133   repo->nsolvables -= count;
134   for (s = repo->pool->solvables + start, i = count; i--; s++)
135     s->repo = 0;
136   pool_free_solvable_block(repo->pool, start, count, reuseids);
137 }
138
139 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
140   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s++)    \
141     if (s->repo == (r))
142
143 #endif /* SATSOLVER_REPO_H */