From dadc8c0d988df3c60caa98512e88f87f4b469993 Mon Sep 17 00:00:00 2001 From: Joey Holtzman <89617856+jdholtz@users.noreply.github.com> Date: Thu, 6 Jul 2023 01:54:21 -0500 Subject: [PATCH] Re-add functionality for Installed and NotInstalled options in the menus (#2233) * fix(menus): Handle Installed and NotInstalled options correctly in the menus This functionality was temporarily removed. This commit adds that functionality back. * fix(tests): Mock InstalledRemotePackageNamesFn when necessary --- local_install_test.go | 11 ++++++++--- pkg/menus/clean_menu.go | 7 ++++--- pkg/menus/diff_menu.go | 8 +++++--- pkg/menus/edit_menu.go | 5 ++--- preparer.go | 8 ++++++-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/local_install_test.go b/local_install_test.go index f6487685..8632904f 100644 --- a/local_install_test.go +++ b/local_install_test.go @@ -138,7 +138,8 @@ func TestIntegrationLocalInstall(t *testing.T) { return nil }, - LocalPackageFn: func(s string) mock.IPackage { return nil }, + LocalPackageFn: func(s string) mock.IPackage { return nil }, + InstalledRemotePackageNamesFn: func() []string { return []string{} }, } config := &settings.Configuration{ @@ -417,6 +418,7 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) { return nil }, + InstalledRemotePackageNamesFn: func() []string { return []string{} }, } config := &settings.Configuration{ @@ -580,6 +582,7 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) { return nil }, + InstalledRemotePackageNamesFn: func() []string { return []string{} }, } config := &settings.Configuration{ @@ -841,7 +844,8 @@ func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) { SyncSatisfierFn: func(s string) mock.IPackage { return nil }, - LocalPackageFn: func(s string) mock.IPackage { return nil }, + LocalPackageFn: func(s string) mock.IPackage { return nil }, + InstalledRemotePackageNamesFn: func() []string { return []string{} }, } config := &settings.Configuration{ @@ -980,7 +984,8 @@ func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) { SyncSatisfierFn: func(s string) mock.IPackage { return nil }, - LocalPackageFn: func(s string) mock.IPackage { return nil }, + LocalPackageFn: func(s string) mock.IPackage { return nil }, + InstalledRemotePackageNamesFn: func() []string { return []string{} }, } config := &settings.Configuration{ diff --git a/pkg/menus/clean_menu.go b/pkg/menus/clean_menu.go index 0e100cb2..703a7e74 100644 --- a/pkg/menus/clean_menu.go +++ b/pkg/menus/clean_menu.go @@ -23,7 +23,9 @@ func anyExistInCache(pkgbuildDirs map[string]string) bool { return false } -func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error { +func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, + pkgbuildDirsByBase map[string]string, installed mapset.Set[string], +) error { if len(pkgbuildDirsByBase) == 0 { return nil // no work to do } @@ -47,8 +49,7 @@ func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, p bases = append(bases, pkg) } - // TOFIX: empty installed slice means installed filter is disabled - toClean, errClean := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewSet[string](), + toClean, errClean := selectionMenu(w, pkgbuildDirsByBase, bases, installed, gotext.Get("Packages to cleanBuild?"), settings.NoConfirm, config.AnswerClean, skipFunc) if errClean != nil { diff --git a/pkg/menus/diff_menu.go b/pkg/menus/diff_menu.go index 558b1cf8..1a2409e8 100644 --- a/pkg/menus/diff_menu.go +++ b/pkg/menus/diff_menu.go @@ -90,7 +90,7 @@ func gitHasDiff(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (bo return true, nil } -// Return wether or not we have reviewed a diff yet. It checks for the existence of +// Return whether or not we have reviewed a diff yet. It checks for the existence of // YAY_DIFF_REVIEW in the git ref-list. func gitHasLastSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) bool { _, _, err := cmdBuilder.Capture( @@ -145,7 +145,9 @@ func updatePkgbuildSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgb return errMulti.Return() } -func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error { +func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, + pkgbuildDirsByBase map[string]string, installed mapset.Set[string], +) error { if len(pkgbuildDirsByBase) == 0 { return nil // no work to do } @@ -155,7 +157,7 @@ func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pk bases = append(bases, base) } - toDiff, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewThreadUnsafeSet[string](), gotext.Get("Diffs to show?"), + toDiff, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, installed, gotext.Get("Diffs to show?"), settings.NoConfirm, config.AnswerDiff, nil) if errMenu != nil || len(toDiff) == 0 { return errMenu diff --git a/pkg/menus/edit_menu.go b/pkg/menus/edit_menu.go index 41a0c250..95c5a30a 100644 --- a/pkg/menus/edit_menu.go +++ b/pkg/menus/edit_menu.go @@ -114,7 +114,7 @@ func editPkgbuilds(log *text.Logger, pkgbuildDirs map[string]string, bases []str } func EditFn(ctx context.Context, cfg *settings.Configuration, w io.Writer, - pkgbuildDirsByBase map[string]string, + pkgbuildDirsByBase map[string]string, installed mapset.Set[string], ) error { if len(pkgbuildDirsByBase) == 0 { return nil // no work to do @@ -125,8 +125,7 @@ func EditFn(ctx context.Context, cfg *settings.Configuration, w io.Writer, bases = append(bases, pkg) } - toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, - mapset.NewThreadUnsafeSet[string](), + toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, installed, gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, cfg.AnswerEdit, nil) if errMenu != nil || len(toEdit) == 0 { return errMenu diff --git a/preparer.go b/preparer.go index fe677abb..dd732609 100644 --- a/preparer.go +++ b/preparer.go @@ -29,7 +29,9 @@ const ( PreDownloadSourcesHook HookType = "pre-download-sources" ) -type HookFn func(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error +type HookFn func(ctx context.Context, config *settings.Configuration, w io.Writer, + pkgbuildDirsByBase map[string]string, installed mapset.Set[string], +) error type Hook struct { Name string @@ -214,9 +216,11 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[stri return nil, err } + remoteNames := preper.dbExecutor.InstalledRemotePackageNames() + remoteNamesCache := mapset.NewThreadUnsafeSet(remoteNames...) for _, hookFn := range preper.hooks { if hookFn.Type == PreDownloadSourcesHook { - if err := hookFn.Hookfn(ctx, preper.cfg, os.Stdout, pkgBuildDirsByBase); err != nil { + if err := hookFn.Hookfn(ctx, preper.cfg, os.Stdout, pkgBuildDirsByBase, remoteNamesCache); err != nil { return nil, err } }