8000 Merge pull request #6920 from libgit2/ethomson/blame_benchmarks · libgit2/libgit2@533ec83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 533ec83

Browse files
authored
Merge pull request #6920 from libgit2/ethomson/blame_benchmarks
Add benchmarks for blame
2 parents 229181b + e68d0b4 commit 533ec83

17 files changed

+213
-73
lines changed

.github/workflows/benchmark.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: Benchmark
33

44
on:
55
workflow_dispatch:
6+
inputs:
7+
suite:
8+
description: Benchmark suite to run
9+
debug:
10+
type: boolean
11+
description: Debugging output
612
schedule:
713
- cron: '15 4 * * *'
814

@@ -62,21 +68,42 @@ jobs:
6268
run: source/ci/setup-${{ matrix.platform.setup-script }}-benchmark.sh
6369
shell: bash
6470
if: matrix.platform.setup-script != ''
71+
- name: Clone resource repositories
72+
run: |
73+
mkdir resources
74+
git clone --bare https://github.com/git/git resources/git
75+
git clone --bare https://github.com/torvalds/linux resources/linux
6576
- name: Build
6677
run: |
6778
mkdir build && cd build
6879
../source/ci/build.sh
6980
shell: bash
7081
- name: Benchmark
7182
run: |
83+
export BENCHMARK_GIT_REPOSITORY="$(pwd)/resources/git"
84+
# avoid linux temporarily; the linux blame benchmarks are simply
85+
# too slow to use
86+
# export BENCHMARK_LINUX_REPOSITORY="$(pwd)/resources/linux"
87+
7288
if [[ "$(uname -s)" == MINGW* ]]; then
7389
GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2"
7490
else
7591
GIT2_CLI="$(pwd)/build/git2"
7692
fi
7793
94+
if [ "${{ github.event.inputs.suite }}" != "" ]; then
95+
SUITE_FLAG="--suite ${{ github.event.inputs.suite }}"
96+
fi
97+
98+
if [ "${{ github.event.inputs.debug }}" = "true" ]; then
99+
DEBUG_FLAG="--debug"
100+
fi
101+
78102
mkdir benchmark && cd benchmark
79-
../source/tests/benchmarks/benchmark.sh --baseline-cli "git" --cli "${GIT2_CLI}" --name libgit2 --json benchmarks.json --zip benchmarks.zip
103+
../source/tests/benchmarks/benchmark.sh \
104+
${SUITE_FLAG} ${DEBUG_FLAG} \
105+
--baseline-cli "git" --cli "${GIT2_CLI}" --name libgit2 \
106+
--json benchmarks.json --zip benchmarks.zip
80107
shell: bash
81108
- name: Upload results
82109
uses: actions/upload-artifact@v4
@@ -89,7 +116,7 @@ jobs:
89116
publish:
90117
name: Publish results
91118
needs: [ build ]
92-
if: always() && github.repository == 'libgit2/libgit2'
119+
if: always() && github.repository == 'libgit2/libgit2' && github.event_name == 'schedule'
93120
runs-on: ubuntu-latest
94121
steps:
95122
- name: Check out benchmark repository

src/cli/cmd_blame.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
static char *file;
2424
static int porcelain, line_porcelain;
25-
static int show_help;
2625

2726
static const cli_opt_spec opts[] = {
2827
CLI_COMMON_OPT,
@@ -40,7 +39,7 @@ static const cli_opt_spec opts[] = {
4039

4140
static void print_help(void)
4241
{
43-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
42+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
4443
printf("\n");
4544

4645
printf("Show the origin of each line of a file.\n");
@@ -254,7 +253,7 @@ int cmd_blame(int argc, char **argv)
254253
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
255254
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
256255

257-
if (show_help) {
256+
if (cli_opt__show_help) {
258257
print_help();
259258
return 0;
260259
}

src/cli/cmd_cat_file.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ typedef enum {
1919
DISPLAY_TYPE
2020
} display_t;
2121

22-
static int show_help;
2322
static int display = DISPLAY_CONTENT;
2423
static char *type_name, *object_spec;
2524

@@ -43,7 +42,7 @@ static const cli_opt_spec opts[] = {
4342

4443
static void print_help(void)
4544
{
46-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
45+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
4746
printf("\n");
4847

4948
printf("Display the content for the given object in the repository.\n");
@@ -147,7 +146,7 @@ int cmd_cat_file(int argc, char **argv)
147146
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
148147
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
149148

150-
if (show_help) {
149+
if (cli_opt__show_help) {
151150
print_help();
152151
return 0;
153152
}

src/cli/cmd_clone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define COMMAND_NAME "clone"
2020

2121
static char *branch, *remote_path, *local_path, *depth;
22-
static int show_help, quiet, checkout = 1, bare;
22+
static int quiet, checkout = 1, bare;
2323
static bool local_path_exists;
2424
static cli_progress progress = CLI_PROGRESS_INIT;
2525

@@ -46,7 +46,7 @@ static const cli_opt_spec opts[] = {
4646

4747
static void print_help(void)
4848
{
49-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
49+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
5050
printf("\n");
5151

5252
printf("Clone a repository into a new directory.\n");
@@ -133,7 +133,7 @@ int cmd_clone(int argc, char **argv)
133133
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
134134
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
135135

136-
if (show_help) {
136+
if (cli_opt__show_help) {
137137
print_help();
138138
return 0;
139139
}

src/cli/cmd_config.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ typedef enum {
2323
static action_t action = ACTION_NONE;
2424
static int show_origin;
2525
static int show_scope;
26-
static int show_help;
2726
static int null_separator;
2827
static int config_level;
2928
static char *config_filename;
@@ -68,7 +67,7 @@ static const cli_opt_spec opts[] = {
6867

6968
static void print_help(void)
7069
{
71-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
70+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
7271
printf("\n");
7372

7473
printf("Query and set configuration options.\n");
@@ -180,7 +179,7 @@ int cmd_config(int argc, char **argv)
180179
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
181180
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
182181

183-
if (show_help) {
182+
if (cli_opt__show_help) {
184183
print_help();
185184
return 0;
186185
}

src/cli/cmd_hash_object.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#define COMMAND_NAME "hash-object"
1515

16-
static int show_help;
1716
static char *type_name;
1817
static int write_object, read_stdin, literally;
1918
static char **filenames;
@@ -36,7 +35,7 @@ static const cli_opt_spec opts[] = {
3635

3736
static void print_help(void)
3837
{
39-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
38+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
4039
printf("\n");
4140

4241
printf("Compute the object ID for a given file and optionally write that file\nto the object database.\n");
@@ -103,7 +102,7 @@ int cmd_hash_object(int argc, char **argv)
103102
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
104103
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
105104

106-
if (show_help) {
105+
if (cli_opt__show_help) {
107106
print_help();
108107
return 0;
109108
}

src/cli/cmd_help.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define COMMAND_NAME "help"
1414

1515
static char *command;
16-
static int show_help;
1716

1817
static const cli_opt_spec opts[] = {
1918
CLI_COMMON_OPT,
@@ -25,7 +24,7 @@ static const cli_opt_spec opts[] = {
2524

2625
static int print_help(void)
2726
{
28-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
27+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, CLI_OPT_USAGE_SHOW_HIDDEN);
2928
printf("\n");
3029

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

42-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts);
41+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN);
4342
printf("\n");
4443

4544
printf("These are the %s commands available:\n\n", PROGRAM_NAME);
@@ -62,7 +61,7 @@ int cmd_help(int argc, char **argv)
6261
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
6362

6463
/* Show the meta-help */
65-
if (show_help)
64+
if (cli_opt__show_help)
6665
return print_help();
6766

6867
/* We were not asked to show help for a specific command. */

src/cli/cmd_index_pack.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414

1515
#define BUFFER_SIZE (1024 * 1024)
1616

17-
static int show_help, verbose, read_stdin;
17+
static int verbose, read_stdin;
1818
static char *filename;
1919
static cli_progress progress = CLI_PROGRESS_INIT;
2020

2121
static const cli_opt_spec opts[] = {
22-
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1,
23-
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
24-
"display help about the " COMMAND_NAME " command" },
22+
CLI_COMMON_OPT,
2523

2624
{ CLI_OPT_TYPE_SWITCH, "verbose", 'v', &verbose, 1,
2725
CLI_OPT_USAGE_DEFAULT, NULL, "display progress output" },
@@ -38,7 +36,7 @@ static const cli_opt_spec opts[] = {
3836

3937
static void print_help(void)
4038
{
41-
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts);
39+
cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts, 0);
4240
printf("\n");
4341

4442
printf("Indexes a packfile and writes the index to disk.\n");
@@ -62,7 +60,7 @@ int cmd_index_pack(int argc, char **argv)
6260
if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU))
6361
return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt);
6462

65-
if (show_help) {
63+
if (cli_opt__show_help) {
6664
print_help();
6765
return 0;
6866
}

src/cli/common.h

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,31 @@
2020
* Common command arguments.
2121
*/
2222

23+
extern int cli_opt__show_help;
24+
extern int cli_opt__use_pager;
25+
2326
#define CLI_COMMON_OPT_HELP \
24-
CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, \
25-
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING
27+
CLI_OPT_TYPE_SWITCH, "help", 0, &cli_opt__show_help, 1, \
28+
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, \
29+
NULL, "display help information"
2630
#define CLI_COMMON_OPT_CONFIG \
27-
CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \
28-
CLI_OPT_USAGE_HIDDEN
31+
CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \
32+
CLI_OPT_USAGE_HIDDEN, \
33+
"key=value", "add configuration value"
2934
#define CLI_COMMON_OPT_CONFIG_ENV \
30-
CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \
31-
CLI_OPT_USAGE_HIDDEN
35+
CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \
36+
CLI_OPT_USAGE_HIDDEN, \
37+
"key=value", "set configuration value to environment variable"
38+
#define CLI_COMMON_OPT_NO_PAGER \
39+
CLI_OPT_TYPE_SWITCH, "no-pager", 0, &cli_opt__use_pager, 0, \
40+
CLI_OPT_USAGE_HIDDEN, \
41+
NULL, "don't paginate multi-page output"
3242

3343
#define CLI_COMMON_OPT \
3444
{ CLI_COMMON_OPT_HELP }, \
3545
{ CLI_COMMON_OPT_CONFIG }, \
36-
{ CLI_COMMON_OPT_CONFIG_ENV }
46+
{ CLI_COMMON_OPT_CONFIG_ENV }, \
47+
{ CLI_COMMON_OPT_NO_PAGER }
3748

3849
typedef struct {
3950
char **args;
@@ -49,23 +60,4 @@ extern int cli_resolve_path(
4960
git_repository *repo,
5061
const char *given_path);
5162

52-
/*
53-
* Common command arguments.
54-
*/
55-
56-
#define CLI_COMMON_OPT_HELP \
57-
CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, \
58-
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING
59-
#define CLI_COMMON_OPT_CONFIG \
60-
CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \
61-
CLI_OPT_USAGE_HIDDEN
62-
#define CLI_COMMON_OPT_CONFIG_ENV \
63-
CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \
64-
CLI_OPT_USAGE_HIDDEN
65-
66-
#define CLI_COMMON_OPT \
67-
{ CLI_COMMON_OPT_HELP }, \
68-
{ CLI_COMMON_OPT_CONFIG }, \
69-
{ CLI_COMMON_OPT_CONFIG_ENV }
70-
7163
#endif /* CLI_common_h__ */

src/cli/main.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010
#include "common.h"
1111
#include "cmd.h"
1212

13-
static int show_help = 0;
13+
int cli_opt__show_help = 0;
14+
int cli_opt__use_pager = 1;
15+
1416
static int show_version = 0;
1517
static char *command = NULL;
1618
static char **args = NULL;
1719

1820
const cli_opt_spec cli_common_opts[] = {
19-
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1,
20-
CLI_OPT_USAGE_DEFAULT, NULL, "display help information" },
21-
{ CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0,
22-
CLI_OPT_USAGE_DEFAULT, "key=value", "add configuration value" },
23-
{ CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0,
24-
CLI_OPT_USAGE_DEFAULT, "key=value", "set configuration value to environment variable" },
21+
CLI_COMMON_OPT,
22+
2523
{ CLI_OPT_TYPE_SWITCH, "version", 0, &show_version, 1,
2624
CLI_OPT_USAGE_DEFAULT, NULL, "display the version" },
2725
{ CLI_OPT_TYPE_ARG, "command", 0, &command, 0,
@@ -64,6 +62,19 @@ static void reorder_args(char **argv, size_t first)
6462
argv[1] = tmp;
6563
}
6664

65+
/*
66+
* When invoked without a command, or just with `--help`, we invoke
67+
* the help command; but we want to preserve only arguments that would
68+
* be useful for that.
69+
*/
70+
static void help_args(int *argc, char **argv)
71+
{
72+
cli_opt__show_help = 0;
73+
74+
argv[0] = "help";
75+
*argc = 1;
76+
}
77+
6778
int main(int argc, char **argv)
6879
{
6980
const cli_cmd_spec *cmd;
@@ -82,7 +93,7 @@ int main(int argc, char **argv)
8293
while (cli_opt_parser_next(&opt, &optparser)) {
8394
if (!opt.spec) {
8495
cli_opt_status_fprint(stderr, PROGRAM_NAME, &opt);
85-
cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts);
96+
cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts, CLI_OPT_USAGE_SHOW_HIDDEN);
8697
ret = CLI_EXIT_USAGE;
8798
goto done;
8899
}
@@ -103,6 +114,7 @@ int main(int argc, char **argv)
103114
}
104115

105116
if (!command) {
117+
help_args(&argc, argv);
106118
ret = cmd_help(argc, argv);
107119
goto done;
108120
}

0 commit comments

Comments
 (0)
0