diff options
author | Paul Okstad <pokstad@gitlab.com> | 2020-07-11 03:30:09 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2020-07-11 03:30:09 +0300 |
commit | 1fae8b36711542e66b772164e159f29c14bb4ce4 (patch) | |
tree | cf8bda560eaecb473918ab3de72a845982457503 | |
parent | 15f6d1a084092ace5feee754ec7f43e010e102ff (diff) | |
parent | de7a5d9d55acc94ee537c81aa7eb516822960c5b (diff) |
Merge branch 'zj-remove-file-count-flag' into 'master'
Remove unused feature: File count commit languages
See merge request gitlab-org/gitaly!2356
-rw-r--r-- | internal/linguist/linguist.go | 42 | ||||
-rw-r--r-- | internal/metadata/featureflag/feature_flags.go | 2 | ||||
-rw-r--r-- | internal/service/commit/languages.go | 19 | ||||
-rw-r--r-- | internal/service/commit/languages_test.go | 8 |
4 files changed, 9 insertions, 62 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index 787a04bee..252e36047 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -19,10 +19,9 @@ func init() { config.RegisterHook(LoadColors) } -var exportedEnvVars = []string{"HOME", "PATH", "GEM_HOME", "BUNDLE_PATH", "BUNDLE_APP_CONFIG"} - var ( - colorMap = make(map[string]Language) + exportedEnvVars = []string{"HOME", "PATH", "GEM_HOME", "BUNDLE_PATH", "BUNDLE_APP_CONFIG"} + colorMap = make(map[string]Language) ) // Language is used to parse Linguist's language.json file. @@ -30,15 +29,9 @@ type Language struct { Color string `json:"color"` } -// CountPerLanguage represents a counter value (int) per language. -type CountPerLanguage map[string]int - // ByteCountPerLanguage represents a counter value (bytes) per language. type ByteCountPerLanguage map[string]uint64 -// FileListPerLanguage is used to parse Linguist's breakdown output to represent the list of files per language. -type FileListPerLanguage map[string][]string - // Stats returns the repository's language stats as reported by 'git-linguist'. func Stats(ctx context.Context, repoPath string, commitID string) (ByteCountPerLanguage, error) { cmd, err := startGitLinguist(ctx, repoPath, commitID, "stats") @@ -59,31 +52,6 @@ func Stats(ctx context.Context, repoPath string, commitID string) (ByteCountPerL return stats, json.Unmarshal(data, &stats) } -// FileCountStats returns the file counts per language -func FileCountStats(ctx context.Context, repoPath string, commitID string) (CountPerLanguage, error) { - reader, err := startGitLinguist(ctx, repoPath, commitID, "breakdown") - if err != nil { - return nil, err - } - - data, err := ioutil.ReadAll(reader) - if err != nil { - return nil, err - } - - languageFiles := make(FileListPerLanguage) - if err := json.Unmarshal(data, &languageFiles); err != nil { - return nil, err - } - - stats := make(CountPerLanguage) - for lang, files := range languageFiles { - stats[lang] = len(files) - } - - return stats, nil -} - // Color returns the color Linguist has assigned to language. func Color(language string) string { if color := colorMap[language].Color; color != "" { @@ -109,8 +77,7 @@ func startGitLinguist(ctx context.Context, repoPath string, commitID string, lin cmd := exec.Command("bundle", "exec", "bin/ruby-cd", repoPath, "git-linguist", "--commit="+commitID, linguistCommand) cmd.Dir = config.Config.Ruby.Dir - var env []string - internalCmd, err := command.New(ctx, cmd, nil, nil, nil, exportEnvironment(env)...) + internalCmd, err := command.New(ctx, cmd, nil, nil, nil, exportEnvironment()...) if err != nil { return nil, err } @@ -158,7 +125,8 @@ func openLanguagesJSON(cfg config.Cfg) (io.ReadCloser, error) { return os.Open(path.Join(linguistPathSymlink.Name(), "lib/linguist/languages.json")) } -func exportEnvironment(env []string) []string { +func exportEnvironment() []string { + var env []string for _, envVarName := range exportedEnvVars { if val, ok := os.LookupEnv(envVarName); ok { env = append(env, fmt.Sprintf("%s=%s", envVarName, val)) diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index 1580ef556..51e6e60c1 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -6,8 +6,6 @@ type FeatureFlag struct { } var ( - // LinguistFileCountStats will invoke an additional git-linguist command to get the number of files per language - LinguistFileCountStats = FeatureFlag{Name: "linguist_file_count_stats", OnByDefault: false} // GoUpdateHook will bypass the ruby update hook and use the go implementation of custom hooks GoUpdateHook = FeatureFlag{Name: "go_update_hook", OnByDefault: true} // RemoteBranchesLsRemote will use `ls-remote` for remote branches diff --git a/internal/service/commit/languages.go b/internal/service/commit/languages.go index 8f5cae955..d6e73629f 100644 --- a/internal/service/commit/languages.go +++ b/internal/service/commit/languages.go @@ -14,7 +14,6 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/linguist" - "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/service/ref" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -53,15 +52,6 @@ func (*server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLanguage return nil, err } - // TODO: remove feature flag when Stats and FileCountStats is executed with one ruby script call - fileCountStats := make(linguist.CountPerLanguage) - if featureflag.IsEnabled(ctx, featureflag.LinguistFileCountStats) { - fileCountStats, err = linguist.FileCountStats(ctx, repoPath, commitID) - if err != nil { - return nil, err - } - } - resp := &gitalypb.CommitLanguagesResponse{} if len(stats) == 0 { return resp, nil @@ -78,11 +68,10 @@ func (*server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLanguage for lang, count := range stats { l := &gitalypb.CommitLanguagesResponse_Language{ - Name: lang, - Share: float32(100*count) / float32(total), - Color: linguist.Color(lang), - FileCount: uint32(fileCountStats[lang]), - Bytes: stats[lang], + Name: lang, + Share: float32(100*count) / float32(total), + Color: linguist.Color(lang), + Bytes: stats[lang], } resp.Languages = append(resp.Languages, l) } diff --git a/internal/service/commit/languages_test.go b/internal/service/commit/languages_test.go index 67f241c37..3e7a79440 100644 --- a/internal/service/commit/languages_test.go +++ b/internal/service/commit/languages_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -29,8 +28,6 @@ func TestLanguages(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - ctx = EnableLinguistFileCountStatsFeatureFlag(ctx) - resp, err := client.CommitLanguages(ctx, request) require.NoError(t, err) @@ -87,7 +84,6 @@ func requireLanguageEqual(t *testing.T, expected, actual *gitalypb.CommitLanguag require.Equal(t, expected.Name, actual.Name) require.Equal(t, expected.Color, actual.Color) require.False(t, (expected.Share-actual.Share)*(expected.Share-actual.Share) >= 1.0, "shares do not match") - require.Equal(t, expected.FileCount, actual.FileCount) require.Equal(t, expected.Bytes, actual.Bytes) } @@ -163,7 +159,3 @@ func TestAmbiguousRefCommitLanguagesRequestRevision(t *testing.T) { }) require.NoError(t, err) } - -func EnableLinguistFileCountStatsFeatureFlag(ctx context.Context) context.Context { - return featureflag.OutgoingCtxWithFeatureFlags(ctx, featureflag.LinguistFileCountStats) -} |