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-09 12:34:18 +0300
commitd470b8f48b5626ec1bcc13094070ac5052dbd54e (patch)
tree0b76a1f8b96e18bd73e791e88dcb143fc158a468
parent0b310f3cb26889f74f8b3024efc683279b2c6ef6 (diff)
linguist: Update version to invalidate cache
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 07904769d..a64f8ad90 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])