Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1433702AbdDZORe (ORCPT ); Wed, 26 Apr 2017 10:17:34 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33454 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1433682AbdDZORS (ORCPT ); Wed, 26 Apr 2017 10:17:18 -0400 From: Taeung Song To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim Subject: [PATCH 1/7] perf config: Refactor a duplicated code for config file name Date: Wed, 26 Apr 2017 23:17:13 +0900 Message-Id: <1493216233-9064-1-git-send-email-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1986 Lines: 63 Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Taeung Song --- tools/perf/builtin-config.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c index 55f04f8..80668fa 100644 --- a/tools/perf/builtin-config.c +++ b/tools/perf/builtin-config.c @@ -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,13 +198,9 @@ 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: @@ -221,13 +223,8 @@ int cmd_config(int argc, const char **argv) if (value == NULL) ret = show_spec_config(set, var); - else { - const char *config_filename = config_exclusive_filename; - - if (!config_exclusive_filename) - config_filename = user_config; + else ret = set_config(set, config_filename, var, value); - } free(arg); } } else -- 2.7.4