Improve code readability #1

+ Improved tests readability of common_utils_test.go
+ Fixed minor typos
This commit is contained in:
Mikołaj Pęczkowski 2024-06-13 21:19:04 +02:00
parent 8cd3ed2127
commit 68636d5e64
8 changed files with 167 additions and 123 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"gitlab.com/revalus/grm/internal/config"
"path"
"sort"
)
@ -20,7 +21,7 @@ func NewStatusChecker(workspace string) StatusChecker {
}
func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit) int {
// This function is a helper function to get only five latest items, based on given commit
getFiveElementsFromHashes := func(commit *object.Commit, hashedSlice *[]string) *object.Commit {
var err error
@ -36,6 +37,7 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
return commit
}
// Compare diff between sources by hash list (the same hash list must be present to assume the end of changes)
getRangeDiff := func(listFist, listSecond []string) (int, bool) {
diffRange := 0
@ -54,6 +56,8 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
baseCommitHashes := []string{}
destCommitHashes := []string{}
// Try to find all differences, limit only to five last changes to avoid reading whole repository at once
for {
if srcCommit != nil {
@ -80,8 +84,8 @@ func (sc StatusChecker) Command(repoCfg config.RepositoryConfig) CommandStatus {
Error: false,
}
destPath := fmt.Sprintf("%v/%v", sc.workspace, repoCfg.Dest)
repo, err := git.PlainOpen(destPath)
repositoryPath := path.Join(sc.workspace, repoCfg.Dest)
repo, err := git.PlainOpen(repositoryPath)
if err != nil {
cmdStatus.Error = true