Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2022-08-05 13:13:37 +0300
committerToon Claes <toon@gitlab.com>2022-08-09 12:34:18 +0300
commit0b310f3cb26889f74f8b3024efc683279b2c6ef6 (patch)
tree54a9a109ba6bd733ccd004fbf1c1911b418fa12a
parentb27f8435115f3258875b3c4e1c55cc20f6d1bd29 (diff)
linguist: Ensure empty files are omitted in totals
Empty files should not be taken into account when calculation totals, because the totals should have no languages that have a count of zero. The linguist gem did this correctly already, but the newer Go implementation didn't. Issue: https://gitlab.com/gitlab-org/gitaly/-/issues/4416 Changelog: fixed
-rw-r--r--internal/gitaly/linguist/language_stats.go4
-rw-r--r--internal/gitaly/linguist/linguist_test.go15
2 files changed, 18 insertions, 1 deletions
diff --git a/internal/gitaly/linguist/language_stats.go b/internal/gitaly/linguist/language_stats.go
index c90452090..62655d48b 100644
--- a/internal/gitaly/linguist/language_stats.go
+++ b/internal/gitaly/linguist/language_stats.go
@@ -89,7 +89,9 @@ func (c *languageStats) add(filename, language string, size uint64) {
}
c.ByFile[filename] = ByteCountPerLanguage{language: size}
- c.Totals[language] += size
+ if size > 0 {
+ c.Totals[language] += size
+ }
}
// drop statistics for the given files
diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go
index ef90e1726..cd9d68f63 100644
--- a/internal/gitaly/linguist/linguist_test.go
+++ b/internal/gitaly/linguist/linguist_test.go
@@ -123,6 +123,21 @@ func testInstanceStats(t *testing.T, ctx context.Context) {
},
},
{
+ desc: "empty code files",
+ setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ emptyBlob := gittest.WriteBlob(t, cfg, repoPath, []byte{})
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
+ gittest.TreeEntry{Path: "README.md", Mode: "100644", Content: "Hello world!"},
+ gittest.TreeEntry{Path: "index.html", Mode: "100644", OID: emptyBlob},
+ gittest.TreeEntry{Path: "app.js", Mode: "100644", OID: emptyBlob},
+ ))
+
+ return repoProto, repoPath, commitID
+ },
+ expectedStats: ByteCountPerLanguage{},
+ },
+ {
desc: "preexisting cache",
setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) {
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])