diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-03-03 15:16:15 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-03-03 15:16:15 +0900 |
commit | 25fc9ef35e9544c5fe62c8c6379ce828bdc975b2 (patch) | |
tree | 82abd85ecc8e05c398fbfe11a483224788a9b3e7 /help.c | |
parent | 2376b62f539bf17c1458795e0cea9c9df4b4927d (diff) | |
download | git-25fc9ef35e9544c5fe62c8c6379ce828bdc975b2.tar.gz git-25fc9ef35e9544c5fe62c8c6379ce828bdc975b2.tar.bz2 git-25fc9ef35e9544c5fe62c8c6379ce828bdc975b2.zip |
Imported Upstream version 2.14.0upstream/2.14.0
Diffstat (limited to 'help.c')
-rw-r--r-- | help.c | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "run-command.h" @@ -9,6 +10,7 @@ #include "column.h" #include "version.h" #include "refs.h" +#include "parse-options.h" void add_cmdname(struct cmdnames *cmds, const char *name, int len) { @@ -267,9 +269,8 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) for (i = 0; i < old->cnt; i++) cmds->names[cmds->cnt++] = old->names[i]; - free(old->names); + FREE_AND_NULL(old->names); old->cnt = 0; - old->names = NULL; } /* An empirically derived magic number */ @@ -389,16 +390,30 @@ const char *help_unknown_cmd(const char *cmd) int cmd_version(int argc, const char **argv, const char *prefix) { + int build_options = 0; + const char * const usage[] = { + N_("git version [<options>]"), + NULL + }; + struct option options[] = { + OPT_BOOL(0, "build-options", &build_options, + "also print build options"), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, usage, 0); + /* * The format of this string should be kept stable for compatibility * with external projects that rely on the output of "git version". + * + * Always show the version, even if other options are given. */ printf("git version %s\n", git_version_string); - while (*++argv) { - if (!strcmp(*argv, "--build-options")) { - printf("sizeof-long: %d\n", (int)sizeof(long)); - /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ - } + + if (build_options) { + printf("sizeof-long: %d\n", (int)sizeof(long)); + /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ } return 0; } |