summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2019-01-19 01:54:11 +0100
committerGuillem Jover <guillem@debian.org>2019-01-21 13:21:27 +0100
commit61bbb77adb5f2c8d6a6d9bff18efa63a4cd2047f (patch)
tree297e80c623371cf9faf6b2388847afdcb8e7ae02
parentd4f6b91fda91803b62972c186a81cd07edf300e4 (diff)
downloaddpkg-61bbb77adb5f2c8d6a6d9bff18efa63a4cd2047f.tar.gz
dpkg: Switch dependtry from an int to an enum
Thiw makes the code way easier to understand as there no magic numbers anymore. It will also make it trivial to add new levels in-between.
-rw-r--r--debian/changelog1
-rw-r--r--src/configure.c2
-rw-r--r--src/main.h11
-rw-r--r--src/packages.c22
-rw-r--r--src/remove.c5
-rw-r--r--src/trigproc.c4
6 files changed, 34 insertions, 11 deletions
diff --git a/debian/changelog b/debian/changelog
index 574c02bee..dcb7025ae 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -87,6 +87,7 @@ dpkg (1.19.3) UNRELEASED; urgency=medium
- dpkg: Initialize trigcyclenode's next member once.
- dpkg: Use common pattern of assigning as an iterator.
- dpkg: Factor trigproc_new_cyclenode() out from check_trigger_cycle().
+ - dpkg: Switch dependtry from an int to an enum.
* Build system:
- get-version: Use a format string with printf.
- run-script: Use $() instead of deprecated ``.
diff --git a/src/configure.c b/src/configure.c
index 0da9723f6..99fc81634 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -608,7 +608,7 @@ deferred_configure(struct pkginfo *pkg)
vdew_nonambig));
}
- if (dependtry > 1)
+ if (dependtry >= DEPEND_TRY_CYCLES)
if (findbreakcycle(pkg))
sincenothing = 0;
diff --git a/src/main.h b/src/main.h
index d1b31b196..b0d08f9da 100644
--- a/src/main.h
+++ b/src/main.h
@@ -217,7 +217,16 @@ enum dep_check breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs);
void deferred_remove(struct pkginfo *pkg);
void deferred_configure(struct pkginfo *pkg);
-extern int sincenothing, dependtry;
+enum dependtry {
+ DEPEND_TRY_NORMAL = 1,
+ DEPEND_TRY_CYCLES = 2,
+ DEPEND_TRY_FORCE_DEPENDS_VERSION = 3,
+ DEPEND_TRY_FORCE_DEPENDS = 4,
+ DEPEND_TRY_LAST,
+};
+
+extern enum dependtry dependtry;
+extern int sincenothing;
/* from cleanup.c (most of these are declared in archives.h) */
diff --git a/src/packages.c b/src/packages.c
index f735ec3e1..7ca003433 100644
--- a/src/packages.c
+++ b/src/packages.c
@@ -49,7 +49,8 @@
static struct pkginfo *progress_bytrigproc;
static struct pkg_queue queue = PKG_QUEUE_INIT;
-int sincenothing = 0, dependtry = 1;
+enum dependtry dependtry = DEPEND_TRY_NORMAL;
+int sincenothing = 0;
void
enqueue_package(struct pkginfo *pkg)
@@ -231,7 +232,7 @@ void process_queue(void) {
* trigger processing, w/o jumping into the next dependtry. */
dependtry++;
sincenothing = 0;
- if (dependtry > 4)
+ if (dependtry >= DEPEND_TRY_LAST)
internerr("exceeded dependtry %d (sincenothing=%d; queue.length=%d)",
dependtry, sincenothing, queue.length);
} else if (sincenothing > queue.length * 2 + 2) {
@@ -243,7 +244,7 @@ void process_queue(void) {
} else {
dependtry++;
sincenothing = 0;
- if (dependtry > 4)
+ if (dependtry >= DEPEND_TRY_LAST)
internerr("exceeded dependtry %d (sincenothing=%d, queue.length=%d)",
dependtry, sincenothing, queue.length);
}
@@ -349,6 +350,15 @@ enum found_status {
FOUND_OK = 3,
};
+static enum found_status
+found_forced_on(enum dependtry dependtry_forced)
+{
+ if (dependtry >= dependtry_forced)
+ return FOUND_FORCED;
+ else
+ return FOUND_DEFER;
+}
+
/*
* Return values:
* 0: cannot be satisfied.
@@ -406,7 +416,7 @@ deppossi_ok_found(struct pkginfo *possdependee, struct pkginfo *requiredby,
pkg_name(possdependee, pnaw_always),
versiondescribe(&provider->version, vdew_nonambig));
if (fc_dependsversion)
- thisf = (dependtry >= 3) ? FOUND_FORCED : FOUND_DEFER;
+ thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS_VERSION);
debug(dbg_depcondetail, " bad version");
goto unsuitable;
}
@@ -419,7 +429,7 @@ deppossi_ok_found(struct pkginfo *possdependee, struct pkginfo *requiredby,
versiondescribe(&possdependee->installed.version,
vdew_nonambig));
if (fc_dependsversion)
- thisf = (dependtry >= 3) ? FOUND_FORCED : FOUND_DEFER;
+ thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS_VERSION);
debug(dbg_depcondetail, " bad version");
goto unsuitable;
}
@@ -688,7 +698,7 @@ dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
if (thisf > found) found= thisf;
}
if (fc_depends) {
- thisf = (dependtry >= 4) ? FOUND_FORCED : FOUND_DEFER;
+ thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS);
if (thisf > found) {
found = thisf;
debug(dbg_depcondetail, " rescued by force-depends, found %d", found);
diff --git a/src/remove.c b/src/remove.c
index fb27341f6..75f9c0f86 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -71,7 +71,10 @@ static void checkforremoval(struct pkginfo *pkgtoremove,
pkg_name(depender, pnaw_always));
continue;
}
- if (dependtry > 1) { if (findbreakcycle(pkgtoremove)) sincenothing= 0; }
+ if (dependtry >= DEPEND_TRY_CYCLES) {
+ if (findbreakcycle(pkgtoremove))
+ sincenothing = 0;
+ }
varbuf_snapshot(raemsgs, &raemsgs_state);
ok= dependencies_ok(depender,pkgtoremove,raemsgs);
if (ok == DEP_CHECK_HALT &&
diff --git a/src/trigproc.c b/src/trigproc.c
index 14b0814a6..76d901176 100644
--- a/src/trigproc.c
+++ b/src/trigproc.c
@@ -390,7 +390,7 @@ trigproc(struct pkginfo *pkg, enum trigproc_type type)
pkg_name(pkg, pnaw_always),
pkg_status_name(pkg));
- if (dependtry > 1) {
+ if (dependtry >= DEPEND_TRY_CYCLES) {
gaveup = check_trigger_cycle(pkg);
if (gaveup == pkg)
return;
@@ -436,7 +436,7 @@ trigproc(struct pkginfo *pkg, enum trigproc_type type)
varbuf_destroy(&depwhynot);
}
- if (dependtry <= 1) {
+ if (dependtry < DEPEND_TRY_CYCLES) {
gaveup = check_trigger_cycle(pkg);
if (gaveup == pkg)
return;