Commit 6db5bee2 authored by Bernhard Link's avatar Bernhard Link

[refactor] replace term_decidechunktarget with term_decidepackage

parent af6486e9
......@@ -616,7 +616,7 @@ static retvalue by_formula(struct package_list *list, struct target *desttarget,
return r;
result = RET_NOTHING;
while (package_next(&iterator)) {
r = term_decidechunktarget(condition, iterator.current.control,
r = term_decidepackage(condition, &iterator.current,
desttarget);
if (r == RET_NOTHING)
continue;
......@@ -745,8 +745,7 @@ static retvalue choose_by_source(struct package *package, void *privdata) {
static retvalue choose_by_condition(struct package *package, void *privdata) {
term *condition = privdata;
return term_decidechunktarget(condition,
package->control, package->target);
return term_decidepackage(condition, package, package->target);
}
static retvalue choose_by_glob(struct package *package, void *privdata) {
......
......@@ -959,8 +959,7 @@ ACTION_D(n, n, y, removesrcs) {
static retvalue package_matches_condition(struct package *package, void *data) {
term *condition = data;
return term_decidechunktarget(condition,
package->control, package->target);
return term_decidepackage(condition, package, package->target);
}
ACTION_D(y, n, y, removefilter) {
......@@ -1412,7 +1411,7 @@ static retvalue listfilterprint(struct package *package, void *data) {
if (listmax == 0)
return RET_NOTHING;
r = term_decidechunktarget(condition, package->control, package->target);
r = term_decidepackage(condition, package, package->target);
if (RET_IS_OK(r)) {
if (listskip <= 0) {
if (listmax > 0)
......
......@@ -785,8 +785,7 @@ static upgrade_decision ud_decide_by_rule(void *privdata, struct target *target,
/* formula tested last as it is the most expensive */
if (rule->includecondition != NULL) {
r = term_decidechunktarget(rule->includecondition,
new->control, target);
r = term_decidepackage(rule->includecondition, new, target);
if (RET_WAS_ERROR(r))
return UD_ERROR;
if (r == RET_NOTHING) {
......
......@@ -57,7 +57,10 @@ static inline bool check_field(enum term_comparison c, const char *value, const
}
}
retvalue term_decidechunk(const term *condition, const char *controlchunk, void *privdata) {
/* this has a target argument instead of using package->target
* as the package might come from one distribution/architecture/...
* and the decision being about adding it somewhere else */
retvalue term_decidepackage(const term *condition, struct package *package, struct target *target) {
const struct term_atom *atom = condition;
while (atom != NULL) {
......@@ -68,9 +71,9 @@ retvalue term_decidechunk(const term *condition, const char *controlchunk, void
if (atom->isspecial) {
correct = atom->special.type->compare(c,
&atom->special.comparewith,
controlchunk, privdata);
package, target);
} else {
r = chunk_getvalue(controlchunk,
r = chunk_getvalue(package->control,
atom->generic.key, &value);
if (RET_WAS_ERROR(r))
return r;
......@@ -116,25 +119,14 @@ static retvalue parsestring(enum term_comparison c, const char *value, size_t le
// TODO: check for well-formed versions
#define parseversion parsestring
static bool comparesource(enum term_comparison c, const struct compare_with *v, const void *d1, void *d2) {
const char *control = d1;
struct target *target = d2;
char *package, *source, *version;
static bool comparesource(enum term_comparison c, const struct compare_with *v, void *d1, UNUSED(void *d2)) {
struct package *package = d1;
retvalue r;
bool matches;
// TODO: make more efficient
r = chunk_getvalue(control, "Package", &package);
r = package_getsource(package);
if (!RET_IS_OK(r))
return false;
r = target->getsourceandversion(control, package, &source, &version);
free(package);
if (!RET_IS_OK(r))
return false;
free(version);
matches = check_field(c, source, v->pointer);
free(source);
return matches;
return check_field(c, package->source, v->pointer);
}
static inline bool compare_dpkgversions(enum term_comparison c, const char *version, const char *param) {
......@@ -162,39 +154,23 @@ static inline bool compare_dpkgversions(enum term_comparison c, const char *vers
return check_field(c, version, param);
}
static bool compareversion(enum term_comparison c, const struct compare_with *v, const void *d1, void *d2) {
const char *control = d1;
struct target *target = d2;
char *version;
static bool compareversion(enum term_comparison c, const struct compare_with *v, void *d1, UNUSED(void *d2)) {
struct package *package = d1;
retvalue r;
bool matches;
r = target->getversion(control, &version);
r = package_getversion(package);
if (!RET_IS_OK(r))
return false;
matches = compare_dpkgversions(c, version, v->pointer);
free(version);
return matches;
return compare_dpkgversions(c, package->version, v->pointer);
}
static bool comparesourceversion(enum term_comparison c, const struct compare_with *v, const void *d1, void *d2) {
const char *control = d1;
struct target *target = d2;
char *package, *source, *version;
static bool comparesourceversion(enum term_comparison c, const struct compare_with *v, void *d1, UNUSED(void *d2)) {
struct package *package = d1;
retvalue r;
bool matches;
// TODO: make more efficient
r = chunk_getvalue(control, "Package", &package);
if (!RET_IS_OK(r))
return false;
r = target->getsourceandversion(control, package, &source, &version);
free(package);
r = package_getsource(package);
if (!RET_IS_OK(r))
return false;
free(source);
matches = compare_dpkgversions(c, version, v->pointer);
free(version);
return matches;
return compare_dpkgversions(c, package->sourceversion, v->pointer);
}
static void freestring(UNUSED(enum term_comparison c), struct compare_with *d) {
......@@ -270,7 +246,7 @@ static retvalue parsecomponent(enum term_comparison c, const char *value, size_t
return RET_ERROR;
}
static bool comparetype(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), void *d2) {
static bool comparetype(enum term_comparison c, const struct compare_with *v, UNUSED( void *d1), void *d2) {
const struct target *target = d2;
if (c == tc_equal)
......@@ -283,7 +259,7 @@ static bool comparetype(enum term_comparison c, const struct compare_with *v, UN
v->pointer);
}
static bool comparearchitecture(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), void *d2) {
static bool comparearchitecture(enum term_comparison c, const struct compare_with *v, UNUSED(void *d1), void *d2) {
const struct target *target = d2;
if (c == tc_equal)
......@@ -295,7 +271,7 @@ static bool comparearchitecture(enum term_comparison c, const struct compare_wit
atoms_architectures[target->architecture],
v->pointer);
}
static bool comparecomponent(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), void *d2) {
static bool comparecomponent(enum term_comparison c, const struct compare_with *v, UNUSED(void *d1), void *d2) {
const struct target *target = d2;
if (c == tc_equal)
......@@ -324,7 +300,3 @@ retvalue term_compilefortargetdecision(term **term_p, const char *formula) {
T_GLOBMATCH|T_OR|T_BRACKETS|T_NEGATION|T_VERSION|T_NOTEQUAL,
targetdecisionspecial);
}
retvalue term_decidechunktarget(const term *condition, const char *controlchunk, struct target *target) {
return term_decidechunk(condition, controlchunk, target);
}
......@@ -7,12 +7,12 @@
#ifndef REPREPRO_TARGET_H
#include "target.h"
#endif
/* decide based on a chunk, (warning: string comparisons even for version!)*/
retvalue term_decidechunk(const term *, const char *, /*@null@*/void *);
#ifndef REPREPRO_PACKAGE_H
#include "package.h"
#endif
retvalue term_compilefortargetdecision(/*@out@*/term **, const char *);
retvalue term_decidechunktarget(const term *, const char *, struct target *);
retvalue term_decidepackage(const term *, struct package *, struct target *);
......
......@@ -40,7 +40,7 @@ typedef struct term_atom {
struct term_special {
const char *name;
retvalue (*parse)(enum term_comparison, const char *, size_t len, struct compare_with *);
bool (*compare)(enum term_comparison, const struct compare_with *, const void*, void*);
bool (*compare)(enum term_comparison, const struct compare_with *, void*, void*);
void (*done)(enum term_comparison, struct compare_with *);
};
......
......@@ -1755,8 +1755,7 @@ static upgrade_decision ud_decide_by_pattern(void *privdata, struct target *targ
while (p != NULL && !p->includecondition_set)
p = p->pattern_from;
if (p != NULL) {
r = term_decidechunktarget(p->includecondition,
new->control, target);
r = term_decidepackage(p->includecondition, new, target);
if (RET_WAS_ERROR(r))
return UD_ERROR;
if (r == RET_NOTHING) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment