diff options
author | Michael Schroeder <mls@suse.de> | 2013-06-17 13:43:49 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2013-06-17 13:43:49 +0200 |
commit | e9666fb9b317ba613da1552af7d6fedb3041b370 (patch) | |
tree | db412eac084f2607c0d0468acfe6d97a28e5df29 | |
parent | b953579fa7caa20826b2e238f04ce7d2368000df (diff) | |
download | libsolv-e9666fb9b317ba613da1552af7d6fedb3041b370.tar.gz libsolv-e9666fb9b317ba613da1552af7d6fedb3041b370.tar.bz2 libsolv-e9666fb9b317ba613da1552af7d6fedb3041b370.zip |
refactor a bit
-rw-r--r-- | bindings/solv.i | 6 | ||||
-rw-r--r-- | src/repodata.c | 66 | ||||
-rw-r--r-- | src/repodata.h | 3 |
3 files changed, 45 insertions, 30 deletions
diff --git a/bindings/solv.i b/bindings/solv.i index ed609d3..1e2e7fe 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -1567,7 +1567,7 @@ rb_eval_string( return; data = repo_id2repodata($self, $self->nrepodata - 1); if (data->state != REPODATA_STUB) - repodata_create_stubs(data); + (void)repodata_create_stubs(data); } #ifdef SWIGRUBY %rename("iscontiguous?") iscontiguous; @@ -2969,7 +2969,9 @@ rb_eval_string( repodata_internalize(repo_id2repodata($self->repo, $self->id)); } void create_stubs() { - repodata_create_stubs(repo_id2repodata($self->repo, $self->id)); + Repodata *data = repo_id2repodata($self->repo, $self->id); + data = repodata_create_stubs(data); + $self->id = data->repodataid; } bool write(FILE *fp) { return repodata_write(repo_id2repodata($self->repo, $self->id), fp) == 0; diff --git a/src/repodata.c b/src/repodata.c index 4d0a46d..54bd3dc 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -3238,7 +3238,35 @@ repodata_load_stub(Repodata *data) data->state = r ? REPODATA_AVAILABLE : REPODATA_ERROR; } -void +static inline void +repodata_add_stubkey(Repodata *data, Id keyname, Id keytype) +{ + Repokey xkey; + + xkey.name = keyname; + xkey.type = keytype; + xkey.storage = KEY_STORAGE_INCORE; + xkey.size = 0; + repodata_key2id(data, &xkey, 1); +} + +static Repodata * +repodata_add_stub(Repodata **datap) +{ + Repodata *data = *datap; + Repo *repo = data->repo; + Id repodataid = data - repo->repodata; + Repodata *sdata = repo_add_repodata(repo, 0); + data = repo->repodata + repodataid; + if (data->end > data->start) + repodata_extend_block(sdata, data->start, data->end - data->start); + sdata->state = REPODATA_STUB; + sdata->loadcallback = repodata_load_stub; + *datap = data; + return sdata; +} + +Repodata * repodata_create_stubs(Repodata *data) { Repo *repo = data->repo; @@ -3248,38 +3276,26 @@ repodata_create_stubs(Repodata *data) Dataiterator di; Id xkeyname = 0; int i, cnt = 0; - int repodataid; - int datastart, dataend; - repodataid = data - repo->repodata; - datastart = data->start; - dataend = data->end; dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_EXTERNAL, 0, 0); while (dataiterator_step(&di)) - { - if (di.data - repo->repodata != repodataid) - continue; + if (di.data == data) cnt++; - } dataiterator_free(&di); if (!cnt) - return; + return data; stubdataids = solv_calloc(cnt, sizeof(*stubdataids)); for (i = 0; i < cnt; i++) { - sdata = repo_add_repodata(repo, 0); - if (dataend > datastart) - repodata_extend_block(sdata, datastart, dataend - datastart); + sdata = repodata_add_stub(&data); stubdataids[i] = sdata - repo->repodata; - sdata->state = REPODATA_STUB; - sdata->loadcallback = repodata_load_stub; } i = 0; dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_EXTERNAL, 0, 0); sdata = 0; while (dataiterator_step(&di)) { - if (di.data - repo->repodata != repodataid) + if (di.data != data) continue; if (di.key->name == REPOSITORY_EXTERNAL && !di.nparents) { @@ -3314,21 +3330,18 @@ repodata_create_stubs(Repodata *data) repodata_add_idarray(sdata, SOLVID_META, di.key->name, di.kv.id); if (di.key->name == REPOSITORY_KEYS) { - Repokey xkey; - if (!xkeyname) { if (!di.kv.eof) xkeyname = di.kv.id; - continue; } - xkey.name = xkeyname; - xkey.type = di.kv.id; - xkey.storage = KEY_STORAGE_INCORE; - xkey.size = 0; - repodata_key2id(sdata, &xkey, 1); - xkeyname = 0; + else + { + repodata_add_stubkey(sdata, xkeyname, di.kv.id); + xkeyname = 0; + } } + break; default: break; } @@ -3337,6 +3350,7 @@ repodata_create_stubs(Repodata *data) for (i = 0; i < cnt; i++) repodata_internalize(repo->repodata + stubdataids[i]); solv_free(stubdataids); + return data; } unsigned int diff --git a/src/repodata.h b/src/repodata.h index 029a7f9..3b3eb19 100644 --- a/src/repodata.h +++ b/src/repodata.h @@ -278,8 +278,7 @@ void repodata_merge_attrs(Repodata *data, Id dest, Id src); void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite); void repodata_swap_attrs(Repodata *data, Id dest, Id src); -void repodata_create_stubs(Repodata *data); -void repodata_join(Repodata *data, Id joinkey); +Repodata *repodata_create_stubs(Repodata *data); /* * load all paged data, used to speed up copying in repo_rpmdb |