{"thread":{"id":"40163","subject":"[PATCH v2] generate-cmdlist: re-implement as shell script","startedAt":"2015-08-23T21:31:09Z","lastAt":"2015-08-23T21:31:09Z","messageCount":1,"participants":["Eric Sunshine"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"268547","messageId":"1440365469-9928-1-git-send-email-sunshine@sunshineco.com","threadId":"40163","inReplyTo":null,"subject":"[PATCH v2] generate-cmdlist: re-implement as shell script","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-08-23T21:31:09Z","receivedAt":"2015-08-23T21:31:09Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"527ec39 (generate-cmdlist: parse common group commands, 2015-05-21)\nreplaced generate-cmdlist.sh with a more functional Perl version,\ngenerate-cmdlist.perl. The Perl version gleans named tags from a new\n\"common groups\" section in command-list.txt and recognizes those tags in\n\"command list\" section entries in place of the old 'common' tag. This\nallows git-help to, not only recognize, but also group common commands.\n\nAlthough the tests require Perl, 527ec39 creates an unconditional\ndependence upon Perl in the build system itself, which can not be\noverridden with NO_PERL. Such a dependency may be undesirable; for\ninstance, the 'git-lite' package in the FreeBSD ports tree is intended\nas a minimal Git installation (which may, for example, be useful on\nservers needing only local clone and update capability), which,\nhistorically, has not depended upon Perl[1].\n\nTherefore, revive generate-cmdlist.sh and extend it to recognize \"common\ngroups\" and its named tags. Retire generate-cmdlist.perl.\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/275905/focus=276132\n\nSigned-off-by: Eric Sunshine <sunshine@sunshineco.com>\n---\n\nChanges since v1 [2]:\n\n* Avoid literal newline inside ${var:+val} when composing grep match\n  patterns, lest some shells might trip over it. Instead, pass match\n  patterns to grep via -f temporary file.\n\n* Don't assume it's portable to feed commands-list.txt to script as\n  stdin and expect one command (sed) to consume only part of it, leaving\n  the rest for consumption by a subsequent command (grep). While this\n  works on some platforms, in practice, the first command (sed) may\n  buffer and eat more of the input than expected. Instead, pass\n  commands-list.txt as argument and have each command independently open\n  and consume it.\n\n* Replace errant 'd' sed command with 'b' to skip comment lines. The end\n  result is the same, but the other \"skipping\" actions use 'b', and 'b'\n  was intended all along.\n\nv2 is still a single patch since I couldn't quite figure out[3] whether\nJunio was asking for the patch to be submitted as a reversion plus a\ncleanup plus an enhancement or not.\n\n[2]: http://thread.gmane.org/gmane.comp.version-control.git/276226\n[3]: http://thread.gmane.org/gmane.comp.version-control.git/276226/focus=276256\n\n Makefile              |  4 ++--\n generate-cmdlist.perl | 50 --------------------------------------------------\n generate-cmdlist.sh   | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 53 insertions(+), 52 deletions(-)\n delete mode 100755 generate-cmdlist.perl\n create mode 100755 generate-cmdlist.sh\n\ndiff --git a/Makefile b/Makefile\nindex e39ca6c..5d3e3b9 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1697,10 +1697,10 @@ $(BUILT_INS): git$X\n \tln -s $< $@ 2>/dev/null || \\\n \tcp $< $@\n \n-common-cmds.h: generate-cmdlist.perl command-list.txt\n+common-cmds.h: generate-cmdlist.sh command-list.txt\n \n common-cmds.h: $(wildcard Documentation/git-*.txt)\n-\t$(QUIET_GEN)$(PERL_PATH) generate-cmdlist.perl command-list.txt > $@+ && mv $@+ $@\n+\t$(QUIET_GEN)./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@\n \n SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\\\n \t$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\\\ndiff --git a/generate-cmdlist.perl b/generate-cmdlist.perl\ndeleted file mode 100755\nindex 31516e3..0000000\n--- a/generate-cmdlist.perl\n+++ /dev/null\n@@ -1,50 +0,0 @@\n-#!/usr/bin/perl\n-use strict;\n-use warnings;\n-\n-print <<\"EOT\";\n-/* Automatically generated by $0 */\n-\n-struct cmdname_help {\n-\tchar name[16];\n-\tchar help[80];\n-\tunsigned char group;\n-};\n-\n-static char *common_cmd_groups[] = {\n-EOT\n-\n-my $n = 0;\n-my %grp;\n-while (<>) {\n-\tlast if /^### command list/;\n-\tnext if (1../^### common groups/) || /^#/ || /^\\s*$/;\n-\tchop;\n-\tmy ($k, $v) = split ' ', $_, 2;\n-\t$grp{$k} = $n++;\n-\tprint \"\\tN_(\\\"$v\\\"),\\n\";\n-}\n-\n-print \"};\\n\\nstatic struct cmdname_help common_cmds[] = {\\n\";\n-\n-while (<>) {\n-\tnext if /^#/ || /^\\s*$/;\n-\tmy @tags = split;\n-\tmy $cmd = shift @tags;\n-\tfor my $t (@tags) {\n-\t\tif (exists $grp{$t}) {\n-\t\t\tmy $s;\n-\t\t\topen my $f, '<', \"Documentation/$cmd.txt\" or die;\n-\t\t\twhile (<$f>) {\n-\t\t\t\t($s) = /^$cmd - (.+)$/;\n-\t\t\t\tlast if $s;\n-\t\t\t}\n-\t\t\tclose $f;\n-\t\t\t$cmd =~ s/^git-//;\n-\t\t\tprint \"\\t{\\\"$cmd\\\", N_(\\\"$s\\\"), $grp{$t}},\\n\";\n-\t\t\tlast;\n-\t\t}\n-\t}\n-}\n-\n-print \"};\\n\";\ndiff --git a/generate-cmdlist.sh b/generate-cmdlist.sh\nnew file mode 100755\nindex 0000000..6b39c62\n--- /dev/null\n+++ b/generate-cmdlist.sh\n@@ -0,0 +1,51 @@\n+#!/bin/sh\n+\n+echo \"/* Automatically generated by $0 */\n+struct cmdname_help {\n+\tchar name[16];\n+\tchar help[80];\n+\tunsigned char group;\n+};\n+\n+static const char *common_cmd_groups[] = {\"\n+\n+grps=grps$$.tmp\n+match=match$$.tmp\n+trap \"rm -f $grps $match\" 0 1 2 3 15\n+\n+sed -n '\n+\t1,/^### common groups/b\n+\t/^### command list/q\n+\t/^#/b\n+\t/^[ \t]*$/b\n+\th;s/^[^ \t][^ \t]*[ \t][ \t]*\\(.*\\)/\tN_(\"\\1\"),/p\n+\tg;s/^\\([^ \t][^ \t]*\\)[ \t].*/\\1/w '$grps'\n+\t' $1\n+printf '};\\n\\n'\n+\n+n=0\n+>$match\n+substnum=\n+while read grp\n+do\n+\techo \"^git-..*[ \t]$grp\" >>$match\n+\tsubstnum=\"$substnum${substnum:+;}s/[ \t]$grp/$n/\"\n+\tn=$(($n+1))\n+done <$grps\n+\n+printf 'static struct cmdname_help common_cmds[] = {\\n'\n+grep -f $match $1 |\n+sed 's/^git-//' |\n+sort |\n+while read cmd tags\n+do\n+\ttag=$(echo $tags | sed \"$substnum; s/[^0-9]//g\")\n+\tsed -n '\n+\t\t/^NAME/,/git-'\"$cmd\"'/H\n+\t\t${\n+\t\t\tx\n+\t\t\ts/.*git-'\"$cmd\"' - \\(.*\\)/\t{\"'\"$cmd\"'\", N_(\"\\1\"), '$tag'},/\n+\t\t\tp\n+\t\t}' \"Documentation/git-$cmd.txt\"\n+done\n+echo \"};\"\n-- \n2.5.0.495.g1755c2e\n"}]}