Skip to content

Commit 247d737

Browse files
Jeff Hostetlerderrickstolee
authored andcommitted
survey: stub in new experimental 'git-survey' command
Start work on a new 'git survey' command to scan the repository for monorepo performance and scaling problems. The goal is to measure the various known "dimensions of scale" and serve as a foundation for adding additional measurements as we learn more about Git monorepo scaling problems. The initial goal is to complement the scanning and analysis performed by the GO-based 'git-sizer' (https://github.com/github/git-sizer) tool. It is hoped that by creating a builtin command, we may be able to take advantage of internal Git data structures and code that is not accessible from GO to gain further insight into potential scaling problems. Co-authored-by: Derrick Stolee <[email protected]> Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
1 parent e3a0eb1 commit 247d737

12 files changed

+149
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
/git-submodule
166166
/git-submodule--helper
167167
/git-subtree
168+
/git-survey
168169
/git-svn
169170
/git-switch
170171
/git-symbolic-ref

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ include::config/status.txt[]
534534

535535
include::config/submodule.txt[]
536536

537+
include::config/survey.txt[]
538+
537539
include::config/tag.txt[]
538540

539541
include::config/tar.txt[]

Documentation/config/survey.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
survey.*::
2+
These variables adjust the default behavior of the `git survey`
3+
command. The intention is that this command could be run in the
4+
background with these options.
5+
+
6+
--
7+
verbose::
8+
This boolean value implies the `--[no-]verbose` option.
9+
progress::
10+
This boolean value implies the `--[no-]progress` option.
11+
--

Documentation/git-survey.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
git-survey(1)
2+
=============
3+
4+
NAME
5+
----
6+
git-survey - EXPERIMENTAL: Measure various repository dimensions of scale
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
(EXPERIMENTAL!) 'git survey' <options>
12+
13+
DESCRIPTION
14+
-----------
15+
16+
Survey the repository and measure various dimensions of scale.
17+
18+
As repositories grow to "monorepo" size, certain data shapes can cause
19+
performance problems. `git-survey` attempts to measure and report on
20+
known problem areas.
21+
22+
OPTIONS
23+
-------
24+
25+
--progress::
26+
Show progress. This is automatically enabled when interactive.
27+
28+
OUTPUT
29+
------
30+
31+
By default, `git survey` will print information about the repository in a
32+
human-readable format that includes overviews and tables.
33+
34+
GIT
35+
---
36+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ BUILTIN_OBJS += builtin/sparse-checkout.o
13091309
BUILTIN_OBJS += builtin/stash.o
13101310
BUILTIN_OBJS += builtin/stripspace.o
13111311
BUILTIN_OBJS += builtin/submodule--helper.o
1312+
BUILTIN_OBJS += builtin/survey.o
13121313
BUILTIN_OBJS += builtin/symbolic-ref.o
13131314
BUILTIN_OBJS += builtin/tag.o
13141315
BUILTIN_OBJS += builtin/unpack-file.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix, struct
231231
int cmd_status(int argc, const char **argv, const char *prefix, struct repository *repo);
232232
int cmd_stash(int argc, const char **argv, const char *prefix, struct repository *repo);
233233
int cmd_stripspace(int argc, const char **argv, const char *prefix, struct repository *repo);
234+
int cmd_survey(int argc, const char **argv, const char *prefix, struct repository *repo);
234235
int cmd_submodule__helper(int argc, const char **argv, const char *prefix, struct repository *repo);
235236
int cmd_switch(int argc, const char **argv, const char *prefix, struct repository *repo);
236237
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix, struct repository *repo);

builtin/survey.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
3+
#include "builtin.h"
4+
#include "config.h"
5+
#include "parse-options.h"
6+
7+
static const char * const survey_usage[] = {
8+
N_("(EXPERIMENTAL!) git survey <options>"),
9+
NULL,
10+
};
11+
12+
struct survey_opts {
13+
int verbose;
14+
int show_progress;
15+
};
16+
17+
struct survey_context {
18+
struct repository *repo;
19+
20+
/* Options that control what is done. */
21+
struct survey_opts opts;
22+
};
23+
24+
static int survey_load_config_cb(const char *var, const char *value,
25+
const struct config_context *cctx, void *pvoid)
26+
{
27+
struct survey_context *ctx = pvoid;
28+
29+
if (!strcmp(var, "survey.verbose")) {
30+
ctx->opts.verbose = git_config_bool(var, value);
31+
return 0;
32+
}
33+
if (!strcmp(var, "survey.progress")) {
34+
ctx->opts.show_progress = git_config_bool(var, value);
35+
return 0;
36+
}
37+
38+
return git_default_config(var, value, cctx, pvoid);
39+
}
40+
41+
static void survey_load_config(struct survey_context *ctx)
42+
{
43+
git_config(survey_load_config_cb, ctx);
44+
}
45+
46+
int cmd_survey(int argc, const char **argv, const char *prefix, struct repository *repo)
47+
{
48+
static struct survey_context ctx = {
49+
.opts = {
50+
.verbose = 0,
51+
.show_progress = -1, /* defaults to isatty(2) */
52+
},
53+
};
54+
55+
static struct option survey_options[] = {
56+
OPT__VERBOSE(&ctx.opts.verbose, N_("verbose output")),
57+
OPT_BOOL(0, "progress", &ctx.opts.show_progress, N_("show progress")),
58+
OPT_END(),
59+
};
60+
61+
if (argc == 2 && !strcmp(argv[1], "-h"))
62+
usage_with_options(survey_usage, survey_options);
63+
64+
ctx.repo = repo;
65+
66+
prepare_repo_settings(ctx.repo);
67+
survey_load_config(&ctx);
68+
69+
argc = parse_options(argc, argv, prefix, survey_options, survey_usage, 0);
70+
71+
if (ctx.opts.show_progress < 0)
72+
ctx.opts.show_progress = isatty(2);
73+
74+
return 0;
75+
}

command-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ git-stash mainporcelain
187187
git-status mainporcelain info
188188
git-stripspace purehelpers
189189
git-submodule mainporcelain
190+
git-survey mainporcelain
190191
git-svn foreignscminterface
191192
git-switch mainporcelain history
192193
git-symbolic-ref plumbingmanipulators

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ static struct cmd_struct commands[] = {
627627
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
628628
{ "stripspace", cmd_stripspace },
629629
{ "submodule--helper", cmd_submodule__helper, RUN_SETUP },
630+
{ "survey", cmd_survey, RUN_SETUP },
630631
{ "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE },
631632
{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
632633
{ "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ builtin_sources = [
592592
'builtin/stash.c',
593593
'builtin/stripspace.c',
594594
'builtin/submodule--helper.c',
595+
'builtin/survey.c',
595596
'builtin/symbolic-ref.c',
596597
'builtin/tag.c',
597598
'builtin/unpack-file.c',

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ integration_tests = [
957957
't8012-blame-colors.sh',
958958
't8013-blame-ignore-revs.sh',
959959
't8014-blame-ignore-fuzzy.sh',
960+
't8100-git-survey.sh',
960961
't9001-send-email.sh',
961962
't9002-column.sh',
962963
't9003-help-autocorrect.sh',

t/t8100-git-survey.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
test_description='git survey'
4+
5+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7+
8+
TEST_PASSES_SANITIZE_LEAK=0
9+
export TEST_PASSES_SANITIZE_LEAK
10+
11+
. ./test-lib.sh
12+
13+
test_expect_success 'git survey -h shows experimental warning' '
14+
test_expect_code 129 git survey -h 2>usage &&
15+
grep "EXPERIMENTAL!" usage
16+
'
17+
18+
test_done

0 commit comments

Comments
 (0)