From 88f1780f2b60e3f879377d795718ec9037662b7e Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:20:25 +0200 Subject: [PATCH 01/13] add comments --- pkg/upgrade/service.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index df0469890..5738c163b 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -302,24 +302,29 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst // upgrade menu asks you which packages to NOT upgrade so in this case // exclude and include are kind of swapped exclude, include, otherExclude, otherInclude := intrange.ParseNumberMenu(numbers) + + // true if user doesn't want to include specific packages isInclude := len(include) == 0 && otherInclude.Cardinality() == 0 excluded := make([]string, 0) for i := range allUp.Up { up := &allUp.Up[i] + // exclude repositories mentionned by the user if isInclude && otherExclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue } + // exclude packages mentionned by the user if isInclude && exclude.Get(len(allUp.Up)-i) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue } + // If the user explicitely wants to include a package/repository, exclude everything else if !isInclude && !(include.Get(len(allUp.Up)-i) || otherInclude.Contains(up.Repository)) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) From 78884701e6888b29cd7effb84653fa01d7e7a374 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:20:31 +0200 Subject: [PATCH 02/13] simplify last condition --- pkg/upgrade/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 5738c163b..9fc86a560 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -325,7 +325,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst } // If the user explicitely wants to include a package/repository, exclude everything else - if !isInclude && !(include.Get(len(allUp.Up)-i) || otherInclude.Contains(up.Repository)) { + if !isInclude && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue From 48bc9198214a42b114b45ebe53e9810d2d15a598 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:20:59 +0200 Subject: [PATCH 03/13] isInclude -> noIncludes --- pkg/upgrade/service.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 9fc86a560..9b33d5442 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -304,28 +304,28 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst exclude, include, otherExclude, otherInclude := intrange.ParseNumberMenu(numbers) // true if user doesn't want to include specific packages - isInclude := len(include) == 0 && otherInclude.Cardinality() == 0 + noIncludes := len(include) == 0 && otherInclude.Cardinality() == 0 excluded := make([]string, 0) for i := range allUp.Up { up := &allUp.Up[i] // exclude repositories mentionned by the user - if isInclude && otherExclude.Contains(up.Repository) { + if noIncludes && otherExclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue } // exclude packages mentionned by the user - if isInclude && exclude.Get(len(allUp.Up)-i) { + if noIncludes && exclude.Get(len(allUp.Up)-i) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue } // If the user explicitely wants to include a package/repository, exclude everything else - if !isInclude && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { + if !noIncludes && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) continue From 02e5f10287c080341dfc0eb698dd40e44c04af28 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:22:29 +0200 Subject: [PATCH 04/13] simplify if noIncludes --- pkg/upgrade/service.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 9b33d5442..f1903cb8c 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -310,26 +310,29 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst for i := range allUp.Up { up := &allUp.Up[i] - // exclude repositories mentionned by the user - if noIncludes && otherExclude.Contains(up.Repository) { - u.log.Debugln("pruning", up.Name) - excluded = append(excluded, graph.Prune(up.Name)...) - continue - } - - // exclude packages mentionned by the user - if noIncludes && exclude.Get(len(allUp.Up)-i) { - u.log.Debugln("pruning", up.Name) - excluded = append(excluded, graph.Prune(up.Name)...) - continue + // check if user wants to exclude specific things (true) or include specific things + if noIncludes { + // exclude repositories mentionned by the user + if otherExclude.Contains(up.Repository) { + u.log.Debugln("pruning", up.Name) + excluded = append(excluded, graph.Prune(up.Name)...) + continue + } + // exclude packages mentionned by the user + if exclude.Get(len(allUp.Up) - i) { + u.log.Debugln("pruning", up.Name) + excluded = append(excluded, graph.Prune(up.Name)...) + continue + } + } else { + // If the user explicitely wants to include a package/repository, exclude everything else + if !noIncludes && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { + u.log.Debugln("pruning", up.Name) + excluded = append(excluded, graph.Prune(up.Name)...) + continue + } } - // If the user explicitely wants to include a package/repository, exclude everything else - if !noIncludes && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { - u.log.Debugln("pruning", up.Name) - excluded = append(excluded, graph.Prune(up.Name)...) - continue - } } return excluded, nil From 30cd762fd7a35cd36e5fca6401e7836008dd1395 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:22:44 +0200 Subject: [PATCH 05/13] remove useless `continue` instructions --- pkg/upgrade/service.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index f1903cb8c..669fcf58c 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -316,20 +316,17 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst if otherExclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) - continue } // exclude packages mentionned by the user if exclude.Get(len(allUp.Up) - i) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) - continue } } else { // If the user explicitely wants to include a package/repository, exclude everything else if !noIncludes && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) - continue } } From 24141bae1eeee2e9a7cd751203ae1c2d4605c862 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:23:06 +0200 Subject: [PATCH 06/13] fix comment --- pkg/upgrade/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 669fcf58c..43ea1b583 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -303,7 +303,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst // exclude and include are kind of swapped exclude, include, otherExclude, otherInclude := intrange.ParseNumberMenu(numbers) - // true if user doesn't want to include specific packages + // true if user doesn't want to include specific repositories/packages noIncludes := len(include) == 0 && otherInclude.Cardinality() == 0 excluded := make([]string, 0) From 29aded7b0c7bc7a488d3007815d15e93cb9030ec Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:28:44 +0200 Subject: [PATCH 07/13] introduce upgradeId --- pkg/upgrade/service.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 43ea1b583..fa48dc323 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -309,6 +309,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst excluded := make([]string, 0) for i := range allUp.Up { up := &allUp.Up[i] + upgradeId := len(allUp.Up) - i // check if user wants to exclude specific things (true) or include specific things if noIncludes { @@ -318,13 +319,13 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst excluded = append(excluded, graph.Prune(up.Name)...) } // exclude packages mentionned by the user - if exclude.Get(len(allUp.Up) - i) { + if exclude.Get(upgradeId) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } } else { // If the user explicitely wants to include a package/repository, exclude everything else - if !noIncludes && !include.Get(len(allUp.Up)-i) && !otherInclude.Contains(up.Repository) { + if !noIncludes && !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } From af8547ac988f1315eb08d9942f0b81aa3a04a563 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:31:03 +0200 Subject: [PATCH 08/13] mentionned -> mentioned --- pkg/upgrade/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index fa48dc323..aa4960f41 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -313,12 +313,12 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst // check if user wants to exclude specific things (true) or include specific things if noIncludes { - // exclude repositories mentionned by the user + // exclude repositories mentioned by the user if otherExclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } - // exclude packages mentionned by the user + // exclude packages mentioned by the user if exclude.Get(upgradeId) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) From 9ffcf6921c47b6f9135c3c5cf9f250aff59d9d4b Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 6 Jun 2024 16:33:54 +0200 Subject: [PATCH 09/13] remove useless condition --- pkg/upgrade/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index aa4960f41..8f3afcb7d 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -325,7 +325,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst } } else { // If the user explicitely wants to include a package/repository, exclude everything else - if !noIncludes && !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { + if !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } From c219e6dfa1feae785346cb7078293dce0817439c Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 20 Jun 2024 14:33:51 +0200 Subject: [PATCH 10/13] replace else/if by else if --- pkg/upgrade/service.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 8f3afcb7d..3dd735af5 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -323,14 +323,10 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } - } else { - // If the user explicitely wants to include a package/repository, exclude everything else - if !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { - u.log.Debugln("pruning", up.Name) - excluded = append(excluded, graph.Prune(up.Name)...) - } + } else if !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { // If the user explicitely wants to include a package/repository, exclude everything else + u.log.Debugln("pruning", up.Name) + excluded = append(excluded, graph.Prune(up.Name)...) } - } return excluded, nil From 8f94e3845cba6655bb911f4d96354afe4250e664 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 20 Jun 2024 14:34:08 +0200 Subject: [PATCH 11/13] upgradeId -> upgradeID --- pkg/upgrade/service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 3dd735af5..24737d612 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -309,7 +309,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst excluded := make([]string, 0) for i := range allUp.Up { up := &allUp.Up[i] - upgradeId := len(allUp.Up) - i + upgradeID := len(allUp.Up) - i // check if user wants to exclude specific things (true) or include specific things if noIncludes { @@ -319,11 +319,11 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst excluded = append(excluded, graph.Prune(up.Name)...) } // exclude packages mentioned by the user - if exclude.Get(upgradeId) { + if exclude.Get(upgradeID) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } - } else if !include.Get(upgradeId) && !otherInclude.Contains(up.Repository) { // If the user explicitely wants to include a package/repository, exclude everything else + } else if !include.Get(upgradeID) && !otherInclude.Contains(up.Repository) { // If the user explicitely wants to include a package/repository, exclude everything else u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } From a386ab39ff8b23755fb4406af6fac4b0977dd261 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 20 Jun 2024 14:34:45 +0200 Subject: [PATCH 12/13] fix line length --- pkg/upgrade/service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 24737d612..9252ada5e 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -323,7 +323,9 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } - } else if !include.Get(upgradeID) && !otherInclude.Contains(up.Repository) { // If the user explicitely wants to include a package/repository, exclude everything else + + // If the user explicitely wants to include a package/repository, exclude everything else + } else if !include.Get(upgradeID) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...) } From a77d98824d11723f56d17df4be51109454067470 Mon Sep 17 00:00:00 2001 From: iTrooz Date: Thu, 20 Jun 2024 14:34:58 +0200 Subject: [PATCH 13/13] fix typo --- pkg/upgrade/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 9252ada5e..881427f08 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -324,7 +324,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst excluded = append(excluded, graph.Prune(up.Name)...) } - // If the user explicitely wants to include a package/repository, exclude everything else + // If the user explicitly wants to include a package/repository, exclude everything else } else if !include.Get(upgradeID) && !otherInclude.Contains(up.Repository) { u.log.Debugln("pruning", up.Name) excluded = append(excluded, graph.Prune(up.Name)...)