{"thread":{"id":"12304","subject":"[PATCH 1/3] help: use parseopt","startedAt":"2008-02-24T22:16:55Z","lastAt":"2008-02-26T20:31:11Z","messageCount":12,"participants":["Jeff King","Jay Soffian","Christian Couder","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"69825","messageId":"20080224221655.GB31309@coredump.intra.peff.net","threadId":"12304","inReplyTo":"cover.1203890846.git.peff@peff.net","subject":"[PATCH 1/3] help: use parseopt","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-24T22:16:55Z","receivedAt":"2008-02-24T22:16:55Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This patch converts cmd_help to use parseopt, along with a\nfew style cleanups, including:\n\n  - enum constants are now ALL_CAPS\n\n  - parse_help_format returns an enum value rather than\n    setting a global as a side effect\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nSorry, the diff turned out quite messy because of the cleanups. It's\nprobably easier to just read the result.\n\n help.c |  123 ++++++++++++++++++++++++++++++---------------------------------\n 1 files changed, 59 insertions(+), 64 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 8143dcd..5feb849 100644\n--- a/help.c\n+++ b/help.c\n@@ -7,40 +7,49 @@\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n #include \"common-cmds.h\"\n-\n-static const char *help_default_format;\n-\n-static enum help_format {\n-\tman_format,\n-\tinfo_format,\n-\tweb_format,\n-} help_format = man_format;\n-\n-static void parse_help_format(const char *format)\n+#include \"parse-options.h\"\n+\n+enum help_format {\n+\tHELP_FORMAT_MAN,\n+\tHELP_FORMAT_INFO,\n+\tHELP_FORMAT_WEB,\n+};\n+\n+static int show_all = 0;\n+static enum help_format help_format = HELP_FORMAT_MAN;\n+static struct option builtin_help_options[] = {\n+\tOPT_BOOLEAN('a', \"all\", &show_all, \"print all available commands\"),\n+\tOPT_SET_INT('m', \"man\", &help_format, \"show man page\", HELP_FORMAT_MAN),\n+\tOPT_SET_INT('w', \"web\", &help_format, \"show manual in web browser\",\n+\t\t\tHELP_FORMAT_WEB),\n+\tOPT_SET_INT('i', \"info\", &help_format, \"show info page\",\n+\t\t\tHELP_FORMAT_INFO),\n+};\n+\n+static const char * const builtin_help_usage[] = {\n+\t\"git-help [--all] [--man|--web|--info] [command]\",\n+\tNULL\n+};\n+\n+static enum help_format parse_help_format(const char *format)\n {\n-\tif (!format) {\n-\t\thelp_format = man_format;\n-\t\treturn;\n-\t}\n-\tif (!strcmp(format, \"man\")) {\n-\t\thelp_format = man_format;\n-\t\treturn;\n-\t}\n-\tif (!strcmp(format, \"info\")) {\n-\t\thelp_format = info_format;\n-\t\treturn;\n-\t}\n-\tif (!strcmp(format, \"web\") || !strcmp(format, \"html\")) {\n-\t\thelp_format = web_format;\n-\t\treturn;\n-\t}\n+\tif (!strcmp(format, \"man\"))\n+\t\treturn HELP_FORMAT_MAN;\n+\tif (!strcmp(format, \"info\"))\n+\t\treturn HELP_FORMAT_INFO;\n+\tif (!strcmp(format, \"web\") || !strcmp(format, \"html\"))\n+\t\treturn HELP_FORMAT_WEB;\n \tdie(\"unrecognized help format '%s'\", format);\n }\n \n static int git_help_config(const char *var, const char *value)\n {\n-\tif (!strcmp(var, \"help.format\"))\n-\t\treturn git_config_string(&help_default_format, var, value);\n+\tif (!strcmp(var, \"help.format\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\thelp_format = parse_help_format(value);\n+\t\treturn 0;\n+\t}\n \treturn git_default_config(var, value);\n }\n \n@@ -362,50 +371,36 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n \n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n-\tconst char *help_cmd = argv[1];\n+\tint nongit;\n \n-\tif (argc < 2) {\n-\t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n-\t\tlist_common_cmds_help();\n-\t\texit(0);\n-\t}\n+\tsetup_git_directory_gently(&nongit);\n+\tgit_config(git_help_config);\n \n-\tif (!strcmp(help_cmd, \"--all\") || !strcmp(help_cmd, \"-a\")) {\n+\targc = parse_options(argc, argv, builtin_help_options,\n+\t\t\tbuiltin_help_usage, 0);\n+\n+\tif (show_all) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n \t\tlist_commands();\n+\t\treturn 0;\n \t}\n \n-\telse if (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n-\t\tshow_html_page(argc > 2 ? argv[2] : NULL);\n-\t}\n-\n-\telse if (!strcmp(help_cmd, \"--info\") || !strcmp(help_cmd, \"-i\")) {\n-\t\tshow_info_page(argc > 2 ? argv[2] : NULL);\n-\t}\n-\n-\telse if (!strcmp(help_cmd, \"--man\") || !strcmp(help_cmd, \"-m\")) {\n-\t\tshow_man_page(argc > 2 ? argv[2] : NULL);\n+\tif (!argv[0]) {\n+\t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n+\t\tlist_common_cmds_help();\n+\t\treturn 0;\n \t}\n \n-\telse {\n-\t\tint nongit;\n-\n-\t\tsetup_git_directory_gently(&nongit);\n-\t\tgit_config(git_help_config);\n-\t\tif (help_default_format)\n-\t\t\tparse_help_format(help_default_format);\n-\n-\t\tswitch (help_format) {\n-\t\tcase man_format:\n-\t\t\tshow_man_page(help_cmd);\n-\t\t\tbreak;\n-\t\tcase info_format:\n-\t\t\tshow_info_page(help_cmd);\n-\t\t\tbreak;\n-\t\tcase web_format:\n-\t\t\tshow_html_page(help_cmd);\n-\t\t\tbreak;\n-\t\t}\n+\tswitch (help_format) {\n+\tcase HELP_FORMAT_MAN:\n+\t\tshow_man_page(argv[0]);\n+\t\tbreak;\n+\tcase HELP_FORMAT_INFO:\n+\t\tshow_info_page(argv[0]);\n+\t\tbreak;\n+\tcase HELP_FORMAT_WEB:\n+\t\tshow_html_page(argv[0]);\n+\t\tbreak;\n \t}\n \n \treturn 0;\n-- \n1.5.4.3.305.g073a4\n"},{"id":"69826","messageId":"20080224221714.GC31309@coredump.intra.peff.net","threadId":"12304","inReplyTo":"cover.1203890846.git.peff@peff.net","subject":"[PATCH 2/3] make alias lookup a public, procedural function","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-24T22:17:14Z","receivedAt":"2008-02-24T22:17:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This converts git_config_alias to the public alias_lookup\nfunction. Because of the nature of our config parser, we\nstill have to rely on setting static data. However, that\ninterface is wrapped so that you can just say\n\n  value = alias_lookup(key);\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Makefile |    3 ++-\n alias.c  |   22 ++++++++++++++++++++++\n cache.h  |    2 ++\n git.c    |   17 +++--------------\n 4 files changed, 29 insertions(+), 15 deletions(-)\n create mode 100644 alias.c\n\ndiff --git a/Makefile b/Makefile\nindex d33a556..b460bb2 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -327,7 +327,8 @@ LIB_OBJS = \\\n \talloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \\\n \tcolor.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \\\n \tconvert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \\\n-\ttransport.o bundle.o walker.o parse-options.o ws.o archive.o\n+\ttransport.o bundle.o walker.o parse-options.o ws.o archive.o \\\n+\talias.o\n \n BUILTIN_OBJS = \\\n \tbuiltin-add.o \\\ndiff --git a/alias.c b/alias.c\nnew file mode 100644\nindex 0000000..116cac8\n--- /dev/null\n+++ b/alias.c\n@@ -0,0 +1,22 @@\n+#include \"cache.h\"\n+\n+static const char *alias_key;\n+static char *alias_val;\n+static int alias_lookup_cb(const char *k, const char *v)\n+{\n+\tif (!prefixcmp(k, \"alias.\") && !strcmp(k+6, alias_key)) {\n+\t\tif (!v)\n+\t\t\treturn config_error_nonbool(k);\n+\t\talias_val = xstrdup(v);\n+\t\treturn 0;\n+\t}\n+\treturn 0;\n+}\n+\n+char *alias_lookup(const char *alias)\n+{\n+\talias_key = alias;\n+\talias_val = NULL;\n+\tgit_config(alias_lookup_cb);\n+\treturn alias_val;\n+}\ndiff --git a/cache.h b/cache.h\nindex fa5a9e5..1e9c937 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -765,4 +765,6 @@ int pathspec_match(const char **spec, char *matched, const char *filename, int s\n int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);\n void overlay_tree_on_cache(const char *tree_name, const char *prefix);\n \n+char *alias_lookup(const char *alias);\n+\n #endif /* CACHE_H */\ndiff --git a/git.c b/git.c\nindex 0cb8688..8f08b12 100644\n--- a/git.c\n+++ b/git.c\n@@ -87,19 +87,6 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)\n \treturn handled;\n }\n \n-static const char *alias_command;\n-static char *alias_string;\n-\n-static int git_alias_config(const char *var, const char *value)\n-{\n-\tif (!prefixcmp(var, \"alias.\") && !strcmp(var + 6, alias_command)) {\n-\t\tif (!value)\n-\t\t\treturn config_error_nonbool(var);\n-\t\talias_string = xstrdup(value);\n-\t}\n-\treturn 0;\n-}\n-\n static int split_cmdline(char *cmdline, const char ***argv)\n {\n \tint src, dst, count = 0, size = 16;\n@@ -159,11 +146,13 @@ static int handle_alias(int *argcp, const char ***argv)\n \tconst char *subdir;\n \tint count, option_count;\n \tconst char** new_argv;\n+\tconst char *alias_command;\n+\tchar *alias_string;\n \n \tsubdir = setup_git_directory_gently(&nongit);\n \n \talias_command = (*argv)[0];\n-\tgit_config(git_alias_config);\n+\talias_string = alias_lookup(alias_command);\n \tif (alias_string) {\n \t\tif (alias_string[0] == '!') {\n \t\t\tif (*argcp > 1) {\n-- \n1.5.4.3.305.g073a4\n"},{"id":"69827","messageId":"20080224221737.GD31309@coredump.intra.peff.net","threadId":"12304","inReplyTo":"cover.1203890846.git.peff@peff.net","subject":"[PATCH 3/3] help: respect aliases","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-24T22:17:37Z","receivedAt":"2008-02-24T22:17:37Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"If we have an alias \"foo\" defined, then the help text for\n\"foo\" (via \"git help foo\" or \"git foo --help\") now shows the\ndefinition of the alias.\n\nBefore showing an alias definition, we make sure that there\nis no git command which would override the alias (so that\neven though you may have a \"log\" alias, even though it will\nnot work, we don't want to it supersede \"git help log\").\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n help.c |   33 ++++++++++++++++++++++++++++++++-\n 1 files changed, 32 insertions(+), 1 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 5feb849..e57a50e 100644\n--- a/help.c\n+++ b/help.c\n@@ -210,7 +210,7 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,\n \treturn longest;\n }\n \n-static void list_commands(void)\n+static unsigned int load_command_list(void)\n {\n \tunsigned int longest = 0;\n \tunsigned int len;\n@@ -250,6 +250,14 @@ static void list_commands(void)\n \tuniq(&other_cmds);\n \texclude_cmds(&other_cmds, &main_cmds);\n \n+\treturn longest;\n+}\n+\n+static void list_commands(void)\n+{\n+\tunsigned int longest = load_command_list();\n+\tconst char *exec_path = git_exec_path();\n+\n \tif (main_cmds.cnt) {\n \t\tprintf(\"available git commands in '%s'\\n\", exec_path);\n \t\tprintf(\"----------------------------\");\n@@ -284,6 +292,22 @@ void list_common_cmds_help(void)\n \t}\n }\n \n+static int is_in_cmdlist(struct cmdnames *c, const char *s)\n+{\n+\tint i;\n+\tfor (i = 0; i < c->cnt; i++)\n+\t\tif (!strcmp(s, c->names[i]->name))\n+\t\t\treturn 1;\n+\treturn 0;\n+}\n+\n+static int is_git_command(const char *s)\n+{\n+\tload_command_list();\n+\treturn is_in_cmdlist(&main_cmds, s) ||\n+\t\tis_in_cmdlist(&other_cmds, s);\n+}\n+\n static const char *cmd_to_page(const char *git_cmd)\n {\n \tif (!git_cmd)\n@@ -372,6 +396,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n \tint nongit;\n+\tconst char *alias;\n \n \tsetup_git_directory_gently(&nongit);\n \tgit_config(git_help_config);\n@@ -391,6 +416,12 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\treturn 0;\n \t}\n \n+\talias = alias_lookup(argv[0]);\n+\tif (alias && !is_git_command(argv[0])) {\n+\t\tprintf(\"`git %s' is aliased to `%s'\\n\", argv[0], alias);\n+\t\treturn 0;\n+\t}\n+\n \tswitch (help_format) {\n \tcase HELP_FORMAT_MAN:\n \t\tshow_man_page(argv[0]);\n-- \n1.5.4.3.305.g073a4\n"},{"id":"69839","messageId":"76718490802241810m5f473156nc350eea07016e8f9@mail.gmail.com","threadId":"12304","inReplyTo":"20080224221737.GD31309@coredump.intra.peff.net","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-25T02:10:00Z","receivedAt":"2008-02-25T02:10:00Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Sun, Feb 24, 2008 at 5:17 PM, Jeff King <peff@peff.net> wrote:\n> If we have an alias \"foo\" defined, then the help text for\n>  \"foo\" (via \"git help foo\" or \"git foo --help\") now shows the\n>  definition of the alias.\n\nHeh, now I can kill this alias of mine:\n\n    h          = \"!sh -c 'git alias \\\"$1\\\" || git help \\\"$1\\\"' -\"\n\n:-)\n\nThis too would be less ugly as a built-in:\n\n    alias      = \"! sh -c 'if test -z \\\"$1\\\"; then git config --list \\\n                  | expand \\\n                  | sed \\\"/^alias\\\\./!d; s/^alias\\\\.//; s/=/ /; s/  */ /g\\\" \\\n                  | sort | while read n v; do \\\n                  printf \\\"%-16s\\\" \\\"$n\\\"; echo \\\"$v\\\" | gnused \\\n                  \\\"s/\\\\(.\\\\{68\\\\}\\\\) /\\\\1\\\\n\\t\\t/g\\\" | expand; \\\n                  done; else git config \\\"alias.$1\\\"; fi' -\"\n:-)\n\nj.\n"},{"id":"69852","messageId":"200802250750.53047.chriscool@tuxfamily.org","threadId":"12304","inReplyTo":"20080224221655.GB31309@coredump.intra.peff.net","subject":"Re: [PATCH 1/3] help: use parseopt","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-02-25T06:50:52Z","receivedAt":"2008-02-25T06:50:52Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le dimanche 24 février 2008, Jeff King a écrit :\n> This patch converts cmd_help to use parseopt, along with a\n> few style cleanups, including:\n>\n>   - enum constants are now ALL_CAPS\n\nOk.\n\n>   - parse_help_format returns an enum value rather than\n>     setting a global as a side effect\n\nNice cleanup.\n\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> Sorry, the diff turned out quite messy because of the cleanups. It's\n> probably easier to just read the result.\n\nOr could you send the cleanups in some separated patches ?\n\nThanks in advance,\nChristian.\n"},{"id":"69853","messageId":"20080225065710.GA3765@coredump.intra.peff.net","threadId":"12304","inReplyTo":"200802250750.53047.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/3] help: use parseopt","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-25T06:57:10Z","receivedAt":"2008-02-25T06:57:10Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 25, 2008 at 07:50:52AM +0100, Christian Couder wrote:\n\n> > Sorry, the diff turned out quite messy because of the cleanups. It's\n> > probably easier to just read the result.\n> \n> Or could you send the cleanups in some separated patches ?\n\nLooking at it again, it's actually not too bad except for the cmd_help()\nfunction itself, which isn't due to the cleanups at all, but because the\nflow changes quite a bit. So I don't think splitting it actually will\nmake the diff any friendlier.\n\n-Peff\n"},{"id":"69855","messageId":"7vbq65o69d.fsf@gitster.siamese.dyndns.org","threadId":"12304","inReplyTo":"20080225065710.GA3765@coredump.intra.peff.net","subject":"Re: [PATCH 1/3] help: use parseopt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-25T07:16:30Z","receivedAt":"2008-02-25T07:16:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Mon, Feb 25, 2008 at 07:50:52AM +0100, Christian Couder wrote:\n>\n>> > Sorry, the diff turned out quite messy because of the cleanups. It's\n>> > probably easier to just read the result.\n>> \n>> Or could you send the cleanups in some separated patches ?\n>\n> Looking at it again, it's actually not too bad except for the cmd_help()\n> function itself, which isn't due to the cleanups at all, but because the\n> flow changes quite a bit. So I don't think splitting it actually will\n> make the diff any friendlier.\n\nYour patch is fine as-is.\n"},{"id":"69988","messageId":"alpine.LSU.1.00.0802261222570.17164@racer.site","threadId":"12304","inReplyTo":"76718490802241810m5f473156nc350eea07016e8f9@mail.gmail.com","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-26T12:43:21Z","receivedAt":"2008-02-26T12:43:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 24 Feb 2008, Jay Soffian wrote:\n\n> This too would be less ugly as a built-in:\n> \n>     alias      = \"! sh -c 'if test -z \\\"$1\\\"; then git config --list \\\n>                   | expand \\\n>                   | sed \\\"/^alias\\\\./!d; s/^alias\\\\.//; s/=/ /; s/  */ /g\\\" \\\n>                   | sort | while read n v; do \\\n>                   printf \\\"%-16s\\\" \\\"$n\\\"; echo \\\"$v\\\" | gnused \\\n>                   \\\"s/\\\\(.\\\\{68\\\\}\\\\) /\\\\1\\\\n\\t\\t/g\\\" | expand; \\\n>                   done; else git config \\\"alias.$1\\\"; fi' -\"\n\nWow.  This would look less ugly as an alias like this, too:\n\nalias = \"!sh -c 'case $# in \\\n        0) git config --get-regexp \\\"^alias\\\\.\\\" | sed \\\"s/^alias\\\\.//\\\";; \\\n        *) git config \\\"alias.$0\\\" ;; \\\n        esac'\"\n\nwhich incidentally fixes a bug in your alias: you ignore $0 which is the \nfirst parameter when using the sh -c '' idiom.\n\nOf course, you can change the sed call to your liking...\n\nCiao,\nDscho\n"},{"id":"69998","messageId":"76718490802260656s459e9241ie2a2d6b255c77fa4@mail.gmail.com","threadId":"12304","inReplyTo":"alpine.LSU.1.00.0802261222570.17164@racer.site","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-26T14:56:13Z","receivedAt":"2008-02-26T14:56:13Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Feb 26, 2008 at 7:43 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n>  On Sun, 24 Feb 2008, Jay Soffian wrote:\n>\n>  > This too would be less ugly as a built-in:\n>  >\n>  >  [elided so as not to burn anyone's eyes out again :-) -- jay]\n>\n>  Wow.  This would look less ugly as an alias like this, too:\n>\n>  alias = \"!sh -c 'case $# in \\\n>         0) git config --get-regexp \\\"^alias\\\\.\\\" | sed \\\"s/^alias\\\\.//\\\";; \\\n>         *) git config \\\"alias.$0\\\" ;; \\\n>         esac'\"\n>\n>  which incidentally fixes a bug in your alias: you ignore $0 which is the\n>  first parameter when using the sh -c '' idiom.\n\nTest mine. Test yours. See which works. :-)\n\nAt least on my system, I had to use:\n\n  sh -c '...' -\n\nAnd then refer to $1.\n\n>  Of course, you can change the sed call to your liking...\n\nMost of the ugliness in mine is that I crammed the whitespace down and\nthat I'm using a quite involved pipeline to reformat all my aliases so\nthey fit into my terminal window.\n\nBut the --get-regexp is a good tip.\n\nj.\n"},{"id":"70000","messageId":"alpine.LSU.1.00.0802261515210.22527@racer.site","threadId":"12304","inReplyTo":"76718490802260656s459e9241ie2a2d6b255c77fa4@mail.gmail.com","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-26T15:15:35Z","receivedAt":"2008-02-26T15:15:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 26 Feb 2008, Jay Soffian wrote:\n\n> On Tue, Feb 26, 2008 at 7:43 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> >  On Sun, 24 Feb 2008, Jay Soffian wrote:\n> >\n> >  > This too would be less ugly as a built-in:\n> >  >\n> >  >  [elided so as not to burn anyone's eyes out again :-) -- jay]\n> >\n> >  Wow.  This would look less ugly as an alias like this, too:\n> >\n> >  alias = \"!sh -c 'case $# in \\\n> >         0) git config --get-regexp \\\"^alias\\\\.\\\" | sed \\\"s/^alias\\\\.//\\\";; \\\n> >         *) git config \\\"alias.$0\\\" ;; \\\n> >         esac'\"\n> >\n> >  which incidentally fixes a bug in your alias: you ignore $0 which is the\n> >  first parameter when using the sh -c '' idiom.\n> \n> Test mine. Test yours. See which works. :-)\n\nI tested only mine.  It works.\n\nCiao,\nDscho\n"},{"id":"70022","messageId":"7vve4b4gqu.fsf@gitster.siamese.dyndns.org","threadId":"12304","inReplyTo":"alpine.LSU.1.00.0802261222570.17164@racer.site","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-26T20:14:49Z","receivedAt":"2008-02-26T20:14:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Hi,\n>\n> On Sun, 24 Feb 2008, Jay Soffian wrote:\n>\n>> This too would be less ugly as a built-in:\n>> \n>>     alias      = \"! sh -c 'if test -z \\\"$1\\\"; then git config --list \\\n>>                   | expand \\\n>>                   | sed \\\"/^alias\\\\./!d; s/^alias\\\\.//; s/=/ /; s/  */ /g\\\" \\\n>>                   | sort | while read n v; do \\\n>>                   printf \\\"%-16s\\\" \\\"$n\\\"; echo \\\"$v\\\" | gnused \\\n>>                   \\\"s/\\\\(.\\\\{68\\\\}\\\\) /\\\\1\\\\n\\t\\t/g\\\" | expand; \\\n>>                   done; else git config \\\"alias.$1\\\"; fi' -\"\n>\n> Wow.  This would look less ugly as an alias like this, too:\n>\n> alias = \"!sh -c 'case $# in \\\n>         0) git config --get-regexp \\\"^alias\\\\.\\\" | sed \\\"s/^alias\\\\.//\\\";; \\\n>         *) git config \\\"alias.$0\\\" ;; \\\n>         esac'\"\n>\n> which incidentally fixes a bug in your alias: you ignore $0 which is the \n> first parameter when using the sh -c '' idiom.\n\nI notice that he is feeding an exra '-' for that.\n\n> Of course, you can change the sed call to your liking...\n\nSure.  The combination of expand, sed, and gnused hurts my eyes\n;-)\n\nOne good lesson to take home is that by ending your lines with\n'|', you can tell the shell that you are not done with the\npipeline you are forming yet.  This allows you to lose all these\nugly backslashes, like this:\n\n\txyzzy |\n        frotz |\n        nitfol\n\ninstead of\n\n\txyzzy \\\n        | frotz \\\n        | nitfol\n"},{"id":"70025","messageId":"76718490802261231j61e66f91r473401e42816cceb@mail.gmail.com","threadId":"12304","inReplyTo":"7vve4b4gqu.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 3/3] help: respect aliases","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-26T20:31:11Z","receivedAt":"2008-02-26T20:31:11Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Feb 26, 2008 at 3:14 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n>  Sure.  The combination of expand, sed, and gnused hurts my eyes\n>  ;-)\n>\n>  One good lesson to take home is that by ending your lines with\n>  '|', you can tell the shell that you are not done with the\n>  pipeline you are forming yet.\n\nThe backslashes aren't there for the shell, they are there for the git\nconfig parser. Anyway, I reworked it a bit:\n\nalias = \"! sh -c 'case $# in \\\n               0) git config --get-regexp \\\"^alias\\\\.\\\" \\\n                  | sort | sed \\\"s/^alias\\\\.//; s/=/ /\\\" \\\n                  | while read n v; do \\\n                     printf \\\"%-16s\\\" \\\"$n\\\"; \\\n                     echo \\\"$v\\\" | fmt -sw 63 | sed \\\"2,$ s/^/\\t\\t/\\\" ;\\\n                  done ;; \\\n               1) git config \\\"alias.$1\\\" | fmt -sw 78 ;; esac' -\"\n\nAnd yes, it's still ugly.\n\nAlways happy to have folks help me bikeshed my git config. :-)\n\nj.\n"}]}