8000 Add benchmarks for blame by ethomson · Pull Request #6920 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Add benchmarks for blame #6920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cli: optionally show hidden options in usage
Callers may wish to show all the options, even hidden ones, when showing
usage. In particular, showing generic help for the CLI should show
global options (those that are generally "hidden"). But showing help for
a particular command should keep them hidden. Instrument a mechanism to
deal with this.
  • Loading branch information
ethomson committed Oct 21, 2024
commit e1d44d9834168c0d1cf694bd3f3a7cdff67d8c8d
2 changes: 1 addition & 1 deletion src/cli/cmd_blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Show the origin of each line of a file.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd_cat_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Display the content for the given object in the repository.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd_clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Clone a repository into a new directory.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Query and set configuration options.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd_hash_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Compute the object ID for a given file and optionally write that file\nto the object database.\n");
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cmd_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const cli_opt_spec opts[] = {

static int print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, CLI_OPT_USAGE_SHOW_HIDDEN);
printf("\n");

printf("Display help information about %s. If a command is specified, help\n", PROGRAM_NAME);
Expand All @@ -39,7 +39,7 @@ static int print_commands(void)
{
const cli_cmd_spec *cmd;

cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN);
printf("\n");

printf("These are the %s commands available:\n\n", PROGRAM_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd_index_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static const cli_opt_spec opts[] = {

static void print_help(void)
{
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
printf("\n");

printf("Indexes a packfile and writes the index to disk.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int main(int argc, char **argv)
while (cli_opt_parser_next(&opt, &optparser)) {
if (!opt.spec) {
cli_opt_status_fprint(stderr, PROGRAM_NAME, &opt);
cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts);
cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN);
ret = CLI_EXIT_USAGE;
goto done;
}
Expand Down
38 changes: 29 additions & 9 deletions src/cli/opt_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ int cli_opt_usage_fprint(
FILE *file,
const char *command,
const char *subcommand,
const cli_opt_spec specs[])
const cli_opt_spec specs[],
unsigned int print_flags)
{
git_str usage = GIT_BUF_INIT, opt = GIT_BUF_INIT;
const cli_opt_spec *spec;
Expand All @@ -73,7 +74,8 @@ int cli_opt_usage_fprint(

next_choice = !!((spec + 1)->usage & CLI_OPT_USAGE_CHOICE);

if (spec->usage & CLI_OPT_USAGE_HIDDEN)
if ((spec->usage & CLI_OPT_USAGE_HIDDEN) &&
!(print_flags & CLI_OPT_USAGE_SHOW_HIDDEN))
continue;

if (choice)
Expand Down Expand Up @@ -140,7 +142,7 @@ int cli_opt_usage_error(
const cli_opt *invalid_opt)
{
cli_opt_status_fprint(stderr, PROGRAM_NAME, invalid_opt);
cli_opt_usage_fprint(stderr, PROGRAM_NAME, subcommand, specs);
cli_opt_usage_fprint(stderr, PROGRAM_NAME, subcommand, specs, 0);
return CLI_EXIT_USAGE;
}

Expand All @@ -150,35 +152,53 @@ int cli_opt_help_fprint(
{
git_str help = GIT_BUF_INIT;
const cli_opt_spec *spec;
bool required;
int error = 0;

/* Display required arguments first */
for (spec = specs; spec->type; ++spec) {
if (! (spec->usage & CLI_OPT_USAGE_REQUIRED) ||
(spec->usage & CLI_OPT_USAGE_HIDDEN))
if ((spec->usage & CLI_OPT_USAGE_HIDDEN) ||
(spec->type == CLI_OPT_TYPE_LITERAL))
continue;

required = ((spec->usage & CLI_OPT_USAGE_REQUIRED) ||
((spec->usage & CLI_OPT_USAGE_CHOICE) && required));

if (!required)
continue;

git_str_printf(&help, " ");

if ((error = print_spec_name(&help, spec)) < 0)
goto done;

git_str_printf(&help, ": %s\n", spec->help);
if (spec->help)
git_str_printf(&help, ": %s", spec->help);

git_str_printf(&help, "\n");
}

/* Display the remaining arguments */
for (spec = specs; spec->type; ++spec) {
if ((spec->usage & CLI_OPT_USAGE_REQUIRED) ||
(spec->usage & CLI_OPT_USAGE_HIDDEN))
if ((spec->usage & CLI_OPT_USAGE_HIDDEN) ||
(spec->type == CLI_OPT_TYPE_LITERAL))
continue;

required = ((spec->usage & CLI_OPT_USAGE_REQUIRED) ||
((spec->usage & CLI_OPT_USAGE_CHOICE) && required));

if (required)
continue;

git_str_printf(&help, " ");

if ((error = print_spec_name(&help, spec)) < 0)
goto done;

git_str_printf(&help, ": %s\n", spec->help);
if (spec->help)
git_str_printf(&help, ": %s", spec->help);

git_str_printf(&help, "\n");
}

if (git_str_oom(&help) ||
Expand Down
7 changes: 6 additions & 1 deletion src/cli/opt_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef CLI_opt_usage_h__
#define CLI_opt_usage_h__

typedef enum {
CLI_OPT_USAGE_SHOW_HIDDEN = (1 << 0),
} cli_opt_usage_flags;

/**
* Prints usage information to the given file handle.
*
Expand All @@ -21,7 +25,8 @@ int cli_opt_usage_fprint(
FILE *file,
const char *command,
const char *subcommand,
const cli_opt_spec specs[]);
const cli_opt_spec specs[],
unsigned int print_flags);

int cli_opt_usage_error(
const char *subcommand,
Expand Down
0