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:
-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])