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