diff options
author | Toon Claes <toon@gitlab.com> | 2022-09-07 15:57:22 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-10-03 16:26:16 +0300 |
commit | e720e48209b996acf23e0c8101fee6116be89cc5 (patch) | |
tree | fd75b2a1dea90577ef2e57f9beee12c54b7148f0 | |
parent | 4c15523cf680c107c5aa2b8268674cd0345a6b78 (diff) |
linguist: Remove git.CommandFactory variable
The linguist Instance does not use the git.CommandFactory variable, so
we can safely remove it.
-rw-r--r-- | cmd/gitaly/main.go | 2 | ||||
-rw-r--r-- | internal/gitaly/linguist/linguist.go | 16 | ||||
-rw-r--r-- | internal/gitaly/linguist/linguist_test.go | 15 | ||||
-rw-r--r-- | internal/testhelper/testserver/gitaly.go | 2 |
4 files changed, 15 insertions, 20 deletions
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go index e1097b866..e3f359ffa 100644 --- a/cmd/gitaly/main.go +++ b/cmd/gitaly/main.go @@ -287,7 +287,7 @@ func run(cfg config.Cfg) error { ) defer gitalyServerFactory.Stop() - ling, err := linguist.New(cfg, gitCmdFactory) + ling, err := linguist.New(cfg) if err != nil { return fmt.Errorf("linguist instance creation: %w", err) } diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go index 696f70a4f..9e4fa648c 100644 --- a/internal/gitaly/linguist/linguist.go +++ b/internal/gitaly/linguist/linguist.go @@ -32,14 +32,13 @@ type ByteCountPerLanguage map[string]uint64 // Instance is a holder of the defined in the system language settings. type Instance struct { - cfg config.Cfg - colorMap map[string]Language - gitCmdFactory git.CommandFactory + cfg config.Cfg + colorMap map[string]Language } -// New loads the name->color map from the Linguist gem and returns initialised instance -// to use back to the caller or an error. -func New(cfg config.Cfg, gitCmdFactory git.CommandFactory) (*Instance, error) { +// New loads the name->color map from the Linguist gem and returns initialized +// instance to use back to the caller or an error. +func New(cfg config.Cfg) (*Instance, error) { jsonReader, err := openLanguagesJSON(cfg) if err != nil { return nil, err @@ -52,9 +51,8 @@ func New(cfg config.Cfg, gitCmdFactory git.CommandFactory) (*Instance, error) { } return &Instance{ - cfg: cfg, - gitCmdFactory: gitCmdFactory, - colorMap: colorMap, + cfg: cfg, + colorMap: colorMap, }, nil } diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index c74152d00..18ee7e906 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -34,9 +34,8 @@ func TestNew_knownLanguages(t *testing.T) { t.Parallel() cfg := testcfg.Build(t, testcfg.WithRealLinguist()) - gitCmdFactory := gittest.NewCommandFactory(t, cfg) - linguist, err := New(cfg, gitCmdFactory) + linguist, err := New(cfg) require.NoError(t, err) t.Run("by name", func(t *testing.T) { @@ -86,9 +85,8 @@ func TestInstance_Stats(t *testing.T) { func testInstanceStats(t *testing.T, ctx context.Context) { cfg := testcfg.Build(t) - gitCmdFactory := gittest.NewCommandFactory(t, cfg) - linguist, err := New(cfg, gitCmdFactory) + linguist, err := New(cfg) require.NoError(t, err) catfileCache := catfile.NewCache(cfg) @@ -280,7 +278,7 @@ func TestInstance_Stats_unmarshalJSONError(t *testing.T) { repo := localrepo.New(config.NewLocator(cfg), gitCmdFactory, catfileCache, invalidRepo) - ling, err := New(cfg, gitCmdFactory) + ling, err := New(cfg) require.NoError(t, err) // When an error occurs, this used to trigger JSON marshaling of a plain string @@ -295,7 +293,7 @@ func TestInstance_Stats_unmarshalJSONError(t *testing.T) { func TestNew(t *testing.T) { cfg := testcfg.Build(t, testcfg.WithRealLinguist()) - ling, err := New(cfg, gittest.NewCommandFactory(t, cfg)) + ling, err := New(cfg) require.NoError(t, err) require.Equal(t, "#701516", ling.Color("Ruby"), "color value for 'Ruby'") @@ -307,7 +305,7 @@ func TestNew_loadLanguagesCustomPath(t *testing.T) { cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{Ruby: config.Ruby{LinguistLanguagesPath: jsonPath}})) - ling, err := New(cfg, gittest.NewCommandFactory(t, cfg)) + ling, err := New(cfg) require.NoError(t, err) require.Equal(t, "foo color", ling.Color("FooBar")) @@ -329,10 +327,9 @@ func BenchmarkInstance_Stats(b *testing.B) { func benchmarkInstanceStats(b *testing.B, ctx context.Context) { cfg := testcfg.Build(b) - gitCmdFactory := gittest.NewCommandFactory(b, cfg) languageStatsFilename := filenameForCache(ctx) - linguist, err := New(cfg, gitCmdFactory) + linguist, err := New(cfg) require.NoError(b, err) catfileCache := catfile.NewCache(cfg) diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go index db46ca039..e59080917 100644 --- a/internal/testhelper/testserver/gitaly.go +++ b/internal/testhelper/testserver/gitaly.go @@ -289,7 +289,7 @@ func (gsd *gitalyServerDeps) createDependencies(tb testing.TB, cfg config.Cfg, r if gsd.linguist == nil { var err error - gsd.linguist, err = linguist.New(cfg, gsd.gitCmdFactory) + gsd.linguist, err = linguist.New(cfg) require.NoError(tb, err) } |