git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtins: search builtin commands via binary search.

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 28, 2013, 09:05 UTC
Message-ID
<CAPig+cSsUJSd2nx6icfbEgv71hBVnBQM8oxpvoqLzqFPkNY4KA@mail.gmail.com>
In-Reply-To
<51F38997.9010507@googlemail.com>

On Sat, Jul 27, 2013 at 4:49 AM, Stefan Beller <stefanbeller@googlemail.com> wrote:

Show 21 quoted lines
> I was fiddling around with make now to include the suggestion of Eric to
> check the arguments for being sorted in make. However I do not
> seem to fully understand the syntax yet.
> My approach would have been:
>
> sorted_internal_cmds: git.c
>         { awk '/cmd_struct commands/,/};/ { if (match($2,/"/)) print $2 }' <git.c >builtin.actual && \
>         sort <builtin.actual >builtin.expect && \
>         cmp -s builtin.expect builtin.actual && \
>         rm builtin.expect builtin.actual \
>         }
>
> all:: sorted_internal_cmds
>
> But then there is
> $ make
> ...
>         }
> /bin/sh: 5: Syntax error: end of file unexpected (expecting "}")
>
> So I suspect the { within the shell code inside the awk parameter is messing up?

As Andreas noted, you need a semicolon before the closing shell '}', however it's not clear why you added the braces since they are not needed. The following works (after fixing whitespace corruption):

-->8--
diff --git a/Makefile b/Makefile
index ef442eb..82e727c 100644
--- a/Makefile
+++ b/Makefile
@@ -1681,6 +1681,15 @@ shell_compatibility_test:
please_set_SHELL_PATH_to_a_more_modern_shell
 strip: $(PROGRAMS) git$X
  $(STRIP) $(STRIP_OPTS) $^

+.PHONY: sorted_internal_cmds
+all:: sorted_internal_cmds
+
+sorted_internal_cmds: git.c
+ @awk '/cmd_struct commands/,/};/ { if (match($$2,/"/)) print $$2 }'
<git.c >builtin.actual && \
+ sort <builtin.actual >builtin.expect && \
+ cmp -s builtin.expect builtin.actual && \
+ rm builtin.expect builtin.actual
+
 ### Target-specific flags and dependencies

 # The generic compilation pattern rule and automatically
-->8--

Note the $$2 in awk expression. Also the .PHONY is a good idea.

However, perhaps, it is better for this check to be part of the test
suite. It might look like this (after fixing whitespace corruption):

-->8--
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 10be52b..e5ba504 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -387,6 +387,14 @@ test_expect_success 'tests clean up even on failures' "
 ################################################################
 # Basics of the basics

+# git.c commands[] of builtins is properly sorted
+test_expect_success 'builtin commands[] sorted' '
+ awk "/cmd_struct commands/,/};/ { if (match(\$2,/\"/)) print \$2 }" \
+ <../../git.c >actual && \
+ sort <actual >expect && \
+ test_cmp expect actual
+'
+
 # updating a new file without --add should fail.
 test_expect_success 'git update-index without --add should fail adding' '
  test_must_fail git update-index should-be-empty
-->8--

I'm not sure that referencing ../../git.c from within the test suite
is kosher. Perhaps Jonathan can say something about that.
Previous: Andreas SchwabNext: Junio C Hamano
Message 6 of 8 in “builtins: search builtin commands via binary search.”
  1. builtins: search builtin commands via binary search.Stefan Beller, Jul 26, 2013
  2. Jonathan NiederJul 26, 2013
  3. Stefan BellerJul 27, 2013
  4. builtins: search builtin commands via binary search.Stefan Beller, Jul 27, 2013
  5. Andreas SchwabJul 27, 2013
  6. Eric SunshineJul 28, 2013
  7. Junio C HamanoJul 29, 2013
  8. Eric SunshineJul 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.