diff --git a/README.md b/README.md index cb7fab68..36c04f75 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![yay-bin](https://img.shields.io/aur/version/yay-bin?color=1793d1&label=yay-bin&logo=arch-linux&style=for-the-badge)](https://aur.archlinux.org/packages/yay-bin/) [![yay-git](https://img.shields.io/aur/version/yay-git?color=1793d1&label=yay-git&logo=arch-linux&style=for-the-badge)](https://aur.archlinux.org/packages/yay-git/) ![AUR votes](https://img.shields.io/aur/votes/yay?color=333333&style=for-the-badge) -[![GitHub license](https://img.shields.io/github/license/jguer/yay?color=333333&style=for-the-badge)](https://github.com/Jguer/yay/blob/master/LICENSE) +[![GitHub license](https://img.shields.io/github/license/jguer/yay?color=333333&style=for-the-badge)](https://github.com/Jguer/yay/blob/next/LICENSE) # yay diff --git a/pkg/dep/dep_graph.go b/pkg/dep/dep_graph.go index 93747414..4978df8c 100644 --- a/pkg/dep/dep_graph.go +++ b/pkg/dep/dep_graph.go @@ -22,19 +22,18 @@ import ( ) type InstallInfo struct { - Source Source - Reason Reason + LastModified int64 Version string LocalVersion string - SrcinfoPath *string - AURBase *string - SyncDBName *string - + AURBase string + SyncDBName string + SrcinfoPath string + Maintainer string + Source Source + Reason Reason IsGroup bool Upgrade bool Devel bool - LastModified int64 // Unix timestamp, non-zero only for AUR packages - Maintainer string // AUR maintainer username, empty for orphaned or non-AUR packages } func (i *InstallInfo) String() string { @@ -278,8 +277,8 @@ func (g *Grapher) GraphFromSrcInfos(ctx context.Context, graph *topo.Graph[strin Value: &InstallInfo{ Source: SrcInfo, Reason: reason, - SrcinfoPath: &pkgBuildDir, - AURBase: &pkg.PackageBase, + SrcinfoPath: pkgBuildDir, + AURBase: pkg.PackageBase, Version: pkg.Version, }, }) @@ -334,7 +333,7 @@ func (g *Grapher) GraphSyncPkg(ctx context.Context, Source: Sync, Reason: Explicit, Version: pkg.Version(), - SyncDBName: &dbName, + SyncDBName: dbName, } if upgradeInfo == nil { @@ -373,7 +372,7 @@ func (g *Grapher) GraphSyncGroup(ctx context.Context, Source: Sync, Reason: Explicit, Version: "", - SyncDBName: &dbName, + SyncDBName: dbName, IsGroup: true, }, }) @@ -468,7 +467,7 @@ func (g *Grapher) GraphFromAUR(ctx context.Context, } graph = g.GraphAURTarget(ctx, graph, aurPkg, &InstallInfo{ - AURBase: &aurPkg.PackageBase, + AURBase: aurPkg.PackageBase, Reason: reason, Source: AUR, Version: aurPkg.Version, @@ -498,8 +497,10 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context, return []aurc.Pkg{} } + depsSlice := deps.ToSlice() + missingNeedles := make([]string, 0, deps.Cardinality()) - for _, depString := range deps.ToSlice() { + for _, depString := range depsSlice { if _, ok := g.providerCache[depString]; !ok { depName, _, _ := splitDep(depString) missingNeedles = append(missingNeedles, depName) @@ -520,7 +521,7 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context, for i := range aurPkgs { pkg := &aurPkgs[i] // Cache by the full depString (including version) for each dep whose name matches - for _, depString := range deps.ToSlice() { + for _, depString := range depsSlice { depName, _, _ := splitDep(depString) if depName == pkg.Name { g.providerCache[depString] = append(g.providerCache[depString], *pkg) @@ -533,7 +534,7 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context, } // Also check provides against versioned deps provideName, _, _ := splitDep(val) - for _, depString := range deps.ToSlice() { + for _, depString := range depsSlice { depName, _, _ := splitDep(depString) if depName == provideName { g.providerCache[depString] = append(g.providerCache[depString], *pkg) @@ -543,7 +544,7 @@ func (g *Grapher) findDepsFromAUR(ctx context.Context, } } - for _, depString := range deps.ToSlice() { + for _, depString := range depsSlice { var aurPkgs []aurc.Pkg depName, _, _ := splitDep(depString) @@ -696,7 +697,7 @@ func (g *Grapher) addNodes( Source: Sync, Reason: depType, Version: alpmPkg.Version(), - SyncDBName: &dbName, + SyncDBName: dbName, }, }) @@ -728,7 +729,7 @@ func (g *Grapher) addNodes( Value: &InstallInfo{ Source: AUR, Reason: depType, - AURBase: &aurPkg.PackageBase, + AURBase: aurPkg.PackageBase, Version: aurPkg.Version, LastModified: int64(aurPkg.LastModified), Maintainer: aurPkg.Maintainer, diff --git a/pkg/dep/dep_graph_bench_test.go b/pkg/dep/dep_graph_bench_test.go index 5a8dd989..016b451c 100644 --- a/pkg/dep/dep_graph_bench_test.go +++ b/pkg/dep/dep_graph_bench_test.go @@ -302,13 +302,13 @@ func verifyLayers(t testing.TB, expected, actual []map[string]*InstallInfo) { require.Equal(t, expectedInfo.Source, actualInfo.Source, "source mismatch for %s", name) require.Equal(t, expectedInfo.Reason, actualInfo.Reason, "reason mismatch for %s", name) require.Equal(t, expectedInfo.Version, actualInfo.Version, "version mismatch for %s", name) - if expectedInfo.AURBase != nil { - require.NotNil(t, actualInfo.AURBase, "AURBase should not be nil for %s", name) - require.Equal(t, *expectedInfo.AURBase, *actualInfo.AURBase, "AURBase mismatch for %s", name) + if expectedInfo.AURBase != "" { + require.NotEmpty(t, actualInfo.AURBase, "AURBase should not be empty for %s", name) + require.Equal(t, expectedInfo.AURBase, actualInfo.AURBase, "AURBase mismatch for %s", name) } - if expectedInfo.SyncDBName != nil { - require.NotNil(t, actualInfo.SyncDBName, "SyncDBName should not be nil for %s", name) - require.Equal(t, *expectedInfo.SyncDBName, *actualInfo.SyncDBName, "SyncDBName mismatch for %s", name) + if expectedInfo.SyncDBName != "" { + require.NotEmpty(t, actualInfo.SyncDBName, "SyncDBName should not be empty for %s", name) + require.Equal(t, expectedInfo.SyncDBName, actualInfo.SyncDBName, "SyncDBName mismatch for %s", name) } } } @@ -322,27 +322,27 @@ func BenchmarkGraphFromTargets_GstreamerGit(b *testing.B) { name: "SingleTarget", targets: []string{"gst-plugins-good-git"}, expectedLayers: []map[string]*InstallInfo{ - {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gst-plugins-base-libs-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gstreamer-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, + {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gst-plugins-base-libs-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gstreamer-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, }, }, { name: "TwoTargets", targets: []string{"gstreamer-git", "gst-plugins-good-git"}, expectedLayers: []map[string]*InstallInfo{ - {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gst-plugins-base-libs-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gstreamer-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, + {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gst-plugins-base-libs-git": {Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gstreamer-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, }, }, { name: "AllThreeExplicit", targets: []string{"gstreamer-git", "gst-plugins-base-libs-git", "gst-plugins-good-git"}, expectedLayers: []map[string]*InstallInfo{ - {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gst-plugins-base-libs-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, - {"gstreamer-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: new("gstreamer-git")}}, + {"gst-plugins-good-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gst-plugins-base-libs-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, + {"gstreamer-git": {Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", AURBase: "gstreamer-git"}}, }, }, } @@ -378,8 +378,8 @@ func BenchmarkGraphFromTargets_Jellyfin(b *testing.B) { noDeps: true, noCheckDeps: false, expectedLayers: []map[string]*InstallInfo{ - {"jellyfin": {Source: AUR, Reason: Explicit, Version: "10.8.8-1", AURBase: new("jellyfin")}}, - {"dotnet-sdk-6.0": {Source: Sync, Reason: MakeDep, Version: "6.0.100-1", SyncDBName: new("community")}}, + {"jellyfin": {Source: AUR, Reason: Explicit, Version: "10.8.8-1", AURBase: "jellyfin"}}, + {"dotnet-sdk-6.0": {Source: Sync, Reason: MakeDep, Version: "6.0.100-1", SyncDBName: "community"}}, }, }, { @@ -388,14 +388,14 @@ func BenchmarkGraphFromTargets_Jellyfin(b *testing.B) { noDeps: false, noCheckDeps: false, expectedLayers: []map[string]*InstallInfo{ - {"jellyfin": {Source: AUR, Reason: Explicit, Version: "10.8.8-1", AURBase: new("jellyfin")}}, + {"jellyfin": {Source: AUR, Reason: Explicit, Version: "10.8.8-1", AURBase: "jellyfin"}}, { - "jellyfin-web": {Source: AUR, Reason: Dep, Version: "10.8.8-1", AURBase: new("jellyfin")}, - "jellyfin-server": {Source: AUR, Reason: Dep, Version: "10.8.8-1", AURBase: new("jellyfin")}, + "jellyfin-web": {Source: AUR, Reason: Dep, Version: "10.8.8-1", AURBase: "jellyfin"}, + "jellyfin-server": {Source: AUR, Reason: Dep, Version: "10.8.8-1", AURBase: "jellyfin"}, }, { - "dotnet-sdk-6.0": {Source: Sync, Reason: MakeDep, Version: "6.0.100-1", SyncDBName: new("community")}, - "dotnet-runtime-6.0": {Source: Sync, Reason: Dep, Version: "6.0.100-1", SyncDBName: new("community")}, + "dotnet-sdk-6.0": {Source: Sync, Reason: MakeDep, Version: "6.0.100-1", SyncDBName: "community"}, + "dotnet-runtime-6.0": {Source: Sync, Reason: Dep, Version: "6.0.100-1", SyncDBName: "community"}, }, }, }, @@ -430,24 +430,24 @@ func BenchmarkGraphFromTargets_CephProvides(b *testing.B) { name: "CephBinWithLibsBin", targets: []string{"ceph-bin", "ceph-libs-bin"}, expectedLayers: []map[string]*InstallInfo{ - {"ceph-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: new("ceph-bin")}}, - {"ceph-libs-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: new("ceph-bin")}}, + {"ceph-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: "ceph-bin"}}, + {"ceph-libs-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: "ceph-bin"}}, }, }, { name: "CephOnly", targets: []string{"ceph"}, expectedLayers: []map[string]*InstallInfo{ - {"ceph": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: new("ceph")}}, - {"ceph-libs": {Source: AUR, Reason: Dep, Version: "17.2.6-2", AURBase: new("ceph")}}, + {"ceph": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: "ceph"}}, + {"ceph-libs": {Source: AUR, Reason: Dep, Version: "17.2.6-2", AURBase: "ceph"}}, }, }, { name: "CephBinOnly", targets: []string{"ceph-bin"}, expectedLayers: []map[string]*InstallInfo{ - {"ceph-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: new("ceph-bin")}}, - {"ceph-libs": {Source: AUR, Reason: Dep, Version: "17.2.6-2", AURBase: new("ceph")}}, + {"ceph-bin": {Source: AUR, Reason: Explicit, Version: "17.2.6-2", AURBase: "ceph-bin"}}, + {"ceph-libs": {Source: AUR, Reason: Dep, Version: "17.2.6-2", AURBase: "ceph"}}, }, }, } @@ -480,8 +480,8 @@ func BenchmarkGraphFromTargets_AndroidSDK(b *testing.B) { name: "WithJDK", targets: []string{"android-sdk", "jdk11-openjdk"}, expectedLayers: []map[string]*InstallInfo{ - {"android-sdk": {Source: AUR, Reason: Explicit, Version: "26.1.1-2", AURBase: new("android-sdk")}}, - {"jdk11-openjdk": {Source: Sync, Reason: Explicit, Version: "11.0.12.u7-1", SyncDBName: new("community")}}, + {"android-sdk": {Source: AUR, Reason: Explicit, Version: "26.1.1-2", AURBase: "android-sdk"}}, + {"jdk11-openjdk": {Source: Sync, Reason: Explicit, Version: "11.0.12.u7-1", SyncDBName: "community"}}, }, } diff --git a/pkg/dep/dep_graph_rpc_test.go b/pkg/dep/dep_graph_rpc_test.go index 27175779..67021d07 100644 --- a/pkg/dep/dep_graph_rpc_test.go +++ b/pkg/dep/dep_graph_rpc_test.go @@ -106,7 +106,7 @@ func TestGrapher_ReliableParser_AWSCliGit(t *testing.T) { require.NotEmpty(td, layers) require.Contains(td, layers[0], "aws-cli-git") require.Equal(td, "1.27.145.r11217.g5885ee4dc-1", layers[0]["aws-cli-git"].Version) - require.Equal(td, "aws-cli-git", *layers[0]["aws-cli-git"].AURBase) + require.Equal(td, "aws-cli-git", layers[0]["aws-cli-git"].AURBase) require.Equal(td, Explicit, layers[0]["aws-cli-git"].Reason) require.Equal(td, AUR, layers[0]["aws-cli-git"].Source) }) @@ -282,11 +282,11 @@ func TestGrapher_SplitPackages_Clion(t *testing.T) { }} installInfos := map[string]*InstallInfo{ - "clion exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: new("clion"), LastModified: 1768325120, Maintainer: "Zrax"}, - "clion-jre exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: new("clion"), LastModified: 1768325120, Maintainer: "Zrax"}, - "clion-cmake exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: new("clion"), LastModified: 1768325120, Maintainer: "Zrax"}, - "clion-gdb exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: new("clion"), LastModified: 1768325120, Maintainer: "Zrax"}, - "clion-lldb exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: new("clion"), LastModified: 1768325120, Maintainer: "Zrax"}, + "clion exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: "clion", LastModified: 1768325120, Maintainer: "Zrax"}, + "clion-jre exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: "clion", LastModified: 1768325120, Maintainer: "Zrax"}, + "clion-cmake exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: "clion", LastModified: 1768325120, Maintainer: "Zrax"}, + "clion-gdb exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: "clion", LastModified: 1768325120, Maintainer: "Zrax"}, + "clion-lldb exp": {Source: AUR, Reason: Explicit, Version: "2025.3.1.1-1", AURBase: "clion", LastModified: 1768325120, Maintainer: "Zrax"}, } tests := []struct { @@ -345,8 +345,8 @@ func TestGrapher_SplitPackages_Clion(t *testing.T) { require.Len(t, layers, 1) for _, info := range layers[0] { - require.NotNil(t, info.AURBase) - require.Equal(t, "clion", *info.AURBase) + require.NotEmpty(t, info.AURBase) + require.Equal(t, "clion", info.AURBase) } }) } @@ -481,8 +481,8 @@ func TestGrapher_SplitPackages_SamsungUnifiedDriver(t *testing.T) { for _, layer := range layers { for _, info := range layer { - require.NotNil(t, info.AURBase) - require.Equal(t, "samsung-unified-driver", *info.AURBase) + require.NotEmpty(t, info.AURBase) + require.Equal(t, "samsung-unified-driver", info.AURBase) } } }) @@ -566,11 +566,11 @@ func TestGrapher_SplitPackages_NX(t *testing.T) { }} installInfos := map[string]*InstallInfo{ - "nxproxy exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: new("nx"), LastModified: 1693834449, Maintainer: "harrietobrien"}, - "nxagent exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: new("nx"), LastModified: 1693834449, Maintainer: "harrietobrien"}, - "nx-x11 dep": {Source: AUR, Reason: Dep, Version: "3.5.99.27-3", AURBase: new("nx"), LastModified: 1693834449, Maintainer: "harrietobrien"}, - "libxcomp dep": {Source: AUR, Reason: Dep, Version: "3.5.99.27-3", AURBase: new("nx"), LastModified: 1693834449, Maintainer: "harrietobrien"}, - "libxcomp exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: new("nx"), LastModified: 1693834449, Maintainer: "harrietobrien"}, + "nxproxy exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: "nx", LastModified: 1693834449, Maintainer: "harrietobrien"}, + "nxagent exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: "nx", LastModified: 1693834449, Maintainer: "harrietobrien"}, + "nx-x11 dep": {Source: AUR, Reason: Dep, Version: "3.5.99.27-3", AURBase: "nx", LastModified: 1693834449, Maintainer: "harrietobrien"}, + "libxcomp dep": {Source: AUR, Reason: Dep, Version: "3.5.99.27-3", AURBase: "nx", LastModified: 1693834449, Maintainer: "harrietobrien"}, + "libxcomp exp": {Source: AUR, Reason: Explicit, Version: "3.5.99.27-3", AURBase: "nx", LastModified: 1693834449, Maintainer: "harrietobrien"}, } tests := []struct { @@ -637,8 +637,8 @@ func TestGrapher_SplitPackages_NX(t *testing.T) { require.NoError(t, err) layers2 := got2.TopoSortedLayers(nil) - require.Equal(t, "nx", *layers1[0]["nxproxy"].AURBase) - require.Equal(t, "nx", *layers2[0]["nxagent"].AURBase) + require.Equal(t, "nx", layers1[0]["nxproxy"].AURBase) + require.Equal(t, "nx", layers2[0]["nxagent"].AURBase) totalPkgs1 := 0 for _, layer := range layers1 { diff --git a/pkg/dep/dep_graph_test.go b/pkg/dep/dep_graph_test.go index 39f987b4..cb1302b9 100644 --- a/pkg/dep/dep_graph_test.go +++ b/pkg/dep/dep_graph_test.go @@ -160,7 +160,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: AUR, Reason: Explicit, Version: "10.8.8-1", - AURBase: new("jellyfin"), + AURBase: "jellyfin", LastModified: 1669830147, Maintainer: "z3ntu", }, @@ -170,7 +170,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: Sync, Reason: MakeDep, Version: "6.0.100-1", - SyncDBName: new("community"), + SyncDBName: "community", }, }, }, @@ -193,7 +193,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: AUR, Reason: Explicit, Version: "10.8.8-1", - AURBase: new("jellyfin"), + AURBase: "jellyfin", LastModified: 1669830147, Maintainer: "z3ntu", }, @@ -203,7 +203,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: AUR, Reason: Dep, Version: "10.8.8-1", - AURBase: new("jellyfin"), + AURBase: "jellyfin", LastModified: 1669830147, Maintainer: "z3ntu", }, @@ -211,7 +211,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: AUR, Reason: Dep, Version: "10.8.8-1", - AURBase: new("jellyfin"), + AURBase: "jellyfin", LastModified: 1669830147, Maintainer: "z3ntu", }, @@ -221,13 +221,13 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) { Source: Sync, Reason: MakeDep, Version: "6.0.100-1", - SyncDBName: new("community"), + SyncDBName: "community", }, "dotnet-runtime-6.0": { Source: Sync, Reason: Dep, Version: "6.0.100-1", - SyncDBName: new("community"), + SyncDBName: "community", }, }, }, @@ -335,7 +335,7 @@ func TestGrapher_GraphProvides_androidsdk(t *testing.T) { Source: AUR, Reason: Explicit, Version: "26.1.1-2", - AURBase: new("android-sdk"), + AURBase: "android-sdk", LastModified: 1647982720, Maintainer: "dreamingincode", }, @@ -345,7 +345,7 @@ func TestGrapher_GraphProvides_androidsdk(t *testing.T) { Source: Sync, Reason: Explicit, Version: "11.0.12.u7-1", - SyncDBName: new("community"), + SyncDBName: "community", }, }, }, @@ -450,31 +450,31 @@ func TestGrapher_GraphFromAUR_Deps_ceph_bin(t *testing.T) { Source: AUR, Reason: Explicit, Version: "17.2.6-2", - AURBase: new("ceph-bin"), + AURBase: "ceph-bin", }, "ceph-libs-bin exp": { Source: AUR, Reason: Explicit, Version: "17.2.6-2", - AURBase: new("ceph-bin"), + AURBase: "ceph-bin", }, "ceph exp": { Source: AUR, Reason: Explicit, Version: "17.2.6-2", - AURBase: new("ceph"), + AURBase: "ceph", }, "ceph-libs exp": { Source: AUR, Reason: Explicit, Version: "17.2.6-2", - AURBase: new("ceph"), + AURBase: "ceph", }, "ceph-libs dep": { Source: AUR, Reason: Dep, Version: "17.2.6-2", - AURBase: new("ceph"), + AURBase: "ceph", }, } @@ -639,25 +639,25 @@ func TestGrapher_GraphFromAUR_Deps_gourou(t *testing.T) { Source: AUR, Reason: Explicit, Version: "0.8.1", - AURBase: new("gourou"), + AURBase: "gourou", }, "libzip dep": { Source: Sync, Reason: Dep, Version: "1.9.2-1", - SyncDBName: new("extra"), + SyncDBName: "extra", }, "libzip exp": { Source: Sync, Reason: Explicit, Version: "1.9.2-1", - SyncDBName: new("extra"), + SyncDBName: "extra", }, "libzip-git exp": { Source: AUR, Reason: Explicit, Version: "1.9.2.r159.gb3ac716c-1", - AURBase: new("libzip-git"), + AURBase: "libzip-git", }, } @@ -809,13 +809,13 @@ func TestGrapher_GraphFromTargets_ReinstalledDeps(t *testing.T) { Source: AUR, Reason: Dep, Version: "0.8.1", - AURBase: new("gourou"), + AURBase: "gourou", }, "libzip dep": { Source: Sync, Reason: Dep, Version: "1.9.2-1", - SyncDBName: new("extra"), + SyncDBName: "extra", }, } @@ -921,7 +921,7 @@ func TestGrapher_GraphFromTargets_TargetNotFound(t *testing.T) { Source: AUR, Reason: Explicit, Version: "1.0.0", - AURBase: new("okpkg"), + AURBase: "okpkg", }, }, }, layers, layers) @@ -1023,7 +1023,7 @@ func TestGrapher_GraphFromAUR_SplitPkgInternalDeps(t *testing.T) { Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", - AURBase: new("gstreamer-git"), + AURBase: "gstreamer-git", LastModified: 1700000000, Maintainer: "testmaint", }, @@ -1031,7 +1031,7 @@ func TestGrapher_GraphFromAUR_SplitPkgInternalDeps(t *testing.T) { Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", - AURBase: new("gstreamer-git"), + AURBase: "gstreamer-git", LastModified: 1700000000, Maintainer: "testmaint", }, @@ -1039,7 +1039,7 @@ func TestGrapher_GraphFromAUR_SplitPkgInternalDeps(t *testing.T) { Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", - AURBase: new("gstreamer-git"), + AURBase: "gstreamer-git", LastModified: 1700000000, Maintainer: "testmaint", }, @@ -1047,7 +1047,7 @@ func TestGrapher_GraphFromAUR_SplitPkgInternalDeps(t *testing.T) { Source: AUR, Reason: Dep, Version: "1.24.0.r37-1", - AURBase: new("gstreamer-git"), + AURBase: "gstreamer-git", LastModified: 1700000000, Maintainer: "testmaint", }, @@ -1055,7 +1055,7 @@ func TestGrapher_GraphFromAUR_SplitPkgInternalDeps(t *testing.T) { Source: AUR, Reason: Explicit, Version: "1.24.0.r37-1", - AURBase: new("gstreamer-git"), + AURBase: "gstreamer-git", LastModified: 1700000000, Maintainer: "testmaint", }, @@ -1313,6 +1313,6 @@ func TestGrapher_GraphFromAUR_VirtualProvides(t *testing.T) { require.Len(t, layers, 1) require.Contains(t, layers[0], "mesa-git") require.Equal(t, "24.0.0.r1234-1", layers[0]["mesa-git"].Version) - require.Equal(t, "mesa-git", *layers[0]["mesa-git"].AURBase) + require.Equal(t, "mesa-git", layers[0]["mesa-git"].AURBase) }) } diff --git a/pkg/dep/dep_unit_test.go b/pkg/dep/dep_unit_test.go index 777bfbab..0092da63 100644 --- a/pkg/dep/dep_unit_test.go +++ b/pkg/dep/dep_unit_test.go @@ -155,7 +155,7 @@ func TestGrapher_GraphSyncGroupAndValidateNodeInfo(t *testing.T) { groupInfo := graph.GetNodeInfo("editors").Value require.NotNil(t, groupInfo) require.True(t, groupInfo.IsGroup) - require.Equal(t, "community", *groupInfo.SyncDBName) + require.Equal(t, "community", groupInfo.SyncDBName) target := "grouped" graph.SetNodeInfo(target, &topo.NodeInfo[*InstallInfo]{Value: &InstallInfo{Reason: Explicit}}) diff --git a/pkg/dep/topo/dep.go b/pkg/dep/topo/dep.go index c3bff5b6..8f0b4a13 100644 --- a/pkg/dep/topo/dep.go +++ b/pkg/dep/topo/dep.go @@ -390,11 +390,10 @@ func (g *Graph[T, V]) buildTransitive(root T, nextFn func(T) NodeSet[T]) NodeSet out := make(NodeSet[T]) searchNext := []T{root} + discovered := make([]T, 0, 8) for len(searchNext) > 0 { - // List of new nodes from this layer of the dependency graph. This is - // assigned to `searchNext` at the end of the outer "discovery" loop. - discovered := []T{} + discovered = discovered[:0] for _, node := range searchNext { // For each node to discover, find the next nodes. @@ -409,7 +408,11 @@ func (g *Graph[T, V]) buildTransitive(root T, nextFn func(T) NodeSet[T]) NodeSet } } - searchNext = discovered + // Swap slices so the two backing arrays alternate roles each layer, + // keeping searchNext and discovered on separate backing arrays and + // avoiding any aliasing while we range over searchNext and append + // to discovered in the same iteration. + searchNext, discovered = discovered, searchNext } return out diff --git a/pkg/query/query_builder.go b/pkg/query/query_builder.go index d1a9697b..633d69bc 100644 --- a/pkg/query/query_builder.go +++ b/pkg/query/query_builder.go @@ -46,7 +46,8 @@ type SourceQueryBuilder struct { sortBy string searchBy string targetMode parser.TargetMode - queryMap map[string]map[string]any + aurQueryMap map[string]*aur.Pkg + repoQueryMap map[string]alpm.Package bottomUp bool singleLineResults bool separateSources bool @@ -75,7 +76,8 @@ func NewSourceQueryBuilder( searchBy: searchBy, singleLineResults: singleLineResults, separateSources: separateSources, - queryMap: map[string]map[string]any{}, + aurQueryMap: map[string]*aur.Pkg{}, + repoQueryMap: map[string]alpm.Package{}, results: make([]abstractResult, 0, 100), } } @@ -199,11 +201,7 @@ func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor for i := range repoResults { dbName := repoResults[i].DB().Name() - if s.queryMap[dbName] == nil { - s.queryMap[dbName] = map[string]any{} - } - - s.queryMap[dbName][repoResults[i].Name()] = repoResults[i] + s.repoQueryMap[repoResults[i].Name()] = repoResults[i] rawProvides := repoResults[i].Provides() @@ -213,7 +211,7 @@ func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor } sortableResults.results = append(sortableResults.results, abstractResult{ - source: repoResults[i].DB().Name(), + source: dbName, name: repoResults[i].Name(), description: repoResults[i].Description(), packageBase: repoResults[i].Base(), @@ -232,17 +230,13 @@ func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor dbName := "aur" for i := range aurResults { - if s.queryMap[dbName] == nil { - s.queryMap[dbName] = map[string]any{} - } - by := getSearchBy(s.searchBy) if (by == aur.NameDesc || by == aur.None || by == aur.Name) && !matchesSearch(&aurResults[i], pkgS) { continue } - s.queryMap[dbName][aurResults[i].Name] = aurResults[i] + s.aurQueryMap[aurResults[i].Name] = &aurResults[i] sortableResults.results = append(sortableResults.results, abstractResult{ source: dbName, @@ -289,13 +283,12 @@ func (s *SourceQueryBuilder) Results(dbExecutor db.Executor, verboseSearch Searc } } - pkg := s.queryMap[s.results[i].source][s.results[i].name] - - switch pPkg := pkg.(type) { - case aur.Pkg: - toPrint += aurPkgSearchString(&pPkg, dbExecutor, s.singleLineResults) - case alpm.Package: - toPrint += syncPkgSearchString(pPkg, dbExecutor, s.singleLineResults) + if s.results[i].source == "aur" { + pkg := s.aurQueryMap[s.results[i].name] + toPrint += aurPkgSearchString(pkg, dbExecutor, s.singleLineResults) + } else { + pkg := s.repoQueryMap[s.results[i].name] + toPrint += syncPkgSearchString(pkg, dbExecutor, s.singleLineResults) } s.logger.Println(toPrint) diff --git a/pkg/sync/build/installer.go b/pkg/sync/build/installer.go index 80628386..3bd1a59b 100644 --- a/pkg/sync/build/installer.go +++ b/pkg/sync/build/installer.go @@ -161,9 +161,9 @@ func (installer *Installer) handleLayer(ctx context.Context, for name, info := range layer { switch info.Source { case dep.AUR, dep.SrcInfo: - nameToBaseMap[name] = *info.AURBase + nameToBaseMap[name] = info.AURBase if installer.origTargets.Contains(name) { - aurOrigTargetBases.Add(*info.AURBase) + aurOrigTargetBases.Add(info.AURBase) } switch info.Reason { @@ -186,7 +186,7 @@ func (installer *Installer) handleLayer(ctx context.Context, upgradeSync = true continue // do not add to targets, let pacman handle it } - compositePkgName := fmt.Sprintf("%s/%s", *info.SyncDBName, name) + compositePkgName := fmt.Sprintf("%s/%s", info.SyncDBName, name) if info.IsGroup { syncGroups.Add(compositePkgName) diff --git a/pkg/sync/build/installer_test.go b/pkg/sync/build/installer_test.go index 372b291d..17cbd191 100644 --- a/pkg/sync/build/installer_test.go +++ b/pkg/sync/build/installer_test.go @@ -146,8 +146,8 @@ func TestInstaller_InstallNeeded(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, } @@ -239,8 +239,8 @@ func TestInstaller_BuildOnlySkipsInstall(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, } @@ -316,14 +316,14 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, "linux": { Source: dep.Sync, Reason: dep.Dep, Version: "17.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", }, }, }, @@ -345,15 +345,15 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, { "linux": { Source: dep.Sync, Reason: dep.Dep, Version: "17.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", }, }, }, @@ -371,13 +371,13 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { Source: dep.Sync, Reason: dep.Explicit, Version: "18.0.0-1", - SyncDBName: new("extra"), + SyncDBName: "extra", }, "linux": { Source: dep.Sync, Reason: dep.Explicit, Version: "17.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", }, }, }, @@ -399,15 +399,15 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, "jellyfin-server": { Source: dep.AUR, Reason: dep.Explicit, Version: "10.8.8-1", - SrcinfoPath: new(tmpDirJfin + "/.SRCINFO"), - AURBase: new("jellyfin"), + SrcinfoPath: tmpDirJfin + "/.SRCINFO", + AURBase: "jellyfin", }, }, }, @@ -431,16 +431,16 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, { "jellyfin-server": { Source: dep.AUR, Reason: dep.MakeDep, Version: "10.8.8-1", - SrcinfoPath: new(tmpDirJfin + "/.SRCINFO"), - AURBase: new("jellyfin"), + SrcinfoPath: tmpDirJfin + "/.SRCINFO", + AURBase: "jellyfin", }, }, }, @@ -604,8 +604,8 @@ func TestInstaller_CompileFailed(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -622,8 +622,8 @@ func TestInstaller_CompileFailed(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -636,15 +636,15 @@ func TestInstaller_CompileFailed(t *testing.T) { failPkgInstall: false, targets: []map[string]*dep.InstallInfo{ {"bob": { - AURBase: new("yay"), + AURBase: "yay", }}, { "yay": { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -709,8 +709,8 @@ func TestInstaller_CompileFailed(t *testing.T) { uniqueBases := make(map[string]struct{}) for _, layer := range tc.targets { for _, info := range layer { - if info.AURBase != nil { - uniqueBases[*info.AURBase] = struct{}{} + if info.AURBase != "" { + uniqueBases[info.AURBase] = struct{}{} } } } @@ -752,23 +752,23 @@ func TestInstaller_InstallSplitPackage(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "10.8.4-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("jellyfin"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "jellyfin", }}, { "jellyfin-server": { Source: dep.AUR, Reason: dep.Dep, Version: "10.8.4-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("jellyfin"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "jellyfin", }, "jellyfin-web": { Source: dep.AUR, Reason: dep.Dep, Version: "10.8.4-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("jellyfin"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "jellyfin", }, }, { @@ -776,19 +776,19 @@ func TestInstaller_InstallSplitPackage(t *testing.T) { Source: dep.Sync, Reason: dep.Dep, Version: "6.0.12.sdk112-1", - SyncDBName: new("community"), + SyncDBName: "community", }, "aspnet-runtime": { Source: dep.Sync, Reason: dep.Dep, Version: "6.0.12.sdk112-1", - SyncDBName: new("community"), + SyncDBName: "community", }, "dotnet-sdk-6.0": { Source: dep.Sync, Reason: dep.MakeDep, Version: "6.0.12.sdk112-1", - SyncDBName: new("community"), + SyncDBName: "community", }, }, }, @@ -1006,8 +1006,8 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, } @@ -1109,7 +1109,7 @@ func TestInstaller_InstallGroup(t *testing.T) { Reason: dep.Explicit, Version: "", IsGroup: true, - SyncDBName: new("community"), + SyncDBName: "community", }, }, } @@ -1186,8 +1186,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1210,8 +1210,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1234,8 +1234,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1258,8 +1258,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { Source: dep.AUR, Reason: dep.Dep, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1409,7 +1409,7 @@ func TestInstaller_InstallUpgrade(t *testing.T) { Source: dep.Sync, Reason: dep.Dep, Version: "17.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", }, }, } @@ -1473,8 +1473,8 @@ func TestInstaller_KeepSrc(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "92.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1583,8 +1583,8 @@ func TestInstaller_InstallAsExplicit(t *testing.T) { Source: dep.AUR, Reason: dep.Dep, Version: "91.0.0-1", - SrcinfoPath: new(tmpDir + "/.SRCINFO"), - AURBase: new("yay"), + SrcinfoPath: tmpDir + "/.SRCINFO", + AURBase: "yay", }, }, }, @@ -1610,7 +1610,7 @@ func TestInstaller_InstallAsExplicit(t *testing.T) { Source: dep.Sync, Reason: dep.Dep, Version: "17.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", }, }, }, diff --git a/pkg/sync/post_install_test.go b/pkg/sync/post_install_test.go index a38fc070..bc53c1d0 100644 --- a/pkg/sync/post_install_test.go +++ b/pkg/sync/post_install_test.go @@ -23,14 +23,14 @@ func TestPostInstallEvent(t *testing.T) { Reason: dep.Explicit, Version: "2.0-1", LocalVersion: "1.0-1", - AURBase: &base, + AURBase: base, }, "pkgB": { Source: dep.AUR, Reason: dep.Dep, Version: "1.1-1", LocalVersion: "", - AURBase: &base, + AURBase: base, }, }, { @@ -46,7 +46,7 @@ func TestPostInstallEvent(t *testing.T) { Reason: dep.Explicit, Version: "2.0-2", LocalVersion: "1.0-1", - AURBase: &base, + AURBase: base, }, }, } diff --git a/pkg/sync/workdir/aur_post_download_test.go b/pkg/sync/workdir/aur_post_download_test.go index b8aa0260..b7f1d3e2 100644 --- a/pkg/sync/workdir/aur_post_download_test.go +++ b/pkg/sync/workdir/aur_post_download_test.go @@ -25,7 +25,7 @@ func TestAURPostDownloadEventsUseAURPreInstallPayload(t *testing.T) { mapset.NewThreadUnsafeSet[string](), []map[string]*dep.InstallInfo{ { - "demo": {Source: dep.AUR, AURBase: &base, Version: "1.0-1"}, + "demo": {Source: dep.AUR, AURBase: base, Version: "1.0-1"}, }, }) require.NoError(t, err) @@ -72,8 +72,8 @@ func TestRunAURPostDownloadLuaHooksRunsBasesInSortedOrder(t *testing.T) { mapset.NewThreadUnsafeSet[string](), []map[string]*dep.InstallInfo{ { - "a": {Source: dep.AUR, AURBase: new("a-base")}, - "z": {Source: dep.AUR, AURBase: new("z-base")}, + "a": {Source: dep.AUR, AURBase: "a-base"}, + "z": {Source: dep.AUR, AURBase: "z-base"}, }, }) require.NoError(t, err) diff --git a/pkg/sync/workdir/aur_preinstall.go b/pkg/sync/workdir/aur_preinstall.go index 90d88796..7528dc2b 100644 --- a/pkg/sync/workdir/aur_preinstall.go +++ b/pkg/sync/workdir/aur_preinstall.go @@ -148,7 +148,7 @@ func aurTargetPackagesByBase(targets []map[string]*dep.InstallInfo) map[string][ for _, layer := range targets { for name, info := range layer { - if info == nil || info.AURBase == nil { + if info == nil || info.AURBase == "" { continue } @@ -156,7 +156,7 @@ func aurTargetPackagesByBase(targets []map[string]*dep.InstallInfo) map[string][ continue } - base := *info.AURBase + base := info.AURBase packages[base] = append(packages[base], settingslua.AURPreInstallPackage{ Name: name, Version: info.Version, @@ -209,11 +209,11 @@ func aurPreInstallLastModified(base string, targets []map[string]*dep.InstallInf for _, layer := range targets { for _, info := range layer { - if info == nil || info.AURBase == nil { + if info == nil || info.AURBase == "" { continue } - if *info.AURBase == base && info.LastModified > lastModified { + if info.AURBase == base && info.LastModified > lastModified { lastModified = info.LastModified } } diff --git a/pkg/sync/workdir/aur_preinstall_test.go b/pkg/sync/workdir/aur_preinstall_test.go index f0f8db98..0d6981e9 100644 --- a/pkg/sync/workdir/aur_preinstall_test.go +++ b/pkg/sync/workdir/aur_preinstall_test.go @@ -30,7 +30,7 @@ func TestAURPreInstallEventsFromPackageFiles(t *testing.T) { Reason: dep.MakeDep, Version: "1:1.2.3-4", LocalVersion: "1:1.2.3-3", - AURBase: &base, + AURBase: base, Upgrade: true, Devel: true, LastModified: 1700000001, @@ -39,7 +39,7 @@ func TestAURPreInstallEventsFromPackageFiles(t *testing.T) { Source: dep.AUR, Reason: dep.Explicit, Version: "1:1.2.3-4", - AURBase: &base, + AURBase: base, LastModified: 1700000000, }, }, @@ -114,8 +114,8 @@ func TestRunAURPreInstallLuaHooksRunsBasesInSortedOrder(t *testing.T) { mapset.NewThreadUnsafeSet[string](), []map[string]*dep.InstallInfo{ { - "a": {Source: dep.AUR, AURBase: new("a-base")}, - "z": {Source: dep.AUR, AURBase: new("z-base")}, + "a": {Source: dep.AUR, AURBase: "a-base"}, + "z": {Source: dep.AUR, AURBase: "z-base"}, }, }) require.NoError(t, err) @@ -162,7 +162,7 @@ func TestRunPreDownloadSourcesHooksRunsLuaBeforeMenus(t *testing.T) { map[string]string{base: dir}, mapset.NewThreadUnsafeSet[string](), []map[string]*dep.InstallInfo{ { - "demo": {Source: dep.AUR, AURBase: &base}, + "demo": {Source: dep.AUR, AURBase: base}, }, }) require.NoError(t, err) @@ -189,7 +189,7 @@ func TestRunAURPreInstallLuaHooksReturnsCallbackError(t *testing.T) { map[string]string{base: dir}, mapset.NewThreadUnsafeSet[string](), []map[string]*dep.InstallInfo{ { - "demo": {Source: dep.AUR, AURBase: &base}, + "demo": {Source: dep.AUR, AURBase: base}, }, }) require.Error(t, err) diff --git a/pkg/sync/workdir/preparer.go b/pkg/sync/workdir/preparer.go index 27162fc9..c8c20476 100644 --- a/pkg/sync/workdir/preparer.go +++ b/pkg/sync/workdir/preparer.go @@ -196,15 +196,15 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context, for _, info := range layer { switch info.Source { case dep.AUR: - pkgBase := *info.AURBase + pkgBase := info.AURBase pkgBuildDir := filepath.Join(preper.cfg.BuildDir, pkgBase) if preper.needToCloneAURBase(info, pkgBuildDir) { aurBasesToClone.Add(pkgBase) } pkgBuildDirsByBase[pkgBase] = pkgBuildDir case dep.SrcInfo: - pkgBase := *info.AURBase - pkgBuildDirsByBase[pkgBase] = *info.SrcinfoPath + pkgBase := info.AURBase + pkgBuildDirsByBase[pkgBase] = info.SrcinfoPath } } } @@ -252,7 +252,7 @@ func (preper *Preparer) needToCloneAURBase(installInfo *dep.InstallInfo, pkgbuil if db.VerCmp(pkgbuild.Version(), installInfo.Version) >= 0 { preper.log.OperationInfoln( gotext.Get("PKGBUILD up to date, skipping download: %s", - text.Cyan(*installInfo.AURBase))) + text.Cyan(installInfo.AURBase))) return false } } diff --git a/pkg/upgrade/service.go b/pkg/upgrade/service.go index 8e9fd1cb..482c1456 100644 --- a/pkg/upgrade/service.go +++ b/pkg/upgrade/service.go @@ -120,7 +120,7 @@ func (u *UpgradeService) upGraph(ctx context.Context, graph *topo.Graph[string, graph = u.grapher.GraphAURTarget(ctx, graph, aurPkg, &dep.InstallInfo{ Reason: reason, Source: dep.AUR, - AURBase: &aurPkg.PackageBase, + AURBase: aurPkg.PackageBase, Upgrade: true, Devel: true, LocalVersion: up.LocalVersion, @@ -153,7 +153,7 @@ func (u *UpgradeService) upGraph(ctx context.Context, graph *topo.Graph[string, graph = u.grapher.GraphAURTarget(ctx, graph, aurPkg, &dep.InstallInfo{ Reason: reason, Source: dep.AUR, - AURBase: &aurPkg.PackageBase, + AURBase: aurPkg.PackageBase, Upgrade: true, Version: up.RemoteVersion, LocalVersion: up.LocalVersion, @@ -221,7 +221,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn Name: name, RemoteVersion: info.Version, Repository: aurRepo, - Base: *info.AURBase, + Base: info.AURBase, LocalVersion: info.LocalVersion, Reason: alpmReason, Extra: extra, @@ -232,7 +232,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn repoUp.Up = append(repoUp.Up, Upgrade{ Name: name, RemoteVersion: info.Version, - Repository: *info.SyncDBName, + Repository: info.SyncDBName, Base: "", LocalVersion: info.LocalVersion, Reason: alpmReason, diff --git a/pkg/upgrade/service_test.go b/pkg/upgrade/service_test.go index d14e2448..ceae99de 100644 --- a/pkg/upgrade/service_test.go +++ b/pkg/upgrade/service_test.go @@ -52,7 +52,7 @@ func newUpgradeSelectTestGraph(t *testing.T) *topo.Graph[string, *dep.InstallInf Value: &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.Sync, - SyncDBName: new("core"), + SyncDBName: "core", LocalVersion: "1.0", Version: "2.0", Upgrade: true, @@ -64,7 +64,7 @@ func newUpgradeSelectTestGraph(t *testing.T) *topo.Graph[string, *dep.InstallInf Value: &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.AUR, - AURBase: new("yay"), + AURBase: "yay", LocalVersion: "1.0", Version: "2.0", Upgrade: true, @@ -79,7 +79,7 @@ func newUpgradeSelectTestGraph(t *testing.T) *topo.Graph[string, *dep.InstallInf Value: &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.AUR, - AURBase: new("example"), + AURBase: "example", LocalVersion: "1.0", Version: "2.0", Upgrade: true, @@ -90,7 +90,7 @@ func newUpgradeSelectTestGraph(t *testing.T) *topo.Graph[string, *dep.InstallInf Value: &dep.InstallInfo{ Reason: dep.Dep, Source: dep.Sync, - SyncDBName: new("core"), + SyncDBName: "core", Version: "1.0", Upgrade: true, }, @@ -104,10 +104,9 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) { linuxDepInfo := &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.Sync, - AURBase: nil, LocalVersion: "4.5.0-1", Version: "5.0.0-1", - SyncDBName: new("core"), + SyncDBName: "core", Upgrade: true, Devel: false, } @@ -115,7 +114,7 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) { exampleDepInfoDevel := &dep.InstallInfo{ Source: dep.AUR, Reason: dep.Dep, - AURBase: new("example"), + AURBase: "example", LocalVersion: "2.2.1.r32.41baa362-1", Version: "latest-commit", Upgrade: true, @@ -126,7 +125,7 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) { newDepInfo := &dep.InstallInfo{ Source: dep.Sync, Reason: dep.Dep, - SyncDBName: new("core"), + SyncDBName: "core", Version: "3.0.1-2", LocalVersion: "", Upgrade: true, @@ -136,7 +135,7 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) { exampleDepInfoAUR := &dep.InstallInfo{ Source: dep.AUR, Reason: dep.Dep, - AURBase: new("example"), + AURBase: "example", LocalVersion: "2.2.1.r32.41baa362-1", Version: "2.2.1.r69.g8a10460-1", Upgrade: true, @@ -147,7 +146,7 @@ func TestUpgradeService_GraphUpgrades(t *testing.T) { yayDepInfo := &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.AUR, - AURBase: new("yay"), + AURBase: "yay", LocalVersion: "10.2.3", Version: "10.2.4", Upgrade: true, @@ -465,7 +464,7 @@ func TestUpgradeService_GraphUpgradesMissingDep(t *testing.T) { exampleDepInfoAUR := &dep.InstallInfo{ Source: dep.AUR, Reason: dep.Dep, - AURBase: new("example"), + AURBase: "example", LocalVersion: "2.2.1.r32.41baa362-1", Version: "2.2.1.r69.g8a10460-1", Upgrade: true, @@ -475,7 +474,7 @@ func TestUpgradeService_GraphUpgradesMissingDep(t *testing.T) { yayDepInfo := &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.AUR, - AURBase: new("yay"), + AURBase: "yay", LocalVersion: "10.2.3", Version: "10.2.4", Upgrade: true, @@ -951,7 +950,7 @@ func TestUpgradeService_GraphUpgrades_zfs_dkms(t *testing.T) { zfsDKMSInfo := &dep.InstallInfo{ Reason: dep.Explicit, Source: dep.AUR, - AURBase: new("zfs-dkms"), + AURBase: "zfs-dkms", LocalVersion: "2.1.10-1", Version: "2.1.11-1", Upgrade: true, @@ -961,7 +960,7 @@ func TestUpgradeService_GraphUpgrades_zfs_dkms(t *testing.T) { zfsUtilsInfo := &dep.InstallInfo{ Reason: dep.Dep, Source: dep.AUR, - AURBase: new("zfs-utils"), + AURBase: "zfs-utils", LocalVersion: "2.1.10-1", Version: "2.1.11-1", Upgrade: true, diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index c531df99..32646c7c 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -119,7 +119,9 @@ func (v *InfoStore) getCommit(ctx context.Context, url, branch string, protocols func (v *InfoStore) Update(ctx context.Context, pkgName string, sources []gosrc.ArchString) { var wg sync.WaitGroup + info := make(OriginInfoByURL) + checkSource := func(source gosrc.ArchString) { defer wg.Done() @@ -141,13 +143,9 @@ func (v *InfoStore) Update(ctx context.Context, pkgName string, sources []gosrc. } v.OriginsByPackage[pkgName] = info + v.mux.Unlock() v.logger.Debugln(gotext.Get("Found git repo: %s", text.Cyan(url))) - - if err := v.Save(); err != nil { - fmt.Fprintln(os.Stderr, err) - } - v.mux.Unlock() } for _, source := range sources { @@ -157,6 +155,12 @@ func (v *InfoStore) Update(ctx context.Context, pkgName string, sources []gosrc. } wg.Wait() + + if len(info) > 0 { + if err := v.Save(); err != nil { + fmt.Fprintln(os.Stderr, err) + } + } } // parseSource returns the git url, default branch and protocols it supports. diff --git a/vcs.go b/vcs.go index b4dd91be..fec889da 100644 --- a/vcs.go +++ b/vcs.go @@ -21,7 +21,7 @@ func infoToInstallInfo(info []aur.Pkg) []map[string]*dep.InstallInfo { for i := range info { pkg := &info[i] installInfo[0][pkg.Name] = &dep.InstallInfo{ - AURBase: &pkg.PackageBase, + AURBase: pkg.PackageBase, Source: dep.AUR, } } diff --git a/vcs_ops_test.go b/vcs_ops_test.go index 9a25e558..9212a976 100644 --- a/vcs_ops_test.go +++ b/vcs_ops_test.go @@ -19,6 +19,6 @@ func TestInfoToInstallInfo(t *testing.T) { require.Len(t, info, 1) require.Len(t, info[0], 2) - require.Equal(t, &dep.InstallInfo{AURBase: new("foo-base"), Source: dep.AUR}, info[0]["foo"]) - require.Equal(t, &dep.InstallInfo{AURBase: new("bar-base"), Source: dep.AUR}, info[0]["bar"]) + require.Equal(t, &dep.InstallInfo{AURBase: "foo-base", Source: dep.AUR}, info[0]["foo"]) + require.Equal(t, &dep.InstallInfo{AURBase: "bar-base", Source: dep.AUR}, info[0]["bar"]) }