Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "config.h" |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 3 | #include "dir.h" |
| 4 | #include "lockfile.h" |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 5 | #include "parse-options.h" |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 6 | #include "repository.h" |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 7 | #include "commit-graph.h" |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 8 | #include "object-store.h" |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 9 | #include "progress.h" |
Taylor Blau | 2f00c35 | 2020-05-13 15:59:55 -0600 | [diff] [blame] | 10 | #include "tag.h" |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 11 | |
Ævar Arnfjörð Bjarmason | 8757b35 | 2021-08-23 14:30:15 +0200 | [diff] [blame] | 12 | #define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \ |
Ævar Arnfjörð Bjarmason | f6a8ef0 | 2022-10-13 17:39:10 +0200 | [diff] [blame] | 13 | N_("git commit-graph verify [--object-dir <dir>] [--shallow] [--[no-]progress]") |
Ævar Arnfjörð Bjarmason | 8757b35 | 2021-08-23 14:30:15 +0200 | [diff] [blame] | 14 | |
| 15 | #define BUILTIN_COMMIT_GRAPH_WRITE_USAGE \ |
Ævar Arnfjörð Bjarmason | f6a8ef0 | 2022-10-13 17:39:10 +0200 | [diff] [blame] | 16 | N_("git commit-graph write [--object-dir <dir>] [--append]\n" \ |
Ævar Arnfjörð Bjarmason | e2f4e7e | 2022-10-13 17:39:06 +0200 | [diff] [blame] | 17 | " [--split[=<strategy>]] [--reachable | --stdin-packs | --stdin-commits]\n" \ |
Ævar Arnfjörð Bjarmason | 5af8b61 | 2022-10-13 17:39:02 +0200 | [diff] [blame] | 18 | " [--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress]\n" \ |
| 19 | " <split options>") |
Ævar Arnfjörð Bjarmason | 8757b35 | 2021-08-23 14:30:15 +0200 | [diff] [blame] | 20 | |
| 21 | static const char * builtin_commit_graph_verify_usage[] = { |
| 22 | BUILTIN_COMMIT_GRAPH_VERIFY_USAGE, |
| 23 | NULL |
| 24 | }; |
| 25 | |
| 26 | static const char * builtin_commit_graph_write_usage[] = { |
| 27 | BUILTIN_COMMIT_GRAPH_WRITE_USAGE, |
| 28 | NULL |
| 29 | }; |
| 30 | |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 31 | static char const * const builtin_commit_graph_usage[] = { |
Ævar Arnfjörð Bjarmason | 8757b35 | 2021-08-23 14:30:15 +0200 | [diff] [blame] | 32 | BUILTIN_COMMIT_GRAPH_VERIFY_USAGE, |
| 33 | BUILTIN_COMMIT_GRAPH_WRITE_USAGE, |
| 34 | NULL, |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | static struct opts_commit_graph { |
| 38 | const char *obj_dir; |
Derrick Stolee | 59fb877 | 2018-06-27 09:24:45 -0400 | [diff] [blame] | 39 | int reachable; |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 40 | int stdin_packs; |
Derrick Stolee | 3d5df01 | 2018-04-10 08:56:07 -0400 | [diff] [blame] | 41 | int stdin_commits; |
Derrick Stolee | 7547b95 | 2018-04-10 08:56:08 -0400 | [diff] [blame] | 42 | int append; |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 43 | int split; |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 44 | int shallow; |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 45 | int progress; |
Garima Singh | d38e07b | 2020-04-06 16:59:51 +0000 | [diff] [blame] | 46 | int enable_changed_paths; |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 47 | } opts; |
| 48 | |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 49 | static struct option common_opts[] = { |
| 50 | OPT_STRING(0, "object-dir", &opts.obj_dir, |
| 51 | N_("dir"), |
| 52 | N_("the object directory to store the graph")), |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 53 | OPT_END() |
| 54 | }; |
| 55 | |
| 56 | static struct option *add_common_options(struct option *to) |
| 57 | { |
| 58 | return parse_options_concat(common_opts, to); |
| 59 | } |
| 60 | |
SZEDER Gábor | 1c3b051 | 2022-08-19 18:04:02 +0200 | [diff] [blame] | 61 | static int graph_verify(int argc, const char **argv, const char *prefix) |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 62 | { |
| 63 | struct commit_graph *graph = NULL; |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 64 | struct object_directory *odb = NULL; |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 65 | char *graph_name; |
Ævar Arnfjörð Bjarmason | 61df89c | 2019-03-25 13:08:30 +0100 | [diff] [blame] | 66 | int open_ok; |
| 67 | int fd; |
| 68 | struct stat st; |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 69 | int flags = 0; |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 70 | |
| 71 | static struct option builtin_commit_graph_verify_options[] = { |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 72 | OPT_BOOL(0, "shallow", &opts.shallow, |
| 73 | N_("if the commit-graph is split, only verify the tip file")), |
Taylor Blau | d5fdf30 | 2021-09-18 12:02:37 -0400 | [diff] [blame] | 74 | OPT_BOOL(0, "progress", &opts.progress, |
| 75 | N_("force progress reporting")), |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 76 | OPT_END(), |
| 77 | }; |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 78 | struct option *options = add_common_options(builtin_commit_graph_verify_options); |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 79 | |
Garima Singh | 0bd7f57 | 2019-08-27 09:56:34 -0700 | [diff] [blame] | 80 | trace2_cmd_mode("verify"); |
| 81 | |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 82 | opts.progress = isatty(2); |
Jeff King | ecd2d3e | 2022-08-25 06:47:00 -0400 | [diff] [blame] | 83 | argc = parse_options(argc, argv, prefix, |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 84 | options, |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 85 | builtin_commit_graph_verify_usage, 0); |
Ævar Arnfjörð Bjarmason | 6d209a0 | 2021-08-23 14:30:20 +0200 | [diff] [blame] | 86 | if (argc) |
| 87 | usage_with_options(builtin_commit_graph_verify_usage, options); |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 88 | |
| 89 | if (!opts.obj_dir) |
| 90 | opts.obj_dir = get_object_directory(); |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 91 | if (opts.shallow) |
| 92 | flags |= COMMIT_GRAPH_VERIFY_SHALLOW; |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 93 | if (opts.progress) |
| 94 | flags |= COMMIT_GRAPH_WRITE_PROGRESS; |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 95 | |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 96 | odb = find_odb(the_repository, opts.obj_dir); |
Taylor Blau | ad2dd5b | 2020-02-03 13:18:02 -0800 | [diff] [blame] | 97 | graph_name = get_commit_graph_filename(odb); |
Ævar Arnfjörð Bjarmason | 61df89c | 2019-03-25 13:08:30 +0100 | [diff] [blame] | 98 | open_ok = open_commit_graph(graph_name, &fd, &st); |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 99 | if (!open_ok && errno != ENOENT) |
Ævar Arnfjörð Bjarmason | 7b8ce9c | 2019-03-25 13:08:32 +0100 | [diff] [blame] | 100 | die_errno(_("Could not open commit-graph '%s'"), graph_name); |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 101 | |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 102 | FREE_AND_NULL(graph_name); |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 103 | FREE_AND_NULL(options); |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 104 | |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 105 | if (open_ok) |
Taylor Blau | ab14d06 | 2020-09-09 11:22:56 -0400 | [diff] [blame] | 106 | graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb); |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 107 | else |
Taylor Blau | 13c2499 | 2020-02-03 13:18:00 -0800 | [diff] [blame] | 108 | graph = read_commit_graph_one(the_repository, odb); |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 109 | |
| 110 | /* Return failure if open_ok predicted success */ |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 111 | if (!graph) |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 112 | return !!open_ok; |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 113 | |
Martin Ågren | 0bfb48e | 2018-10-03 10:12:17 -0700 | [diff] [blame] | 114 | UNLEAK(graph); |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 115 | return verify_commit_graph(the_repository, graph, flags); |
Derrick Stolee | 283e68c | 2018-06-27 09:24:32 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Derrick Stolee | d653824 | 2018-08-20 18:24:27 +0000 | [diff] [blame] | 118 | extern int read_replace_refs; |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 119 | static struct commit_graph_opts write_opts; |
Derrick Stolee | d653824 | 2018-08-20 18:24:27 +0000 | [diff] [blame] | 120 | |
Taylor Blau | 4f02735 | 2020-04-13 22:04:08 -0600 | [diff] [blame] | 121 | static int write_option_parse_split(const struct option *opt, const char *arg, |
| 122 | int unset) |
| 123 | { |
Taylor Blau | fdbde82 | 2020-04-13 22:04:12 -0600 | [diff] [blame] | 124 | enum commit_graph_split_flags *flags = opt->value; |
| 125 | |
Jeff King | 8d2aa8d | 2020-09-30 08:29:02 -0400 | [diff] [blame] | 126 | BUG_ON_OPT_NEG(unset); |
| 127 | |
Taylor Blau | 4f02735 | 2020-04-13 22:04:08 -0600 | [diff] [blame] | 128 | opts.split = 1; |
| 129 | if (!arg) |
| 130 | return 0; |
| 131 | |
Taylor Blau | fdbde82 | 2020-04-13 22:04:12 -0600 | [diff] [blame] | 132 | if (!strcmp(arg, "no-merge")) |
| 133 | *flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED; |
Taylor Blau | 8a6ac28 | 2020-04-13 22:04:17 -0600 | [diff] [blame] | 134 | else if (!strcmp(arg, "replace")) |
| 135 | *flags = COMMIT_GRAPH_SPLIT_REPLACE; |
Taylor Blau | fdbde82 | 2020-04-13 22:04:12 -0600 | [diff] [blame] | 136 | else |
| 137 | die(_("unrecognized --split argument, %s"), arg); |
Taylor Blau | 4f02735 | 2020-04-13 22:04:08 -0600 | [diff] [blame] | 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 142 | static int read_one_commit(struct oidset *commits, struct progress *progress, |
| 143 | const char *hash) |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 144 | { |
Taylor Blau | 2f00c35 | 2020-05-13 15:59:55 -0600 | [diff] [blame] | 145 | struct object *result; |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 146 | struct object_id oid; |
| 147 | const char *end; |
| 148 | |
| 149 | if (parse_oid_hex(hash, &oid, &end)) |
| 150 | return error(_("unexpected non-hex object ID: %s"), hash); |
| 151 | |
Taylor Blau | 2f00c35 | 2020-05-13 15:59:55 -0600 | [diff] [blame] | 152 | result = deref_tag(the_repository, parse_object(the_repository, &oid), |
| 153 | NULL, 0); |
| 154 | if (!result) |
| 155 | return error(_("invalid object: %s"), hash); |
Abhishek Kumar | 6da43d9 | 2020-06-17 14:44:08 +0530 | [diff] [blame] | 156 | else if (object_as_type(result, OBJ_COMMIT, 1)) |
Taylor Blau | 2f00c35 | 2020-05-13 15:59:55 -0600 | [diff] [blame] | 157 | oidset_insert(commits, &result->oid); |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 158 | |
| 159 | display_progress(progress, oidset_size(commits)); |
| 160 | |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
Taylor Blau | 809e032 | 2020-09-18 09:27:27 -0400 | [diff] [blame] | 164 | static int write_option_max_new_filters(const struct option *opt, |
| 165 | const char *arg, |
| 166 | int unset) |
| 167 | { |
| 168 | int *to = opt->value; |
| 169 | if (unset) |
| 170 | *to = -1; |
| 171 | else { |
| 172 | const char *s; |
| 173 | *to = strtol(arg, (char **)&s, 10); |
| 174 | if (*s) |
Ævar Arnfjörð Bjarmason | 13d9fce | 2021-10-08 21:07:43 +0200 | [diff] [blame] | 175 | return error(_("option `%s' expects a numerical value"), |
| 176 | "max-new-filters"); |
Taylor Blau | 809e032 | 2020-09-18 09:27:27 -0400 | [diff] [blame] | 177 | } |
| 178 | return 0; |
| 179 | } |
| 180 | |
Taylor Blau | d356d5d | 2020-09-17 22:59:57 -0400 | [diff] [blame] | 181 | static int git_commit_graph_write_config(const char *var, const char *value, |
Ævar Arnfjörð Bjarmason | 5cf88fd | 2022-08-25 19:09:48 +0200 | [diff] [blame] | 182 | void *cb UNUSED) |
Taylor Blau | d356d5d | 2020-09-17 22:59:57 -0400 | [diff] [blame] | 183 | { |
| 184 | if (!strcmp(var, "commitgraph.maxnewfilters")) |
| 185 | write_opts.max_new_filters = git_config_int(var, value); |
| 186 | /* |
| 187 | * No need to fall-back to 'git_default_config', since this was already |
| 188 | * called in 'cmd_commit_graph()'. |
| 189 | */ |
| 190 | return 0; |
| 191 | } |
| 192 | |
SZEDER Gábor | 1c3b051 | 2022-08-19 18:04:02 +0200 | [diff] [blame] | 193 | static int graph_write(int argc, const char **argv, const char *prefix) |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 194 | { |
Ævar Arnfjörð Bjarmason | 4a04790 | 2022-03-04 19:32:12 +0100 | [diff] [blame] | 195 | struct string_list pack_indexes = STRING_LIST_INIT_DUP; |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 196 | struct strbuf buf = STRBUF_INIT; |
Taylor Blau | 6830c36 | 2020-04-13 22:04:25 -0600 | [diff] [blame] | 197 | struct oidset commits = OIDSET_INIT; |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 198 | struct object_directory *odb = NULL; |
Derrick Stolee | e103f72 | 2019-06-12 06:29:37 -0700 | [diff] [blame] | 199 | int result = 0; |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 200 | enum commit_graph_write_flags flags = 0; |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 201 | struct progress *progress = NULL; |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 202 | |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 203 | static struct option builtin_commit_graph_write_options[] = { |
Derrick Stolee | 59fb877 | 2018-06-27 09:24:45 -0400 | [diff] [blame] | 204 | OPT_BOOL(0, "reachable", &opts.reachable, |
| 205 | N_("start walk at all refs")), |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 206 | OPT_BOOL(0, "stdin-packs", &opts.stdin_packs, |
| 207 | N_("scan pack-indexes listed by stdin for commits")), |
Derrick Stolee | 3d5df01 | 2018-04-10 08:56:07 -0400 | [diff] [blame] | 208 | OPT_BOOL(0, "stdin-commits", &opts.stdin_commits, |
| 209 | N_("start walk at commits listed by stdin")), |
Derrick Stolee | 7547b95 | 2018-04-10 08:56:08 -0400 | [diff] [blame] | 210 | OPT_BOOL(0, "append", &opts.append, |
| 211 | N_("include all commits already in the commit-graph file")), |
Garima Singh | d38e07b | 2020-04-06 16:59:51 +0000 | [diff] [blame] | 212 | OPT_BOOL(0, "changed-paths", &opts.enable_changed_paths, |
| 213 | N_("enable computation for changed paths")), |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 214 | OPT_CALLBACK_F(0, "split", &write_opts.split_flags, NULL, |
Taylor Blau | 4f02735 | 2020-04-13 22:04:08 -0600 | [diff] [blame] | 215 | N_("allow writing an incremental commit-graph file"), |
| 216 | PARSE_OPT_OPTARG | PARSE_OPT_NONEG, |
| 217 | write_option_parse_split), |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 218 | OPT_INTEGER(0, "max-commits", &write_opts.max_commits, |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 219 | N_("maximum number of commits in a non-base split commit-graph")), |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 220 | OPT_INTEGER(0, "size-multiple", &write_opts.size_multiple, |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 221 | N_("maximum ratio between two levels of a split commit-graph")), |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 222 | OPT_EXPIRY_DATE(0, "expire-time", &write_opts.expire_time, |
Derrick Stolee | b09b785 | 2020-04-01 21:00:44 +0000 | [diff] [blame] | 223 | N_("only expire files older than a given date-time")), |
Taylor Blau | 809e032 | 2020-09-18 09:27:27 -0400 | [diff] [blame] | 224 | OPT_CALLBACK_F(0, "max-new-filters", &write_opts.max_new_filters, |
| 225 | NULL, N_("maximum number of changed-path Bloom filters to compute"), |
| 226 | 0, write_option_max_new_filters), |
Taylor Blau | d5fdf30 | 2021-09-18 12:02:37 -0400 | [diff] [blame] | 227 | OPT_BOOL(0, "progress", &opts.progress, |
| 228 | N_("force progress reporting")), |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 229 | OPT_END(), |
| 230 | }; |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 231 | struct option *options = add_common_options(builtin_commit_graph_write_options); |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 232 | |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 233 | opts.progress = isatty(2); |
Derrick Stolee | 0087a87 | 2020-07-01 13:27:24 +0000 | [diff] [blame] | 234 | opts.enable_changed_paths = -1; |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 235 | write_opts.size_multiple = 2; |
| 236 | write_opts.max_commits = 0; |
| 237 | write_opts.expire_time = 0; |
Taylor Blau | 809e032 | 2020-09-18 09:27:27 -0400 | [diff] [blame] | 238 | write_opts.max_new_filters = -1; |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 239 | |
Garima Singh | 0bd7f57 | 2019-08-27 09:56:34 -0700 | [diff] [blame] | 240 | trace2_cmd_mode("write"); |
| 241 | |
Taylor Blau | d356d5d | 2020-09-17 22:59:57 -0400 | [diff] [blame] | 242 | git_config(git_commit_graph_write_config, &opts); |
| 243 | |
Jeff King | ecd2d3e | 2022-08-25 06:47:00 -0400 | [diff] [blame] | 244 | argc = parse_options(argc, argv, prefix, |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 245 | options, |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 246 | builtin_commit_graph_write_usage, 0); |
Ævar Arnfjörð Bjarmason | 6d209a0 | 2021-08-23 14:30:20 +0200 | [diff] [blame] | 247 | if (argc) |
| 248 | usage_with_options(builtin_commit_graph_write_usage, options); |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 249 | |
Derrick Stolee | 59fb877 | 2018-06-27 09:24:45 -0400 | [diff] [blame] | 250 | if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1) |
| 251 | die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs")); |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 252 | if (!opts.obj_dir) |
| 253 | opts.obj_dir = get_object_directory(); |
Derrick Stolee | 5af8039 | 2019-06-12 06:29:38 -0700 | [diff] [blame] | 254 | if (opts.append) |
SZEDER Gábor | 39d8831 | 2019-08-05 10:02:39 +0200 | [diff] [blame] | 255 | flags |= COMMIT_GRAPH_WRITE_APPEND; |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 256 | if (opts.split) |
SZEDER Gábor | 39d8831 | 2019-08-05 10:02:39 +0200 | [diff] [blame] | 257 | flags |= COMMIT_GRAPH_WRITE_SPLIT; |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 258 | if (opts.progress) |
| 259 | flags |= COMMIT_GRAPH_WRITE_PROGRESS; |
Derrick Stolee | 0087a87 | 2020-07-01 13:27:24 +0000 | [diff] [blame] | 260 | if (!opts.enable_changed_paths) |
| 261 | flags |= COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS; |
| 262 | if (opts.enable_changed_paths == 1 || |
Garima Singh | d5b873c | 2020-04-06 16:59:55 +0000 | [diff] [blame] | 263 | git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0)) |
Garima Singh | d38e07b | 2020-04-06 16:59:51 +0000 | [diff] [blame] | 264 | flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS; |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 265 | |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 266 | odb = find_odb(the_repository, opts.obj_dir); |
Derrick Stolee | d653824 | 2018-08-20 18:24:27 +0000 | [diff] [blame] | 267 | |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 268 | if (opts.reachable) { |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 269 | if (write_commit_graph_reachable(odb, flags, &write_opts)) |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 270 | return 1; |
| 271 | return 0; |
| 272 | } |
Derrick Stolee | 59fb877 | 2018-06-27 09:24:45 -0400 | [diff] [blame] | 273 | |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 274 | if (opts.stdin_packs) { |
Derrick Stolee | d88b14b | 2018-06-27 09:24:44 -0400 | [diff] [blame] | 275 | while (strbuf_getline(&buf, stdin) != EOF) |
Ævar Arnfjörð Bjarmason | 4a04790 | 2022-03-04 19:32:12 +0100 | [diff] [blame] | 276 | string_list_append_nodup(&pack_indexes, |
| 277 | strbuf_detach(&buf, NULL)); |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 278 | } else if (opts.stdin_commits) { |
| 279 | oidset_init(&commits, 0); |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 280 | if (opts.progress) |
| 281 | progress = start_delayed_progress( |
| 282 | _("Collecting commits from input"), 0); |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 283 | |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 284 | while (strbuf_getline(&buf, stdin) != EOF) { |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 285 | if (read_one_commit(&commits, progress, buf.buf)) { |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 286 | result = 1; |
| 287 | goto cleanup; |
Taylor Blau | 6830c36 | 2020-04-13 22:04:25 -0600 | [diff] [blame] | 288 | } |
SZEDER Gábor | 7c5c9b9 | 2019-08-05 10:02:40 +0200 | [diff] [blame] | 289 | } |
Taylor Blau | 5b6653e | 2020-05-13 15:59:44 -0600 | [diff] [blame] | 290 | |
SZEDER Gábor | 862aead | 2020-07-10 21:02:38 +0200 | [diff] [blame] | 291 | stop_progress(&progress); |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Taylor Blau | 0bd52e2 | 2020-02-03 21:51:50 -0800 | [diff] [blame] | 294 | if (write_commit_graph(odb, |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 295 | opts.stdin_packs ? &pack_indexes : NULL, |
Taylor Blau | 6830c36 | 2020-04-13 22:04:25 -0600 | [diff] [blame] | 296 | opts.stdin_commits ? &commits : NULL, |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 297 | flags, |
Taylor Blau | 98bb796 | 2020-09-17 22:59:49 -0400 | [diff] [blame] | 298 | &write_opts)) |
Derrick Stolee | e103f72 | 2019-06-12 06:29:37 -0700 | [diff] [blame] | 299 | result = 1; |
Derrick Stolee | 049d51a | 2018-04-10 08:56:06 -0400 | [diff] [blame] | 300 | |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 301 | cleanup: |
Ævar Arnfjörð Bjarmason | 84e4484 | 2021-08-23 14:30:17 +0200 | [diff] [blame] | 302 | FREE_AND_NULL(options); |
Taylor Blau | fa8953c | 2020-05-18 13:27:09 -0600 | [diff] [blame] | 303 | string_list_clear(&pack_indexes, 0); |
| 304 | strbuf_release(&buf); |
Derrick Stolee | e103f72 | 2019-06-12 06:29:37 -0700 | [diff] [blame] | 305 | return result; |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 306 | } |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 307 | |
| 308 | int cmd_commit_graph(int argc, const char **argv, const char *prefix) |
| 309 | { |
SZEDER Gábor | 1c3b051 | 2022-08-19 18:04:02 +0200 | [diff] [blame] | 310 | parse_opt_subcommand_fn *fn = NULL; |
| 311 | struct option builtin_commit_graph_options[] = { |
| 312 | OPT_SUBCOMMAND("verify", &fn, graph_verify), |
| 313 | OPT_SUBCOMMAND("write", &fn, graph_write), |
| 314 | OPT_END(), |
| 315 | }; |
| 316 | struct option *options = parse_options_concat(builtin_commit_graph_options, common_opts); |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 317 | |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 318 | git_config(git_default_config, NULL); |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 319 | |
Ævar Arnfjörð Bjarmason | 095d112 | 2021-10-15 01:37:16 +0200 | [diff] [blame] | 320 | read_replace_refs = 0; |
Jeff King | dd2e50a | 2019-09-07 01:04:40 -0400 | [diff] [blame] | 321 | save_commit_buffer = 0; |
| 322 | |
SZEDER Gábor | 1c3b051 | 2022-08-19 18:04:02 +0200 | [diff] [blame] | 323 | argc = parse_options(argc, argv, prefix, options, |
| 324 | builtin_commit_graph_usage, 0); |
| 325 | FREE_AND_NULL(options); |
Derrick Stolee | f237c8b | 2018-04-02 16:34:20 -0400 | [diff] [blame] | 326 | |
SZEDER Gábor | 1c3b051 | 2022-08-19 18:04:02 +0200 | [diff] [blame] | 327 | return fn(argc, argv, prefix); |
Derrick Stolee | 4ce58ee | 2018-04-02 16:34:18 -0400 | [diff] [blame] | 328 | } |