]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Remove cmd_usage() routine and re-organize the help/usage code.
authorRamsay Allan Jones <ramsay@ramsay1.demon.co.uk>
Sun, 30 Jul 2006 21:42:25 +0000 (22:42 +0100)
committerJunio C Hamano <junkio@cox.net>
Wed, 2 Aug 2006 07:27:18 +0000 (00:27 -0700)
The cmd_usage() routine was causing warning messages due to a NULL
format parameter being passed in three out of four calls. This is a
problem if you want to compile with -Werror. A simple solution is to
simply remove the GNU __attribute__ format pragma from the cmd_usage()
declaration in the header file. The function interface was somewhat
muddled anyway, so re-write the code to finesse the problem.

[jc: this incidentally revealed that t9100 test assumed that the output
 from "git help" to be fixed in stone, but this patch lower-cases
 "Usage" to "usage".  Update the test not to rely on "git help" output.]

Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-help.c
builtin.h
git.c
t/t9100-git-svn-basic.sh

index bb0b03f1ae64cc5f4fa1376169c27b8a7cb71734..fb731cc9345e197e710aea611e9519f1e04e0ab8 100644 (file)
@@ -9,8 +9,6 @@
 #include "exec_cmd.h"
 #include "common-cmds.h"
 
-static const char git_usage[] =
-       "Usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ ARGS ]";
 
 /* most GUI terminals set COLUMNS (although some don't export it) */
 static int term_columns(void)
@@ -178,31 +176,6 @@ static void list_common_cmds_help(void)
        puts("(use 'git help -a' to get a list of all installed git commands)");
 }
 
-void cmd_usage(int show_all, const char *exec_path, const char *fmt, ...)
-{
-       if (fmt) {
-               va_list ap;
-
-               va_start(ap, fmt);
-               printf("git: ");
-               vprintf(fmt, ap);
-               va_end(ap);
-               putchar('\n');
-       }
-       else
-               puts(git_usage);
-
-       if (exec_path) {
-               putchar('\n');
-               if (show_all)
-                       list_commands(exec_path, "git-*");
-               else
-                       list_common_cmds_help();
-        }
-
-       exit(1);
-}
-
 static void show_man_page(const char *git_cmd)
 {
        const char *page;
@@ -221,6 +194,13 @@ static void show_man_page(const char *git_cmd)
        execlp("man", "man", page, NULL);
 }
 
+void help_unknown_cmd(const char *cmd)
+{
+       printf("git: '%s' is not a git-command\n\n", cmd);
+       list_common_cmds_help();
+       exit(1);
+}
+
 int cmd_version(int argc, const char **argv, const char *prefix)
 {
        printf("git version %s\n", git_version_string);
@@ -230,12 +210,24 @@ int cmd_version(int argc, const char **argv, const char *prefix)
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
        const char *help_cmd = argc > 1 ? argv[1] : NULL;
-       if (!help_cmd)
-               cmd_usage(0, git_exec_path(), NULL);
-       else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a"))
-               cmd_usage(1, git_exec_path(), NULL);
+       const char *exec_path = git_exec_path();
+
+       if (!help_cmd) {
+               printf("usage: %s\n\n", git_usage_string);
+               list_common_cmds_help();
+               exit(1);
+       }
+
+       else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) {
+               printf("usage: %s\n\n", git_usage_string);
+               if(exec_path)
+                       list_commands(exec_path, "git-*");
+               exit(1);
+       }
+
        else
                show_man_page(help_cmd);
+
        return 0;
 }
 
index 88c4d847123fc74847bbbb03ad37ddda7518d6cb..f10d3b77c87ea5e542a9ff150051baa72fb47a40 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -5,12 +5,9 @@
 #include <limits.h>
 
 extern const char git_version_string[];
+extern const char git_usage_string[];
 
-void cmd_usage(int show_all, const char *exec_path, const char *fmt, ...)
-#ifdef __GNUC__
-       __attribute__((__format__(__printf__, 3, 4), __noreturn__))
-#endif
-       ;
+extern void help_unknown_cmd(const char *cmd);
 
 extern int cmd_help(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index d031eb9a1868befaa546e230579152b35591054e..110e82e9ac52bb0972f25efd5e84a229a72b03d5 100644 (file)
--- a/git.c
+++ b/git.c
@@ -15,6 +15,9 @@
 
 #include "builtin.h"
 
+const char git_usage_string[] =
+       "git [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ ARGS ]";
+
 static void prepend_to_path(const char *dir, int len)
 {
        const char *old_path = getenv("PATH");
@@ -78,7 +81,7 @@ static int handle_options(const char*** argv, int* argc)
                        setenv("GIT_DIR", getcwd(git_dir, 1024), 1);
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
-                       cmd_usage(0, NULL, NULL);
+                       usage(git_usage_string);
                }
 
                (*argv)++;
@@ -375,7 +378,7 @@ int main(int argc, const char **argv, char **envp)
        }
 
        if (errno == ENOENT)
-               cmd_usage(0, exec_path, "'%s' is not a git-command", cmd);
+               help_unknown_cmd(cmd);
 
        fprintf(stderr, "Failed to run command '%s': %s\n",
                cmd, strerror(errno));
index bf1d6381d9f7cb3f2a0d037893986be265de4dec..34a3ccd31cee8e82fd8a9867637cf610efae3e4c 100755 (executable)
@@ -170,7 +170,7 @@ then
             test -L $SVN_TREE/exec-2.sh"
 
        name='modify a symlink to become a file'
-       git help > help || true
+       echo git help > help || true
        rm exec-2.sh
        cp help exec-2.sh
        git update-index exec-2.sh
@@ -217,10 +217,10 @@ name='check imported tree checksums expected tree checksums'
 rm -f expected
 if test "$have_utf8" = t
 then
-       echo tree f735671b89a7eb30cab1d8597de35bd4271ab813 > expected
+       echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected
 fi
 cat >> expected <<\EOF
-tree 4b9af72bb861eaed053854ec502cf7df72618f0f
+tree 83654bb36f019ae4fe77a0171f81075972087624
 tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
 tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
@@ -231,4 +231,3 @@ EOF
 test_expect_success "$name" "diff -u a expected"
 
 test_done
-