Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "tag.h" |
| 3 | #include "commit.h" |
| 4 | #include "tree.h" |
| 5 | #include "blob.h" |
| 6 | #include "diff.h" |
| 7 | #include "tree-walk.h" |
| 8 | #include "revision.h" |
| 9 | #include "list-objects.h" |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 10 | #include "list-objects-filter.h" |
| 11 | #include "list-objects-filter-options.h" |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 12 | #include "packfile.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame] | 13 | #include "object-store.h" |
Matthew DeVore | 8b10a20 | 2018-10-17 17:39:15 -0700 | [diff] [blame] | 14 | #include "trace.h" |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 15 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 16 | struct traversal_context { |
| 17 | struct rev_info *revs; |
| 18 | show_object_fn show_object; |
| 19 | show_commit_fn show_commit; |
| 20 | void *show_data; |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 21 | struct filter *filter; |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 24 | static void show_commit(struct traversal_context *ctx, |
| 25 | struct commit *commit) |
| 26 | { |
| 27 | if (!ctx->show_commit) |
| 28 | return; |
| 29 | ctx->show_commit(commit, ctx->show_data); |
| 30 | } |
| 31 | |
| 32 | static void show_object(struct traversal_context *ctx, |
| 33 | struct object *object, |
| 34 | const char *name) |
| 35 | { |
| 36 | if (!ctx->show_object) |
| 37 | return; |
| 38 | ctx->show_object(object, name, ctx->show_data); |
| 39 | } |
| 40 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 41 | static void process_blob(struct traversal_context *ctx, |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 42 | struct blob *blob, |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 43 | struct strbuf *path, |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 44 | const char *name) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 45 | { |
| 46 | struct object *obj = &blob->object; |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 47 | size_t pathlen; |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 48 | enum list_objects_filter_result r; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 49 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 50 | if (!ctx->revs->blob_objects) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 51 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 52 | if (!obj) |
| 53 | die("bad blob object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 54 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 55 | return; |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 56 | |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 57 | /* |
| 58 | * Pre-filter known-missing objects when explicitly requested. |
| 59 | * Otherwise, a missing object error message may be reported |
| 60 | * later (depending on other filtering criteria). |
| 61 | * |
| 62 | * Note that this "--exclude-promisor-objects" pre-filtering |
| 63 | * may cause the actual filter to report an incomplete list |
| 64 | * of missing objects. |
| 65 | */ |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 66 | if (ctx->revs->exclude_promisor_objects && |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 67 | !has_object_file(&obj->oid) && |
| 68 | is_promisor_object(&obj->oid)) |
| 69 | return; |
| 70 | |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 71 | pathlen = path->len; |
| 72 | strbuf_addstr(path, name); |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 73 | r = list_objects_filter__filter_object(ctx->revs->repo, |
| 74 | LOFS_BLOB, obj, |
| 75 | path->buf, &path->buf[pathlen], |
| 76 | ctx->filter); |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 77 | if (r & LOFR_MARK_SEEN) |
| 78 | obj->flags |= SEEN; |
| 79 | if (r & LOFR_DO_SHOW) |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 80 | show_object(ctx, obj, path->buf); |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 81 | strbuf_setlen(path, pathlen); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Processing a gitlink entry currently does nothing, since |
| 86 | * we do not recurse into the subproject. |
| 87 | * |
| 88 | * We *could* eventually add a flag that actually does that, |
| 89 | * which would involve: |
| 90 | * - is the subproject actually checked out? |
| 91 | * - if so, see if the subproject has already been added |
| 92 | * to the alternates list, and add it if not. |
| 93 | * - process the commit (or tag) the gitlink points to |
| 94 | * recursively. |
| 95 | * |
| 96 | * However, it's unclear whether there is really ever any |
| 97 | * reason to see superprojects and subprojects as such a |
| 98 | * "unified" object pool (potentially resulting in a totally |
| 99 | * humongous pack - avoiding which was the whole point of |
| 100 | * having gitlinks in the first place!). |
| 101 | * |
| 102 | * So for now, there is just a note that we *could* follow |
| 103 | * the link, and how to do it. Whether it necessarily makes |
| 104 | * any sense what-so-ever to ever do that is another issue. |
| 105 | */ |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 106 | static void process_gitlink(struct traversal_context *ctx, |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 107 | const unsigned char *sha1, |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 108 | struct strbuf *path, |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 109 | const char *name) |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 110 | { |
| 111 | /* Nothing to do */ |
| 112 | } |
| 113 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 114 | static void process_tree(struct traversal_context *ctx, |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 115 | struct tree *tree, |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 116 | struct strbuf *base, |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 117 | const char *name); |
| 118 | |
| 119 | static void process_tree_contents(struct traversal_context *ctx, |
| 120 | struct tree *tree, |
| 121 | struct strbuf *base) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 122 | { |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 123 | struct tree_desc desc; |
| 124 | struct name_entry entry; |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 125 | enum interesting match = ctx->revs->diffopt.pathspec.nr == 0 ? |
| 126 | all_entries_interesting : entry_not_interesting; |
| 127 | |
| 128 | init_tree_desc(&desc, tree->buffer, tree->size); |
| 129 | |
| 130 | while (tree_entry(&desc, &entry)) { |
| 131 | if (match != all_entries_interesting) { |
Nguyễn Thái Ngọc Duy | 67022e0 | 2018-11-18 17:47:57 +0100 | [diff] [blame] | 132 | match = tree_entry_interesting(ctx->revs->repo->index, |
| 133 | &entry, base, 0, |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 134 | &ctx->revs->diffopt.pathspec); |
| 135 | if (match == all_entries_not_interesting) |
| 136 | break; |
| 137 | if (match == entry_not_interesting) |
| 138 | continue; |
| 139 | } |
| 140 | |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 141 | if (S_ISDIR(entry.mode)) { |
brian m. carlson | ea82b2a | 2019-01-15 00:39:44 +0000 | [diff] [blame] | 142 | struct tree *t = lookup_tree(ctx->revs->repo, &entry.oid); |
Taylor Blau | b49e74e | 2019-04-09 19:13:19 -0700 | [diff] [blame] | 143 | if (!t) { |
| 144 | die(_("entry '%s' in tree %s has tree mode, " |
| 145 | "but is not a tree"), |
| 146 | entry.path, oid_to_hex(&tree->object.oid)); |
| 147 | } |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 148 | t->object.flags |= NOT_USER_GIVEN; |
| 149 | process_tree(ctx, t, base, entry.path); |
| 150 | } |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 151 | else if (S_ISGITLINK(entry.mode)) |
brian m. carlson | ea82b2a | 2019-01-15 00:39:44 +0000 | [diff] [blame] | 152 | process_gitlink(ctx, entry.oid.hash, |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 153 | base, entry.path); |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 154 | else { |
brian m. carlson | ea82b2a | 2019-01-15 00:39:44 +0000 | [diff] [blame] | 155 | struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid); |
Taylor Blau | 23c2044 | 2019-04-09 19:13:17 -0700 | [diff] [blame] | 156 | if (!b) { |
| 157 | die(_("entry '%s' in tree %s has blob mode, " |
| 158 | "but is not a blob"), |
| 159 | entry.path, oid_to_hex(&tree->object.oid)); |
| 160 | } |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 161 | b->object.flags |= NOT_USER_GIVEN; |
| 162 | process_blob(ctx, b, base, entry.path); |
| 163 | } |
Matthew DeVore | 9202489 | 2018-08-13 11:14:29 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | static void process_tree(struct traversal_context *ctx, |
| 168 | struct tree *tree, |
| 169 | struct strbuf *base, |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 170 | const char *name) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 171 | { |
| 172 | struct object *obj = &tree->object; |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 173 | struct rev_info *revs = ctx->revs; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 174 | int baselen = base->len; |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 175 | enum list_objects_filter_result r; |
Matthew DeVore | 7c0fe33 | 2018-10-05 14:31:23 -0700 | [diff] [blame] | 176 | int failed_parse; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 177 | |
| 178 | if (!revs->tree_objects) |
| 179 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 180 | if (!obj) |
| 181 | die("bad tree object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 182 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 183 | return; |
Jeff King | aa9ad6f | 2021-06-14 08:05:44 -0400 | [diff] [blame] | 184 | if (revs->include_check_obj && |
| 185 | !revs->include_check_obj(&tree->object, revs->include_check_data)) |
| 186 | return; |
Matthew DeVore | 7c0fe33 | 2018-10-05 14:31:23 -0700 | [diff] [blame] | 187 | |
| 188 | failed_parse = parse_tree_gently(tree, 1); |
| 189 | if (failed_parse) { |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 190 | if (revs->ignore_missing_links) |
| 191 | return; |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Pre-filter known-missing tree objects when explicitly |
| 195 | * requested. This may cause the actual filter to report |
| 196 | * an incomplete list of missing objects. |
| 197 | */ |
| 198 | if (revs->exclude_promisor_objects && |
| 199 | is_promisor_object(&obj->oid)) |
| 200 | return; |
| 201 | |
Matthew DeVore | 7c0fe33 | 2018-10-05 14:31:23 -0700 | [diff] [blame] | 202 | if (!revs->do_not_die_on_missing_tree) |
| 203 | die("bad tree object %s", oid_to_hex(&obj->oid)); |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 204 | } |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 205 | |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 206 | strbuf_addstr(base, name); |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 207 | r = list_objects_filter__filter_object(ctx->revs->repo, |
| 208 | LOFS_BEGIN_TREE, obj, |
| 209 | base->buf, &base->buf[baselen], |
| 210 | ctx->filter); |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 211 | if (r & LOFR_MARK_SEEN) |
| 212 | obj->flags |= SEEN; |
| 213 | if (r & LOFR_DO_SHOW) |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 214 | show_object(ctx, obj, base->buf); |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 215 | if (base->len) |
| 216 | strbuf_addch(base, '/'); |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 217 | |
Matthew DeVore | 8b10a20 | 2018-10-17 17:39:15 -0700 | [diff] [blame] | 218 | if (r & LOFR_SKIP_TREE) |
| 219 | trace_printf("Skipping contents of tree %s...\n", base->buf); |
| 220 | else if (!failed_parse) |
Matthew DeVore | 7c0fe33 | 2018-10-05 14:31:23 -0700 | [diff] [blame] | 221 | process_tree_contents(ctx, tree, base); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 222 | |
Matthew DeVore | 9430147 | 2019-06-27 15:54:05 -0700 | [diff] [blame] | 223 | r = list_objects_filter__filter_object(ctx->revs->repo, |
| 224 | LOFS_END_TREE, obj, |
| 225 | base->buf, &base->buf[baselen], |
| 226 | ctx->filter); |
| 227 | if (r & LOFR_MARK_SEEN) |
| 228 | obj->flags |= SEEN; |
| 229 | if (r & LOFR_DO_SHOW) |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 230 | show_object(ctx, obj, base->buf); |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 231 | |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 232 | strbuf_setlen(base, baselen); |
Jeff King | 6e454b9 | 2013-06-05 18:37:39 -0400 | [diff] [blame] | 233 | free_tree_buffer(tree); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Patrick Steinhardt | 628d81b | 2021-04-09 13:28:02 +0200 | [diff] [blame] | 236 | static void process_tag(struct traversal_context *ctx, |
| 237 | struct tag *tag, |
| 238 | const char *name) |
| 239 | { |
Patrick Steinhardt | 9a2a4f9 | 2021-04-12 15:37:35 +0200 | [diff] [blame] | 240 | enum list_objects_filter_result r; |
| 241 | |
| 242 | r = list_objects_filter__filter_object(ctx->revs->repo, LOFS_TAG, |
| 243 | &tag->object, NULL, NULL, |
| 244 | ctx->filter); |
| 245 | if (r & LOFR_MARK_SEEN) |
| 246 | tag->object.flags |= SEEN; |
| 247 | if (r & LOFR_DO_SHOW) |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 248 | show_object(ctx, &tag->object, name); |
Patrick Steinhardt | 628d81b | 2021-04-09 13:28:02 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 251 | static void mark_edge_parents_uninteresting(struct commit *commit, |
| 252 | struct rev_info *revs, |
| 253 | show_edge_fn show_edge) |
| 254 | { |
| 255 | struct commit_list *parents; |
| 256 | |
| 257 | for (parents = commit->parents; parents; parents = parents->next) { |
| 258 | struct commit *parent = parents->item; |
| 259 | if (!(parent->object.flags & UNINTERESTING)) |
| 260 | continue; |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 261 | mark_tree_uninteresting(revs->repo, get_commit_tree(parent)); |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 262 | if (revs->edge_hint && !(parent->object.flags & SHOWN)) { |
| 263 | parent->object.flags |= SHOWN; |
| 264 | show_edge(parent); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Derrick Stolee | 4f6d26b | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 269 | static void add_edge_parents(struct commit *commit, |
| 270 | struct rev_info *revs, |
| 271 | show_edge_fn show_edge, |
| 272 | struct oidset *set) |
| 273 | { |
| 274 | struct commit_list *parents; |
| 275 | |
| 276 | for (parents = commit->parents; parents; parents = parents->next) { |
| 277 | struct commit *parent = parents->item; |
| 278 | struct tree *tree = get_commit_tree(parent); |
| 279 | |
| 280 | if (!tree) |
| 281 | continue; |
| 282 | |
| 283 | oidset_insert(set, &tree->object.oid); |
| 284 | |
| 285 | if (!(parent->object.flags & UNINTERESTING)) |
| 286 | continue; |
| 287 | tree->object.flags |= UNINTERESTING; |
| 288 | |
| 289 | if (revs->edge_hint && !(parent->object.flags & SHOWN)) { |
| 290 | parent->object.flags |= SHOWN; |
| 291 | show_edge(parent); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void mark_edges_uninteresting(struct rev_info *revs, |
| 297 | show_edge_fn show_edge, |
| 298 | int sparse) |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 299 | { |
Nguyễn Thái Ngọc Duy | e76a5fb | 2013-08-16 16:52:06 +0700 | [diff] [blame] | 300 | struct commit_list *list; |
Nguyễn Thái Ngọc Duy | fbd4a70 | 2013-08-16 16:52:07 +0700 | [diff] [blame] | 301 | int i; |
| 302 | |
Derrick Stolee | 4f6d26b | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 303 | if (sparse) { |
| 304 | struct oidset set; |
| 305 | oidset_init(&set, 16); |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 306 | |
Derrick Stolee | 4f6d26b | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 307 | for (list = revs->commits; list; list = list->next) { |
| 308 | struct commit *commit = list->item; |
| 309 | struct tree *tree = get_commit_tree(commit); |
| 310 | |
| 311 | if (commit->object.flags & UNINTERESTING) |
| 312 | tree->object.flags |= UNINTERESTING; |
| 313 | |
| 314 | oidset_insert(&set, &tree->object.oid); |
| 315 | add_edge_parents(commit, revs, show_edge, &set); |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 316 | } |
Derrick Stolee | 4f6d26b | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 317 | |
| 318 | mark_trees_uninteresting_sparse(revs->repo, &set); |
| 319 | oidset_clear(&set); |
| 320 | } else { |
| 321 | for (list = revs->commits; list; list = list->next) { |
| 322 | struct commit *commit = list->item; |
| 323 | if (commit->object.flags & UNINTERESTING) { |
| 324 | mark_tree_uninteresting(revs->repo, |
| 325 | get_commit_tree(commit)); |
| 326 | if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) { |
| 327 | commit->object.flags |= SHOWN; |
| 328 | show_edge(commit); |
| 329 | } |
| 330 | continue; |
| 331 | } |
| 332 | mark_edge_parents_uninteresting(commit, revs, show_edge); |
| 333 | } |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 334 | } |
Derrick Stolee | 4f6d26b | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 335 | |
brian m. carlson | 1684c1b | 2014-12-24 23:05:39 +0000 | [diff] [blame] | 336 | if (revs->edge_hint_aggressive) { |
Jeff King | 200abe7 | 2014-01-20 21:25:40 -0500 | [diff] [blame] | 337 | for (i = 0; i < revs->cmdline.nr; i++) { |
| 338 | struct object *obj = revs->cmdline.rev[i].item; |
| 339 | struct commit *commit = (struct commit *)obj; |
| 340 | if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING)) |
| 341 | continue; |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 342 | mark_tree_uninteresting(revs->repo, |
| 343 | get_commit_tree(commit)); |
Jeff King | 200abe7 | 2014-01-20 21:25:40 -0500 | [diff] [blame] | 344 | if (!(obj->flags & SHOWN)) { |
| 345 | obj->flags |= SHOWN; |
| 346 | show_edge(commit); |
| 347 | } |
Nguyễn Thái Ngọc Duy | fbd4a70 | 2013-08-16 16:52:07 +0700 | [diff] [blame] | 348 | } |
| 349 | } |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 352 | static void add_pending_tree(struct rev_info *revs, struct tree *tree) |
| 353 | { |
| 354 | add_pending_object(revs, &tree->object, ""); |
| 355 | } |
| 356 | |
Teng Long | b3e36df | 2021-08-12 16:59:31 +0800 | [diff] [blame] | 357 | static void traverse_non_commits(struct traversal_context *ctx, |
| 358 | struct strbuf *base) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 359 | { |
| 360 | int i; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 361 | |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 362 | assert(base->len == 0); |
| 363 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 364 | for (i = 0; i < ctx->revs->pending.nr; i++) { |
| 365 | struct object_array_entry *pending = ctx->revs->pending.objects + i; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 366 | struct object *obj = pending->item; |
| 367 | const char *name = pending->name; |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 368 | const char *path = pending->path; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 369 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 370 | continue; |
| 371 | if (obj->type == OBJ_TAG) { |
Patrick Steinhardt | 628d81b | 2021-04-09 13:28:02 +0200 | [diff] [blame] | 372 | process_tag(ctx, (struct tag *)obj, name); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 373 | continue; |
| 374 | } |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 375 | if (!path) |
| 376 | path = ""; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 377 | if (obj->type == OBJ_TREE) { |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 378 | process_tree(ctx, (struct tree *)obj, base, path); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 379 | continue; |
| 380 | } |
| 381 | if (obj->type == OBJ_BLOB) { |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 382 | process_blob(ctx, (struct blob *)obj, base, path); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 383 | continue; |
| 384 | } |
| 385 | die("unknown pending object %s (%s)", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 386 | oid_to_hex(&obj->oid), name); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 387 | } |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 388 | object_array_clear(&ctx->revs->pending); |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 391 | static void do_traverse(struct traversal_context *ctx) |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 392 | { |
| 393 | struct commit *commit; |
| 394 | struct strbuf csp; /* callee's scratch pad */ |
| 395 | strbuf_init(&csp, PATH_MAX); |
| 396 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 397 | while ((commit = get_revision(ctx->revs)) != NULL) { |
Patrick Steinhardt | 9a2a4f9 | 2021-04-12 15:37:35 +0200 | [diff] [blame] | 398 | enum list_objects_filter_result r; |
| 399 | |
| 400 | r = list_objects_filter__filter_object(ctx->revs->repo, |
| 401 | LOFS_COMMIT, &commit->object, |
| 402 | NULL, NULL, ctx->filter); |
| 403 | |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 404 | /* |
| 405 | * an uninteresting boundary commit may not have its tree |
| 406 | * parsed yet, but we are not going to show them anyway |
| 407 | */ |
Jeff King | 72ed80c | 2019-09-11 21:11:37 -0400 | [diff] [blame] | 408 | if (!ctx->revs->tree_objects) |
| 409 | ; /* do not bother loading tree */ |
| 410 | else if (get_commit_tree(commit)) { |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 411 | struct tree *tree = get_commit_tree(commit); |
| 412 | tree->object.flags |= NOT_USER_GIVEN; |
| 413 | add_pending_tree(ctx->revs, tree); |
Jeff King | 97dd512 | 2019-04-09 19:13:25 -0700 | [diff] [blame] | 414 | } else if (commit->object.parsed) { |
| 415 | die(_("unable to load root tree for commit %s"), |
| 416 | oid_to_hex(&commit->object.oid)); |
Matthew DeVore | 99c9aa9 | 2018-10-05 14:31:24 -0700 | [diff] [blame] | 417 | } |
Patrick Steinhardt | 9a2a4f9 | 2021-04-12 15:37:35 +0200 | [diff] [blame] | 418 | |
| 419 | if (r & LOFR_MARK_SEEN) |
| 420 | commit->object.flags |= SEEN; |
| 421 | if (r & LOFR_DO_SHOW) |
Ævar Arnfjörð Bjarmason | 4f33a63 | 2022-03-09 16:01:38 +0000 | [diff] [blame] | 422 | show_commit(ctx, commit); |
Stefan Beller | ce5b6f9 | 2017-11-15 18:00:35 -0800 | [diff] [blame] | 423 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 424 | if (ctx->revs->tree_blobs_in_commit_order) |
Stefan Beller | ce5b6f9 | 2017-11-15 18:00:35 -0800 | [diff] [blame] | 425 | /* |
| 426 | * NEEDSWORK: Adding the tree and then flushing it here |
| 427 | * needs a reallocation for each commit. Can we pass the |
| 428 | * tree directory without allocation churn? |
| 429 | */ |
Teng Long | b3e36df | 2021-08-12 16:59:31 +0800 | [diff] [blame] | 430 | traverse_non_commits(ctx, &csp); |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 431 | } |
Teng Long | b3e36df | 2021-08-12 16:59:31 +0800 | [diff] [blame] | 432 | traverse_non_commits(ctx, &csp); |
Stefan Beller | 91904f5 | 2017-11-02 12:41:43 -0700 | [diff] [blame] | 433 | strbuf_release(&csp); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 434 | } |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 435 | |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 436 | void traverse_commit_list_filtered( |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 437 | struct rev_info *revs, |
| 438 | show_commit_fn show_commit, |
| 439 | show_object_fn show_object, |
| 440 | void *show_data, |
| 441 | struct oidset *omitted) |
| 442 | { |
Derrick Stolee | 3e0370a | 2022-03-09 16:01:36 +0000 | [diff] [blame] | 443 | struct traversal_context ctx = { |
| 444 | .revs = revs, |
| 445 | .show_object = show_object, |
| 446 | .show_commit = show_commit, |
| 447 | .show_data = show_data, |
| 448 | }; |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 449 | |
Derrick Stolee | 3e0370a | 2022-03-09 16:01:36 +0000 | [diff] [blame] | 450 | if (revs->filter.choice) |
| 451 | ctx.filter = list_objects_filter__init(omitted, &revs->filter); |
| 452 | |
Matthew DeVore | f447a49 | 2018-08-13 11:14:28 -0700 | [diff] [blame] | 453 | do_traverse(&ctx); |
Derrick Stolee | 3e0370a | 2022-03-09 16:01:36 +0000 | [diff] [blame] | 454 | |
| 455 | if (ctx.filter) |
| 456 | list_objects_filter__free(ctx.filter); |
Jeff Hostetler | 25ec7bc | 2017-11-21 20:58:50 +0000 | [diff] [blame] | 457 | } |