2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef LIBSOLV_REPO_H
14 #define LIBSOLV_REPO_H
16 #include "pooltypes.h"
20 #include "dataiterator.h"
27 typedef struct s_Repo {
28 const char *name; /* name pointer */
29 Id repoid; /* our id */
30 void *appdata; /* application private pointer */
32 Pool *pool; /* pool containing this repo */
34 int start; /* start of this repo solvables within pool->solvables */
35 int end; /* last solvable + 1 of this repo */
36 int nsolvables; /* number of solvables repo is contributing to pool */
38 int disabled; /* ignore the solvables? */
39 int priority; /* priority of this repo */
40 int subpriority; /* sub-priority of this repo, used just for sorting, not pruning */
42 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
45 int nrepodata; /* number of our stores.. */
47 Id *rpmdbid; /* solvable side data: rpm database id */
49 #ifdef LIBSOLV_INTERNAL
50 Repodata *repodata; /* our stores for non-solvable related data */
51 Offset lastoff; /* start of last array in idarraydata */
53 Hashtable lastidhash; /* hash to speed up repo_addid_dep */
54 Hashval lastidhash_mask;
55 int lastidhash_idarraysize;
58 #endif /* LIBSOLV_INTERNAL */
61 extern Repo *repo_create(Pool *pool, const char *name);
62 extern void repo_free(Repo *repo, int reuseids);
63 extern void repo_empty(Repo *repo, int reuseids);
64 extern void repo_freedata(Repo *repo);
65 extern Id repo_add_solvable(Repo *repo);
66 extern Id repo_add_solvable_block(Repo *repo, int count);
67 extern void repo_free_solvable(Repo *repo, Id p, int reuseids);
68 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
69 extern void *repo_sidedata_create(Repo *repo, size_t size);
70 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
71 extern Id repo_add_solvable_block_before(Repo *repo, int count, Repo *beforerepo);
73 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
74 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
75 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
77 static inline const char *repo_name(const Repo *repo)
82 /* those two functions are here because they need the Repo definition */
84 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
86 return repoid < pool->nrepos ? pool->repos[repoid] : 0;
89 static inline int pool_disabled_solvable(const Pool *pool, Solvable *s)
91 if (s->repo && s->repo->disabled)
95 Id id = s - pool->solvables;
96 if (!MAPTST(pool->considered, id))
102 static inline int pool_badarch_solvable(const Pool *pool, Solvable *s)
104 if (pool->id2arch && (!s->arch || pool_arch2score(pool, s->arch) == 0))
109 static inline int pool_installable(const Pool *pool, Solvable *s)
111 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
113 if (s->repo && s->repo->disabled)
115 if (pool->id2arch && (!s->arch || pool_arch2score(pool, s->arch) == 0))
117 if (pool->considered)
119 Id id = s - pool->solvables;
120 if (!MAPTST(pool->considered, id))
126 #ifdef LIBSOLV_INTERNAL
127 static inline int pool_installable_whatprovides(const Pool *pool, Solvable *s)
129 /* we always need the installed solvable in the whatprovides data,
130 otherwise obsoletes/conflicts on them won't work */
131 if (s->repo != pool->installed)
133 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC || pool_badarch_solvable(pool, s))
135 if (pool->considered && !pool->whatprovideswithdisabled)
137 Id id = s - pool->solvables;
138 if (!MAPTST(pool->considered, id))
146 /* not in solvable.h because we need the repo definition */
147 static inline Solvable *solvable_free(Solvable *s, int reuseids)
150 repo_free_solvable(s->repo, s - s->repo->pool->solvables, reuseids);
154 /* search callback values */
155 #define SEARCH_NEXT_KEY 1
156 #define SEARCH_NEXT_SOLVABLE 2
157 #define SEARCH_STOP 3
158 #define SEARCH_ENTERSUB -1
160 /* standard flags used in the repo_add functions */
161 #define REPO_REUSE_REPODATA (1 << 0)
162 #define REPO_NO_INTERNALIZE (1 << 1)
163 #define REPO_LOCALPOOL (1 << 2)
164 #define REPO_USE_LOADING (1 << 3)
165 #define REPO_EXTEND_SOLVABLES (1 << 4)
166 #define REPO_USE_ROOTDIR (1 << 5)
167 #define REPO_NO_LOCATION (1 << 6)
169 Repodata *repo_add_repodata(Repo *repo, int flags);
170 Repodata *repo_id2repodata(Repo *repo, Id id);
171 Repodata *repo_last_repodata(Repo *repo);
173 void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
175 /* returns the last repodata that contains the key */
176 Repodata *repo_lookup_repodata(Repo *repo, Id entry, Id keyname);
177 Repodata *repo_lookup_repodata_opt(Repo *repo, Id entry, Id keyname);
178 Repodata *repo_lookup_filelist_repodata(Repo *repo, Id entry, Datamatcher *matcher);
180 /* returns the string value of the attribute, or NULL if not found */
181 Id repo_lookup_type(Repo *repo, Id entry, Id keyname);
182 const char *repo_lookup_str(Repo *repo, Id entry, Id keyname);
183 /* returns the integer value of the attribute, or notfound if not found */
184 unsigned long long repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound);
185 Id repo_lookup_id(Repo *repo, Id entry, Id keyname);
186 int repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q);
187 int repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker);
188 int repo_lookup_void(Repo *repo, Id entry, Id keyname);
189 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
190 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
191 const void *repo_lookup_binary(Repo *repo, Id entry, Id keyname, int *lenp);
192 Id solv_depmarker(Id keyname, Id marker);
194 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
195 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num);
196 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
197 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
198 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
199 void repo_add_idarray(Repo *repo, Id p, Id keyname, Id id);
200 void repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker);
201 void repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q);
202 void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker);
203 void repo_unset(Repo *repo, Id p, Id keyname);
205 void repo_internalize(Repo *repo);
206 void repo_disable_paging(Repo *repo);
207 Id *repo_create_keyskip(Repo *repo, Id entry, Id **oldkeyskip);
210 /* iterator macros */
211 #define FOR_REPO_SOLVABLES(r, p, s) \
212 for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p) \
213 if (s->repo != (r)) \
217 #ifdef LIBSOLV_INTERNAL
218 #define FOR_REPODATAS(repo, rdid, data) \
219 for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
221 #define FOR_REPODATAS(repo, rdid, data) \
222 for (rdid = 1; rdid < repo->nrepodata && (data = repo_id2repodata(repo, rdid)); rdid++)
225 /* weird suse stuff, do not use */
226 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
227 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
228 extern void repo_rewrite_suse_deps(Solvable *s, Offset freshens);
234 #endif /* LIBSOLV_REPO_H */