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-08 17:56:59 +0300
committerToon Claes <toon@gitlab.com>2022-08-08 17:56:59 +0300
commitdb5acc711c54f1dcb68bc391dbd1172bcff7d731 (patch)
tree90e8c0a2b04fbb450f2ce74d8383747fba77c9c1
parentd7f29efee7cb002b2af753a204fb80228c5fe3f0 (diff)
linguist: Update version to invalidate cachetoon-linguist-no-zeroes
In the previous commit we've created a fix in the language stats, but there still might be faulty values cached. To invalidate those, update the version so we'll always recalculate stats from scratch unless it was calculated with the fix in place.
-rw-r--r--internal/gitaly/linguist/language_stats.go2
-rw-r--r--internal/gitaly/linguist/language_stats_test.go26
2 files changed, 27 insertions, 1 deletions
diff --git a/internal/gitaly/linguist/language_stats.go b/internal/gitaly/linguist/language_stats.go
index 62655d48b..e65a90c9a 100644
--- a/internal/gitaly/linguist/language_stats.go
+++ b/internal/gitaly/linguist/language_stats.go
@@ -16,7 +16,7 @@ const (
// a cached version of the language statistics. The name is
// intentionally different from what the linguist gem uses.
languageStatsFilename = "gitaly-language.stats"
- languageStatsVersion = "v1:gitaly"
+ languageStatsVersion = "v2:gitaly"
)
// languageStats takes care of accumulating and caching language statistics for
diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go
index 0656a664f..3417d74ca 100644
--- a/internal/gitaly/linguist/language_stats_test.go
+++ b/internal/gitaly/linguist/language_stats_test.go
@@ -3,6 +3,9 @@
package linguist
import (
+ "compress/zlib"
+ "encoding/json"
+ "fmt"
"os"
"path/filepath"
"testing"
@@ -54,6 +57,29 @@ func TestNewLanguageStats(t *testing.T) {
require.Empty(t, stats.ByFile)
},
},
+ {
+ desc: "incorrect version cache",
+ run: func(t *testing.T, repo *localrepo.Repo, repoPath string) {
+ stats, err := newLanguageStats(repo)
+ require.NoError(t, err)
+
+ stats.Totals["C"] = 555
+ stats.Version = "faulty"
+
+ // Copy save() behavior, but with a faulty version
+ file, err := os.OpenFile(filepath.Join(repoPath, languageStatsFilename), os.O_WRONLY|os.O_CREATE, 0o755)
+ require.NoError(t, err)
+ w := zlib.NewWriter(file)
+ require.NoError(t, json.NewEncoder(w).Encode(stats))
+ require.NoError(t, w.Close())
+ require.NoError(t, file.Sync())
+ require.NoError(t, file.Close())
+
+ newStats, err := newLanguageStats(repo)
+ require.Error(t, err, fmt.Errorf("new language stats version mismatch %s vs %s", languageStatsVersion, "faulty"))
+ require.Empty(t, newStats.Totals)
+ },
+ },
} {
t.Run(tc.desc, func(t *testing.T) {
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])