summaryrefslogtreecommitdiff
path: root/builtin-help.c
diff options
context:
space:
mode:
authorRamsay Allan Jones <ramsay@ramsay1.demon.co.uk>2006-07-30 21:42:25 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-08-02 07:27:18 (GMT)
commit822a7d507151e1d6310f52d5b05234d65db11a88 (patch)
tree649ce1c6b078ed5a040f5ffb91cf847c023a473f /builtin-help.c
parent8e76483ce0ce256b01345abc4ca97b1f94aed354 (diff)
downloadgit-822a7d507151e1d6310f52d5b05234d65db11a88.zip
git-822a7d507151e1d6310f52d5b05234d65db11a88.tar.gz
git-822a7d507151e1d6310f52d5b05234d65db11a88.tar.bz2
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>
Diffstat (limited to 'builtin-help.c')
-rw-r--r--builtin-help.c54
1 files changed, 23 insertions, 31 deletions
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 @@ 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;
}