aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-12 07:18:26 +0200
committerGitHub <noreply@github.com>2022-10-12 13:18:26 +0800
commit0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch)
treee5a92c55af5366924bd40ae14b4bf12842239193 /modules/git
parente84558b0931309cf1f4f2767bc47296483b9b3e1 (diff)
downloadgitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz
gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip
Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/log_name_status.go12
-rw-r--r--modules/git/repo_stats.go8
2 files changed, 10 insertions, 10 deletions
diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go
index 80f1602708..469932525f 100644
--- a/modules/git/log_name_status.go
+++ b/modules/git/log_name_status.go
@@ -14,6 +14,8 @@ import (
"sort"
"strings"
+ "code.gitea.io/gitea/modules/container"
+
"github.com/djherbis/buffer"
"github.com/djherbis/nio/v3"
)
@@ -339,7 +341,7 @@ func WalkGitLog(ctx context.Context, repo *Repository, head *Commit, treepath st
lastEmptyParent := head.ID.String()
commitSinceLastEmptyParent := uint64(0)
commitSinceNextRestart := uint64(0)
- parentRemaining := map[string]bool{}
+ parentRemaining := make(container.Set[string])
changed := make([]bool, len(paths))
@@ -365,7 +367,7 @@ heaploop:
if current == nil {
break heaploop
}
- delete(parentRemaining, current.CommitID)
+ parentRemaining.Remove(current.CommitID)
if current.Paths != nil {
for i, found := range current.Paths {
if !found {
@@ -410,14 +412,12 @@ heaploop:
}
}
g = NewLogNameStatusRepoParser(ctx, repo.Path, lastEmptyParent, treepath, remainingPaths...)
- parentRemaining = map[string]bool{}
+ parentRemaining = make(container.Set[string])
nextRestart = (remaining * 3) / 4
continue heaploop
}
}
- for _, parent := range current.ParentIDs {
- parentRemaining[parent] = true
- }
+ parentRemaining.AddMultiple(current.ParentIDs...)
}
g.Close()
diff --git a/modules/git/repo_stats.go b/modules/git/repo_stats.go
index c0c91c6fc6..cb44c58cec 100644
--- a/modules/git/repo_stats.go
+++ b/modules/git/repo_stats.go
@@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"
+
+ "code.gitea.io/gitea/modules/container"
)
// CodeActivityStats represents git statistics data
@@ -80,7 +82,7 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
stats.Additions = 0
stats.Deletions = 0
authors := make(map[string]*CodeActivityAuthor)
- files := make(map[string]bool)
+ files := make(container.Set[string])
var author string
p := 0
for scanner.Scan() {
@@ -119,9 +121,7 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
stats.Deletions += c
}
}
- if _, ok := files[parts[2]]; !ok {
- files[parts[2]] = true
- }
+ files.Add(parts[2])
}
}
}