Remove cmd_usage() routine and re-organize the help/usage code.

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>
diff --git a/builtin-help.c b/builtin-help.c
index bb0b03f..fb731cc 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -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 @@
 	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 @@
 	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_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;
 }
 
diff --git a/builtin.h b/builtin.h
index 88c4d84..f10d3b7 100644
--- 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 d031eb9..110e82e 100644
--- 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 @@
 			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 @@
 	}
 
 	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));
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index bf1d638..34a3ccd 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -170,7 +170,7 @@
 	     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 @@
 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 @@
 test_expect_success "$name" "diff -u a expected"
 
 test_done
-