perf config: Invert an if statement to reduce nesting in cmd_config()
[linux-2.6-microblaze.git] / tools / perf / builtin-config.c
index 55f04f8..7545966 100644 (file)
@@ -159,6 +159,7 @@ int cmd_config(int argc, const char **argv)
        int i, ret = 0;
        struct perf_config_set *set;
        char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
+       const char *config_filename;
 
        argc = parse_options(argc, argv, config_options, config_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
@@ -175,6 +176,11 @@ int cmd_config(int argc, const char **argv)
        else if (use_user_config)
                config_exclusive_filename = user_config;
 
+       if (!config_exclusive_filename)
+               config_filename = user_config;
+       else
+               config_filename = config_exclusive_filename;
+
        /*
         * At only 'config' sub-command, individually use the config set
         * because of reinitializing with options config file location.
@@ -192,46 +198,39 @@ int cmd_config(int argc, const char **argv)
                        parse_options_usage(config_usage, config_options, "l", 1);
                } else {
                        ret = show_config(set);
-                       if (ret < 0) {
-                               const char * config_filename = config_exclusive_filename;
-                               if (!config_exclusive_filename)
-                                       config_filename = user_config;
+                       if (ret < 0)
                                pr_err("Nothing configured, "
                                       "please check your %s \n", config_filename);
-                       }
                }
                break;
        default:
-               if (argc) {
-                       for (i = 0; argv[i]; i++) {
-                               char *var, *value;
-                               char *arg = strdup(argv[i]);
-
-                               if (!arg) {
-                                       pr_err("%s: strdup failed\n", __func__);
-                                       ret = -1;
-                                       break;
-                               }
+               if (!argc) {
+                       usage_with_options(config_usage, config_options);
+                       break;
+               }
 
-                               if (parse_config_arg(arg, &var, &value) < 0) {
-                                       free(arg);
-                                       ret = -1;
-                                       break;
-                               }
+               for (i = 0; argv[i]; i++) {
+                       char *var, *value;
+                       char *arg = strdup(argv[i]);
 
-                               if (value == NULL)
-                                       ret = show_spec_config(set, var);
-                               else {
-                                       const char *config_filename = config_exclusive_filename;
+                       if (!arg) {
+                               pr_err("%s: strdup failed\n", __func__);
+                               ret = -1;
+                               break;
+                       }
 
-                                       if (!config_exclusive_filename)
-                                               config_filename = user_config;
-                                       ret = set_config(set, config_filename, var, value);
-                               }
+                       if (parse_config_arg(arg, &var, &value) < 0) {
                                free(arg);
+                               ret = -1;
+                               break;
                        }
-               } else
-                       usage_with_options(config_usage, config_options);
+
+                       if (value == NULL)
+                               ret = show_spec_config(set, var);
+                       else
+                               ret = set_config(set, config_filename, var, value);
+                       free(arg);
+               }
        }
 
        perf_config_set__delete(set);