Merge branch 'jk/consistent-h'

"git $cmd -h" for builtin commands calls the implementation of the
command (i.e. cmd_$cmd() function) without doing any repository
set-up, and the commands that expect RUN_SETUP is done by the Git
potty needs to be prepared to show the help text without barfing.

* jk/consistent-h:
  t0012: test "-h" with builtins
  git: add hidden --list-builtins option
  version: convert to parse-options
  diff- and log- family: handle "git cmd -h" early
  submodule--helper: show usage for "-h"
  remote-{ext,fd}: print usage message on invalid arguments
  upload-archive: handle "-h" option early
  credential: handle invalid arguments earlier
This commit is contained in:
Junio C Hamano
2017-06-19 12:38:45 -07:00
12 changed files with 72 additions and 13 deletions

25
help.c
View File

@ -9,6 +9,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)
{
@ -383,16 +384,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;
}