]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
perf tools: Remove support for command aliases
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 28 Mar 2017 14:19:59 +0000 (11:19 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 28 Mar 2017 14:19:59 +0000 (11:19 -0300)
This came from 'git', but isn't documented anywhere in
tools/perf/Documentation/, looks like baggage we can do without, ditch
it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-e7uwkn60t4hmlnwj99ba4t2s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-help.c
tools/perf/perf.c
tools/perf/util/Build
tools/perf/util/alias.c [deleted file]
tools/perf/util/cache.h
tools/perf/util/help-unknown-cmd.c

index 7ae238929e9545cf779540f9b192d35118bbcba2..1eec96a0fa675350fed9e55e1bbef85bfd266171 100644 (file)
@@ -301,12 +301,6 @@ void list_common_cmds_help(void)
        }
 }
 
-static int is_perf_command(const char *s)
-{
-       return is_in_cmdlist(&main_cmds, s) ||
-               is_in_cmdlist(&other_cmds, s);
-}
-
 static const char *cmd_to_page(const char *perf_cmd)
 {
        char *s;
@@ -446,7 +440,6 @@ int cmd_help(int argc, const char **argv)
                "perf help [--all] [--man|--web|--info] [command]",
                NULL
        };
-       const char *alias;
        int rc;
 
        load_command_list("perf-", &main_cmds, &other_cmds);
@@ -472,12 +465,6 @@ int cmd_help(int argc, const char **argv)
                return 0;
        }
 
-       alias = alias_lookup(argv[0]);
-       if (alias && !is_perf_command(argv[0])) {
-               printf("`perf %s' is aliased to `%s'\n", argv[0], alias);
-               return 0;
-       }
-
        switch (help_format) {
        case HELP_FORMAT_MAN:
                rc = show_man_page(argv[0]);
index 4b283d18e158f3b7f56985d38f9cf65b9b950b14..9217f2227f3d2eb053245d92eddec05b9db2fb83 100644 (file)
@@ -267,71 +267,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
        return handled;
 }
 
-static int handle_alias(int *argcp, const char ***argv)
-{
-       int envchanged = 0, ret = 0, saved_errno = errno;
-       int count, option_count;
-       const char **new_argv;
-       const char *alias_command;
-       char *alias_string;
-
-       alias_command = (*argv)[0];
-       alias_string = alias_lookup(alias_command);
-       if (alias_string) {
-               if (alias_string[0] == '!') {
-                       if (*argcp > 1) {
-                               struct strbuf buf;
-
-                               if (strbuf_init(&buf, PATH_MAX) < 0 ||
-                                   strbuf_addstr(&buf, alias_string) < 0 ||
-                                   sq_quote_argv(&buf, (*argv) + 1,
-                                                 PATH_MAX) < 0)
-                                       die("Failed to allocate memory.");
-                               free(alias_string);
-                               alias_string = buf.buf;
-                       }
-                       ret = system(alias_string + 1);
-                       if (ret >= 0 && WIFEXITED(ret) &&
-                           WEXITSTATUS(ret) != 127)
-                               exit(WEXITSTATUS(ret));
-                       die("Failed to run '%s' when expanding alias '%s'",
-                           alias_string + 1, alias_command);
-               }
-               count = split_cmdline(alias_string, &new_argv);
-               if (count < 0)
-                       die("Bad alias.%s string", alias_command);
-               option_count = handle_options(&new_argv, &count, &envchanged);
-               if (envchanged)
-                       die("alias '%s' changes environment variables\n"
-                                "You can use '!perf' in the alias to do this.",
-                                alias_command);
-               memmove(new_argv - option_count, new_argv,
-                               count * sizeof(char *));
-               new_argv -= option_count;
-
-               if (count < 1)
-                       die("empty alias for %s", alias_command);
-
-               if (!strcmp(alias_command, new_argv[0]))
-                       die("recursive alias: %s", alias_command);
-
-               new_argv = realloc(new_argv, sizeof(char *) *
-                                   (count + *argcp + 1));
-               /* insert after command name */
-               memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
-               new_argv[count + *argcp] = NULL;
-
-               *argv = new_argv;
-               *argcp += count - 1;
-
-               ret = 1;
-       }
-
-       errno = saved_errno;
-
-       return ret;
-}
-
 #define RUN_SETUP      (1<<0)
 #define USE_PAGER      (1<<1)
 
@@ -455,25 +390,12 @@ do_die:
 
 static int run_argv(int *argcp, const char ***argv)
 {
-       int done_alias = 0;
-
-       while (1) {
-               /* See if it's an internal command */
-               handle_internal_command(*argcp, *argv);
-
-               /* .. then try the external ones */
-               execv_dashed_external(*argv);
+       /* See if it's an internal command */
+       handle_internal_command(*argcp, *argv);
 
-               /* It could be an alias -- this works around the insanity
-                * of overriding "perf log" with "perf show" by having
-                * alias.log = show
-                */
-               if (done_alias || !handle_alias(argcp, argv))
-                       break;
-               done_alias = 1;
-       }
-
-       return done_alias;
+       /* .. then try the external ones */
+       execv_dashed_external(*argv);
+       return 0;
 }
 
 static void pthread__block_sigwinch(void)
@@ -606,17 +528,12 @@ int main(int argc, const char **argv)
 
        while (1) {
                static int done_help;
-               int was_alias = run_argv(&argc, &argv);
+
+               run_argv(&argc, &argv);
 
                if (errno != ENOENT)
                        break;
 
-               if (was_alias) {
-                       fprintf(stderr, "Expansion of alias '%s' failed; "
-                               "'%s' is not a perf-command\n",
-                               cmd, argv[0]);
-                       goto out;
-               }
                if (!done_help) {
                        cmd = argv[0] = help_unknown_cmd(cmd);
                        done_help = 1;
index 2ae92da613dd61ad1d6302c7ff4b1ccdc033e6df..5c0ea11a8f0a12af168b20bfce589661370173cd 100644 (file)
@@ -1,4 +1,3 @@
-libperf-y += alias.o
 libperf-y += annotate.o
 libperf-y += block-range.o
 libperf-y += build-id.o
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c
deleted file mode 100644 (file)
index 6455471..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "cache.h"
-#include "util.h"
-#include "config.h"
-
-static const char *alias_key;
-static char *alias_val;
-
-static int alias_lookup_cb(const char *k, const char *v,
-                          void *cb __maybe_unused)
-{
-       if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
-               if (!v)
-                       return config_error_nonbool(k);
-               alias_val = strdup(v);
-               return 0;
-       }
-       return 0;
-}
-
-char *alias_lookup(const char *alias)
-{
-       alias_key = alias;
-       alias_val = NULL;
-       perf_config(alias_lookup_cb, NULL);
-       return alias_val;
-}
-
-int split_cmdline(char *cmdline, const char ***argv)
-{
-       int src, dst, count = 0, size = 16;
-       char quoted = 0;
-
-       *argv = malloc(sizeof(char*) * size);
-
-       /* split alias_string */
-       (*argv)[count++] = cmdline;
-       for (src = dst = 0; cmdline[src];) {
-               char c = cmdline[src];
-               if (!quoted && isspace(c)) {
-                       cmdline[dst++] = 0;
-                       while (cmdline[++src]
-                                       && isspace(cmdline[src]))
-                               ; /* skip */
-                       if (count >= size) {
-                               size += 16;
-                               *argv = realloc(*argv, sizeof(char*) * size);
-                       }
-                       (*argv)[count++] = cmdline + dst;
-               } else if (!quoted && (c == '\'' || c == '"')) {
-                       quoted = c;
-                       src++;
-               } else if (c == quoted) {
-                       quoted = 0;
-                       src++;
-               } else {
-                       if (c == '\\' && quoted != '\'') {
-                               src++;
-                               c = cmdline[src];
-                               if (!c) {
-                                       zfree(argv);
-                                       return error("cmdline ends with \\");
-                               }
-                       }
-                       cmdline[dst++] = c;
-                       src++;
-               }
-       }
-
-       cmdline[dst] = 0;
-
-       if (quoted) {
-               zfree(argv);
-               return error("unclosed quote");
-       }
-
-       return count;
-}
-
index 512c0c83fbc6a9a9ed2a9c996de74ff6fb45eb62..0328f297a748380d7e128e69b204e42001c3e8c1 100644 (file)
@@ -15,7 +15,6 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
-char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
 
 #define alloc_nr(x) (((x)+16)*3/2)
index 2821f8d77e5208116cbd5832f9b9833d0764221e..34201440ac03dca697c0c28eeced7344ac747f5d 100644 (file)
@@ -6,16 +6,12 @@
 #include "levenshtein.h"
 
 static int autocorrect;
-static struct cmdnames aliases;
 
 static int perf_unknown_cmd_config(const char *var, const char *value,
                                   void *cb __maybe_unused)
 {
        if (!strcmp(var, "help.autocorrect"))
                autocorrect = perf_config_int(var,value);
-       /* Also use aliases for command lookup */
-       if (!prefixcmp(var, "alias."))
-               add_cmdname(&aliases, var + 6, strlen(var + 6));
 
        return 0;
 }
@@ -59,14 +55,12 @@ const char *help_unknown_cmd(const char *cmd)
 
        memset(&main_cmds, 0, sizeof(main_cmds));
        memset(&other_cmds, 0, sizeof(main_cmds));
-       memset(&aliases, 0, sizeof(aliases));
 
        perf_config(perf_unknown_cmd_config, NULL);
 
        load_command_list("perf-", &main_cmds, &other_cmds);
 
-       if (add_cmd_list(&main_cmds, &aliases) < 0 ||
-           add_cmd_list(&main_cmds, &other_cmds) < 0) {
+       if (add_cmd_list(&main_cmds, &other_cmds) < 0) {
                fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n");
                goto end;
        }