From bef23ac58bcd206eb2487605ea064c8b5491017d Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sat, 7 Sep 2024 09:16:04 +0300 Subject: small refactor Signed-off-by: Arthur Zamarin --- pkg/portage/utils/git.go | 15 ++++----------- pkg/utils/utils.go | 18 +++--------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/pkg/portage/utils/git.go b/pkg/portage/utils/git.go index 1a30cfb..e7efea3 100644 --- a/pkg/portage/utils/git.go +++ b/pkg/portage/utils/git.go @@ -20,7 +20,6 @@ func AllFiles() []string { "ls-tree", "-r", "master", "--name-only") - cmd.Dir = config.PortDir() out, err := cmd.CombinedOutput() if err != nil { @@ -95,24 +94,18 @@ func GetLatestCommit() string { // GetLatestCommitAndPreceding retrieves the latest // commit in the database. The hash of the latest commit // as well as the number of preceding commits is returned -func GetLatestCommitAndPreceding() (string, int) { - latestCommit := EmptyTree() - PrecedingCommitsOffset := 0 - +func GetLatestCommitAndPreceding() (latestCommit string, precedingCommitsOffset int) { var commits []*models.Commit err := database.DBCon.Model(&commits). Order("preceding_commits DESC"). Limit(1). Select() if err == nil && len(commits) == 1 { - latestCommit = commits[0].Id - PrecedingCommitsOffset = commits[0].PrecedingCommits + return commits[0].Id, commits[0].PrecedingCommits } - return latestCommit, PrecedingCommitsOffset + return EmptyTree, 0 } // EmptyTree returns the hash of the empty tree -func EmptyTree() string { - return "4b825dc642cb6eb9a060e54bf8d69288fbee4904" -} +const EmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index a715ff0..98f832b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,7 +2,7 @@ package utils import ( - "sort" + "slices" "strings" ) @@ -10,20 +10,8 @@ import ( // a slice which only contains unique items. func Deduplicate(items []string) []string { if len(items) > 1 { - sort.Strings(items) - j := 0 - for i := 1; i < len(items); i++ { - if items[j] == items[i] { - continue - } - j++ - // preserve the original data - // in[i], in[j] = in[j], in[i] - // only set what is required - items[j] = items[i] - } - result := items[:j+1] - return result + slices.Sort(items) + return slices.Compact(items) } else { return items } -- cgit v1.2.3-65-gdbad