Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
  • Loading branch information
ffjlabo committed Jan 29, 2024
1 parent a274d89 commit 55a801a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
2 changes: 0 additions & 2 deletions pkg/app/piped/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (p *piped) run(ctx context.Context, input cli.Input) (runErr error) {
gitOptions := []git.Option{
git.WithUserName(cfg.Git.Username),
git.WithEmail(cfg.Git.Email),
git.WithAutoDetach(true),
git.WithLogger(input.Logger),
}
for _, repo := range cfg.GitHelmChartRepositories() {
Expand Down Expand Up @@ -457,7 +456,6 @@ func (p *piped) run(ctx context.Context, input cli.Input) (runErr error) {
gc, err := git.NewClient(
git.WithUserName(cfg.Git.Username),
git.WithEmail(cfg.Git.Email),
git.WithAutoDetach(true),
git.WithLogger(input.Logger),
)
if err != nil {
Expand Down
48 changes: 21 additions & 27 deletions pkg/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ type Client interface {
}

type client struct {
username string
email string
gitPath string
cacheDir string
mu sync.Mutex
repoLocks map[string]*sync.Mutex

gitEnvs []string
gitEnvsByRepo map[string][]string
gitGCAutoDetach bool
logger *zap.Logger
username string
email string
gcAutoDetach bool // whether to be executed `git gc`in the foreground when some git commands (e.g. merge, commit and so on) are executed.
gitPath string
cacheDir string
mu sync.Mutex
repoLocks map[string]*sync.Mutex

gitEnvs []string
gitEnvsByRepo map[string][]string
logger *zap.Logger
}

type Option func(*client)
Expand Down Expand Up @@ -91,12 +91,6 @@ func WithEmail(e string) Option {
}
}

func WithAutoDetach(a bool) Option {
return func(c *client) {
c.gitGCAutoDetach = a
}
}

// NewClient creates a new CLient instance for cloning git repositories.
// After using Clean should be called to delete cache data.
func NewClient(opts ...Option) (Client, error) {
Expand All @@ -111,14 +105,14 @@ func NewClient(opts ...Option) (Client, error) {
}

c := &client{
username: defaultUsername,
email: defaultEmail,
gitPath: gitPath,
cacheDir: cacheDir,
repoLocks: make(map[string]*sync.Mutex),
gitEnvsByRepo: make(map[string][]string, 0),
gitGCAutoDetach: true,
logger: zap.NewNop(),
username: defaultUsername,
email: defaultEmail,
gcAutoDetach: true, // Enable this by default. See issue #4760, discussion #4758.
gitPath: gitPath,
cacheDir: cacheDir,
repoLocks: make(map[string]*sync.Mutex),
gitEnvsByRepo: make(map[string][]string, 0),
logger: zap.NewNop(),
}

for _, opt := range opts {
Expand Down Expand Up @@ -212,8 +206,8 @@ func (c *client) Clone(ctx context.Context, repoID, remote, branch, destination
}
}

logger.Info("setting gc.autoDetach", zap.Bool("gc.autoDetach", c.gitGCAutoDetach), zap.String("r.dir", r.dir))
if err := r.setGCAutoDetach(ctx, c.gitGCAutoDetach); err != nil {
logger.Info("setting gc.autoDetach", zap.Bool("gc.autoDetach", c.gcAutoDetach))
if err := r.setGCAutoDetach(ctx, c.gcAutoDetach); err != nil {
return nil, fmt.Errorf("failed to set auto detach: %v", err)
}

Check warning on line 212 in pkg/git/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/git/client.go#L211-L212

Added lines #L211 - L212 were not covered by tests

Expand Down

0 comments on commit 55a801a

Please sign in to comment.