// reqs.Previous, but the methods of reqs must otherwise handle such versions
// correctly.
func Downgrade(target module.Version, reqs Reqs, downgrade ...module.Version) ([]module.Version, error) {
- list, err := reqs.Required(target)
+ // Per https://research.swtch.com/vgo-mvs#algorithm_4:
+ // “To avoid an unnecessary downgrade to E 1.1, we must also add a new
+ // requirement on E 1.2. We can apply Algorithm R to find the minimal set of
+ // new requirements to write to go.mod.”
+ //
+ // In order to generate those new requirements, we need to identify versions
+ // for every module in the build list — not just reqs.Required(target).
+ list, err := BuildList(target, reqs)
if err != nil {
return nil, err
}
+ list = list[1:] // remove target
+
max := make(map[string]string)
for _, r := range list {
max[r.Path] = r.Version
}
added[m] = true
if v, ok := max[m.Path]; ok && reqs.Max(m.Version, v) != v {
+ // m would upgrade an existing dependency — it is not a strict downgrade,
+ // and because it was already present as a dependency, it could affect the
+ // behavior of other relevant packages.
exclude(m)
return
}
// is transient (we couldn't download go.mod), return the error from
// Downgrade. Currently, we can't tell what kind of error it is.
exclude(m)
+ return
}
for _, r := range list {
add(r)
}
}
- var out []module.Version
- out = append(out, target)
+ downgraded := make([]module.Version, 0, len(list)+1)
+ downgraded = append(downgraded, target)
List:
for _, r := range list {
add(r)
add(p)
r = p
}
- out = append(out, r)
+ downgraded = append(downgraded, r)
}
- return out, nil
+ return BuildList(target, &override{
+ target: target,
+ list: downgraded,
+ Reqs: reqs,
+ })
}
type override struct {
upgrade* A: A B1 C4 D5 E2 F1 G1
upgrade A C4: A B1 C4 D4 E2 F1 G1
build A2: A2 B1 C4 D4 E2 F1 G1
-# BUG: selected versions E2 and F1 are not preserved.
-downgrade A2 D2: A2 C4 D2
+downgrade A2 D2: A2 C4 D2 E2 F1 G1
name: trim
A: B1 C2
B1: C1
B2: C2
build A: A B2 C2
-# BUG: build list from downgrade omits selected version C1.
-downgrade A C1: A B1
+downgrade A C1: A B1 C1
name: down2
A: B2 E2
E1:
F1:
build A: A B2 C2 D2 E2 F2
-# BUG: selected versions C1 and D1 are not preserved, and
-# requested version F1 is not selected.
-downgrade A F1: A B1 E1
+downgrade A F1: A B1 C1 D1 E1 F1
# https://research.swtch.com/vgo-mvs#algorithm_4:
# “[D]owngrades are constrained to only downgrade packages, not also upgrade
D1:
D2:
build A: A B2 C1 D2
-# BUG: requested version D1 is not selected.
-downgrade A D1: A
+downgrade A D1: A D1
# https://research.swtch.com/vgo-mvs#algorithm_4:
# “Unlike upgrades, downgrades must work by removing requirements, not adding
C1:
D1:
D2:
-build A: A B2 D2
-# BUG: requested version D1 is not selected,
-# and selected version C1 is omitted from the returned build list.
-downgrade A D1: A B1
+build A: A B2 D2
+downgrade A D1: A B1 C1 D1
name: downcycle
A: A B2
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- update-a-expected --
-go get: example.com/badchain/a@v1.0.0 updating to
- example.com/badchain/a@v1.1.0 requires
+go get: example.com/badchain/a@v1.1.0 requires
example.com/badchain/b@v1.1.0 requires
example.com/badchain/c@v1.1.0: parsing go.mod:
module declares its path as: badchain.example.com/c