From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754164AbdECRlI (ORCPT ); Wed, 3 May 2017 13:41:08 -0400 Received: from terminus.zytor.com ([65.50.211.136]:41809 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752950AbdECRlB (ORCPT ); Wed, 3 May 2017 13:41:01 -0400 Date: Wed, 3 May 2017 10:38:51 -0700 From: tip-bot for Taeung Song Message-ID: Cc: linux-kernel@vger.kernel.org, namhyung@kernel.org, hpa@zytor.com, treeze.taeung@gmail.com, mingo@kernel.org, acme@redhat.com, tglx@linutronix.de, jolsa@kernel.org Reply-To: linux-kernel@vger.kernel.org, namhyung@kernel.org, mingo@kernel.org, treeze.taeung@gmail.com, acme@redhat.com, hpa@zytor.com, jolsa@kernel.org, tglx@linutronix.de In-Reply-To: <1493209268-5543-2-git-send-email-treeze.taeung@gmail.com> References: <1493209268-5543-2-git-send-email-treeze.taeung@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf config: Refactor a duplicated code for obtaining config file name Git-Commit-ID: 4341ec6b3db4c3e903d6c44958722918baec1e59 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 4341ec6b3db4c3e903d6c44958722918baec1e59 Gitweb: http://git.kernel.org/tip/4341ec6b3db4c3e903d6c44958722918baec1e59 Author: Taeung Song AuthorDate: Wed, 26 Apr 2017 21:21:02 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 2 May 2017 18:23:12 -0300 perf config: Refactor a duplicated code for obtaining config file name We were doing the same sequence to figure out what is the config pathname to use, fix it by doing it before those two uses. Signed-off-by: Taeung Song Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lkml.kernel.org/r/1493209268-5543-2-git-send-email-treeze.taeung@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- 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