Skip to content

Commit a9e5309

Browse files
authored
Merge pull request #5893 from thaJeztah/hooks_optim
small performance optimizations for running hooks
2 parents a89a15a + 6d551e0 commit a9e5309

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cli/command/cli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ func (cli *DockerCli) BuildKitEnabled() (bool, error) {
194194

195195
// HooksEnabled returns whether plugin hooks are enabled.
196196
func (cli *DockerCli) HooksEnabled() bool {
197-
// legacy support DOCKER_CLI_HINTS env var
198-
if v := os.Getenv("DOCKER_CLI_HINTS"); v != "" {
197+
// use DOCKER_CLI_HOOKS env var value if set and not empty
198+
if v := os.Getenv("DOCKER_CLI_HOOKS"); v != "" {
199199
enabled, err := strconv.ParseBool(v)
200200
if err != nil {
201201
return false
202202
}
203203
return enabled
204204
}
205-
// use DOCKER_CLI_HOOKS env var value if set and not empty
206-
if v := os.Getenv("DOCKER_CLI_HOOKS"); v != "" {
205+
// legacy support DOCKER_CLI_HINTS env var
206+
if v := os.Getenv("DOCKER_CLI_HINTS"); v != "" {
207207
enabled, err := strconv.ParseBool(v)
208208
if err != nil {
209209
return false

cmd/docker/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
446446
if err != nil || pluginmanager.IsPluginCommand(ccmd) {
447447
err := tryPluginRun(ctx, dockerCli, cmd, args[0], envs)
448448
if err == nil {
449-
if dockerCli.HooksEnabled() && dockerCli.Out().IsTerminal() && ccmd != nil {
449+
if ccmd != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() {
450450
pluginmanager.RunPluginHooks(ctx, dockerCli, cmd, ccmd, args)
451451
}
452452
return nil
@@ -471,7 +471,7 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
471471

472472
// If the command is being executed in an interactive terminal
473473
// and hook are enabled, run the plugin hooks.
474-
if dockerCli.HooksEnabled() && dockerCli.Out().IsTerminal() && subCommand != nil {
474+
if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() {
475475
var errMessage string
476476
if err != nil {
477477
errMessage = err.Error()

0 commit comments

Comments
 (0)