Skip to content

Commit 4dea749

Browse files
committed
refactor code
1 parent 9670ca4 commit 4dea749

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/git/RepositoryManagerAnalytics.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func transform(src *object.Commit, tag *object.Tag) (dst *Commit) {
202202
func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(gitCtx GitContext, checkoutPath string, Old string, New string) (*GitChanges, error) {
203203
var err error
204204
start := time.Now()
205+
useGitCli := impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics
205206
defer func() {
206207
util.TriggerGitOperationMetrics("changesSinceByRepositoryForAnalytics", start, err)
207208
}()
@@ -214,7 +215,7 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
214215
oldHash := plumbing.NewHash(Old)
215216

216217
var fileStats FileStats
217-
if strings.Contains(checkoutPath, "/.git") || impl.configuration.UseGitCli {
218+
if strings.Contains(checkoutPath, "/.git") || useGitCli {
218219
oldHashString := oldHash.String()
219220
newHashString := newHash.String()
220221
fileStats, err = impl.gitManager.FetchDiffStatBetweenCommitsWithNumstat(gitCtx, oldHashString, newHashString, checkoutPath)
@@ -243,15 +244,16 @@ func (impl RepositoryManagerAnalyticsImpl) ChangesSinceByRepositoryForAnalytics(
243244
func (impl RepositoryManagerAnalyticsImpl) computeCommitDiff(gitCtx GitContext, checkoutPath string, oldHash plumbing.Hash, newHash plumbing.Hash, repository *GitRepository) ([]*Commit, error) {
244245
var commitsCli, commitsGoGit []*Commit
245246
var err error
246-
if impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics || impl.configuration.AnalyticsDebug {
247+
useGitCli := impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics
248+
if useGitCli || impl.configuration.AnalyticsDebug {
247249
impl.logger.Infow("Computing commit diff using cli ", "checkoutPath", checkoutPath)
248250
commitsCli, err = impl.gitManager.LogMergeBase(gitCtx, checkoutPath, oldHash.String(), newHash.String())
249251
if err != nil {
250252
impl.logger.Errorw("error in fetching commits for analytics through CLI: ", "err", err)
251253
return nil, err
252254
}
253255
}
254-
if !(impl.configuration.UseGitCli || impl.configuration.UseGitCliAnalytics) || impl.configuration.AnalyticsDebug {
256+
if !useGitCli || impl.configuration.AnalyticsDebug {
255257
impl.logger.Infow("Computing commit diff using go-git ", "checkoutPath", checkoutPath)
256258
ctx, cancel := gitCtx.WithTimeout(impl.configuration.GoGitTimeout)
257259
defer cancel()
@@ -267,7 +269,7 @@ func (impl RepositoryManagerAnalyticsImpl) computeCommitDiff(gitCtx GitContext,
267269
impl.logOldestCommitComparison(commitsGoGit, commitsCli, checkoutPath, oldHash.String(), newHash.String())
268270
}
269271

270-
if !impl.configuration.UseGitCli {
272+
if !useGitCli {
271273
return commitsGoGit, nil
272274
}
273275
return commitsCli, nil

0 commit comments

Comments
 (0)