blob: 11ad8be411eeb29b3f1bb0fd798ab71e71791014 [file] [log] [blame]
Elijah Newrend812c3b2023-04-11 00:41:56 -07001#include "git-compat-util.h"
Junio C Hamanoc64ed702006-09-04 21:50:12 -07002#include "tag.h"
3#include "commit.h"
Elijah Newrenf394e092023-03-21 06:25:54 +00004#include "gettext.h"
Elijah Newren41771fa2023-02-24 00:09:27 +00005#include "hex.h"
Junio C Hamanoc64ed702006-09-04 21:50:12 -07006#include "tree.h"
7#include "blob.h"
8#include "diff.h"
9#include "tree-walk.h"
10#include "revision.h"
11#include "list-objects.h"
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000012#include "list-objects-filter.h"
13#include "list-objects-filter-options.h"
Jonathan Tandf11e192017-12-08 15:27:15 +000014#include "packfile.h"
Elijah Newrena034e912023-05-16 06:34:06 +000015#include "object-store-ll.h"
Matthew DeVore8b10a202018-10-17 17:39:15 -070016#include "trace.h"
Jeff King670a1da2023-08-31 02:22:03 -040017#include "environment.h"
Junio C Hamanoc64ed702006-09-04 21:50:12 -070018
Matthew DeVoref447a492018-08-13 11:14:28 -070019struct traversal_context {
20 struct rev_info *revs;
21 show_object_fn show_object;
22 show_commit_fn show_commit;
23 void *show_data;
Matthew DeVore94301472019-06-27 15:54:05 -070024 struct filter *filter;
Jeff King670a1da2023-08-31 02:22:03 -040025 int depth;
Matthew DeVoref447a492018-08-13 11:14:28 -070026};
27
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +000028static void show_commit(struct traversal_context *ctx,
29 struct commit *commit)
30{
31 if (!ctx->show_commit)
32 return;
33 ctx->show_commit(commit, ctx->show_data);
34}
35
36static void show_object(struct traversal_context *ctx,
37 struct object *object,
38 const char *name)
39{
40 if (!ctx->show_object)
41 return;
Taylor Blau4263f922023-11-06 17:56:30 -050042 if (ctx->revs->unpacked && has_object_pack(&object->oid))
43 return;
44
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +000045 ctx->show_object(object, name, ctx->show_data);
46}
47
Matthew DeVoref447a492018-08-13 11:14:28 -070048static void process_blob(struct traversal_context *ctx,
Junio C Hamanoc64ed702006-09-04 21:50:12 -070049 struct blob *blob,
Jeff Kingbd645162016-02-11 17:26:44 -050050 struct strbuf *path,
Matthew DeVoref447a492018-08-13 11:14:28 -070051 const char *name)
Junio C Hamanoc64ed702006-09-04 21:50:12 -070052{
53 struct object *obj = &blob->object;
Jeff Kingde1e67d2016-02-11 17:28:36 -050054 size_t pathlen;
Matthew DeVore94301472019-06-27 15:54:05 -070055 enum list_objects_filter_result r;
Junio C Hamanoc64ed702006-09-04 21:50:12 -070056
Matthew DeVoref447a492018-08-13 11:14:28 -070057 if (!ctx->revs->blob_objects)
Junio C Hamanoc64ed702006-09-04 21:50:12 -070058 return;
Martin Koeglera301b0c2008-02-18 21:47:56 +010059 if (!obj)
60 die("bad blob object");
Junio C Hamanoc64ed702006-09-04 21:50:12 -070061 if (obj->flags & (UNINTERESTING | SEEN))
62 return;
Jeff Kingde1e67d2016-02-11 17:28:36 -050063
Jonathan Tandf11e192017-12-08 15:27:15 +000064 /*
65 * Pre-filter known-missing objects when explicitly requested.
66 * Otherwise, a missing object error message may be reported
67 * later (depending on other filtering criteria).
68 *
69 * Note that this "--exclude-promisor-objects" pre-filtering
70 * may cause the actual filter to report an incomplete list
71 * of missing objects.
72 */
Matthew DeVoref447a492018-08-13 11:14:28 -070073 if (ctx->revs->exclude_promisor_objects &&
Ævar Arnfjörð Bjarmasonbc726bd2023-03-28 15:58:50 +020074 !repo_has_object_file(the_repository, &obj->oid) &&
Jonathan Tandf11e192017-12-08 15:27:15 +000075 is_promisor_object(&obj->oid))
76 return;
77
Jeff Kingde1e67d2016-02-11 17:28:36 -050078 pathlen = path->len;
79 strbuf_addstr(path, name);
Matthew DeVore94301472019-06-27 15:54:05 -070080 r = list_objects_filter__filter_object(ctx->revs->repo,
81 LOFS_BLOB, obj,
82 path->buf, &path->buf[pathlen],
83 ctx->filter);
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +000084 if (r & LOFR_MARK_SEEN)
85 obj->flags |= SEEN;
86 if (r & LOFR_DO_SHOW)
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +000087 show_object(ctx, obj, path->buf);
Jeff Kingde1e67d2016-02-11 17:28:36 -050088 strbuf_setlen(path, pathlen);
Junio C Hamanoc64ed702006-09-04 21:50:12 -070089}
90
Matthew DeVoref447a492018-08-13 11:14:28 -070091static void process_tree(struct traversal_context *ctx,
Junio C Hamanoc64ed702006-09-04 21:50:12 -070092 struct tree *tree,
Elijah Newrencc5fa2f2010-12-17 20:26:47 +070093 struct strbuf *base,
Matthew DeVore92024892018-08-13 11:14:29 -070094 const char *name);
95
96static void process_tree_contents(struct traversal_context *ctx,
97 struct tree *tree,
98 struct strbuf *base)
Junio C Hamanoc64ed702006-09-04 21:50:12 -070099{
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700100 struct tree_desc desc;
101 struct name_entry entry;
Matthew DeVore92024892018-08-13 11:14:29 -0700102 enum interesting match = ctx->revs->diffopt.pathspec.nr == 0 ?
103 all_entries_interesting : entry_not_interesting;
104
Eric W. Biedermanefed6872023-10-01 21:40:28 -0500105 init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
Matthew DeVore92024892018-08-13 11:14:29 -0700106
107 while (tree_entry(&desc, &entry)) {
108 if (match != all_entries_interesting) {
Nguyễn Thái Ngọc Duy67022e02018-11-18 17:47:57 +0100109 match = tree_entry_interesting(ctx->revs->repo->index,
Junio C Hamano0ad927e2023-07-07 15:21:15 -0700110 &entry, base,
Matthew DeVore92024892018-08-13 11:14:29 -0700111 &ctx->revs->diffopt.pathspec);
112 if (match == all_entries_not_interesting)
113 break;
114 if (match == entry_not_interesting)
115 continue;
116 }
117
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700118 if (S_ISDIR(entry.mode)) {
brian m. carlsonea82b2a2019-01-15 00:39:44 +0000119 struct tree *t = lookup_tree(ctx->revs->repo, &entry.oid);
Taylor Blaub49e74e2019-04-09 19:13:19 -0700120 if (!t) {
121 die(_("entry '%s' in tree %s has tree mode, "
122 "but is not a tree"),
123 entry.path, oid_to_hex(&tree->object.oid));
124 }
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700125 t->object.flags |= NOT_USER_GIVEN;
Jeff King670a1da2023-08-31 02:22:03 -0400126 ctx->depth++;
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700127 process_tree(ctx, t, base, entry.path);
Jeff King670a1da2023-08-31 02:22:03 -0400128 ctx->depth--;
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700129 }
Matthew DeVore92024892018-08-13 11:14:29 -0700130 else if (S_ISGITLINK(entry.mode))
Jeff King00271482022-12-13 06:12:09 -0500131 ; /* ignore gitlink */
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700132 else {
brian m. carlsonea82b2a2019-01-15 00:39:44 +0000133 struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid);
Taylor Blau23c20442019-04-09 19:13:17 -0700134 if (!b) {
135 die(_("entry '%s' in tree %s has blob mode, "
136 "but is not a blob"),
137 entry.path, oid_to_hex(&tree->object.oid));
138 }
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700139 b->object.flags |= NOT_USER_GIVEN;
140 process_blob(ctx, b, base, entry.path);
141 }
Matthew DeVore92024892018-08-13 11:14:29 -0700142 }
143}
144
145static void process_tree(struct traversal_context *ctx,
146 struct tree *tree,
147 struct strbuf *base,
Matthew DeVoref447a492018-08-13 11:14:28 -0700148 const char *name)
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700149{
150 struct object *obj = &tree->object;
Matthew DeVoref447a492018-08-13 11:14:28 -0700151 struct rev_info *revs = ctx->revs;
Elijah Newrencc5fa2f2010-12-17 20:26:47 +0700152 int baselen = base->len;
Matthew DeVore94301472019-06-27 15:54:05 -0700153 enum list_objects_filter_result r;
Matthew DeVore7c0fe332018-10-05 14:31:23 -0700154 int failed_parse;
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700155
156 if (!revs->tree_objects)
157 return;
Martin Koeglera301b0c2008-02-18 21:47:56 +0100158 if (!obj)
159 die("bad tree object");
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700160 if (obj->flags & (UNINTERESTING | SEEN))
161 return;
Jeff Kingaa9ad6f2021-06-14 08:05:44 -0400162 if (revs->include_check_obj &&
163 !revs->include_check_obj(&tree->object, revs->include_check_data))
164 return;
Matthew DeVore7c0fe332018-10-05 14:31:23 -0700165
Jeff King670a1da2023-08-31 02:22:03 -0400166 if (ctx->depth > max_allowed_tree_depth)
167 die("exceeded maximum allowed tree depth");
168
Matthew DeVore7c0fe332018-10-05 14:31:23 -0700169 failed_parse = parse_tree_gently(tree, 1);
170 if (failed_parse) {
Vicent Marti2db1a432014-03-28 06:00:43 -0400171 if (revs->ignore_missing_links)
172 return;
Jonathan Tandf11e192017-12-08 15:27:15 +0000173
174 /*
175 * Pre-filter known-missing tree objects when explicitly
176 * requested. This may cause the actual filter to report
177 * an incomplete list of missing objects.
178 */
179 if (revs->exclude_promisor_objects &&
180 is_promisor_object(&obj->oid))
181 return;
182
Karthik Nayakca556f42023-10-26 12:11:07 +0200183 if (!revs->do_not_die_on_missing_objects)
Matthew DeVore7c0fe332018-10-05 14:31:23 -0700184 die("bad tree object %s", oid_to_hex(&obj->oid));
Vicent Marti2db1a432014-03-28 06:00:43 -0400185 }
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700186
Jeff King13528ab2016-02-11 17:26:18 -0500187 strbuf_addstr(base, name);
Matthew DeVore94301472019-06-27 15:54:05 -0700188 r = list_objects_filter__filter_object(ctx->revs->repo,
189 LOFS_BEGIN_TREE, obj,
190 base->buf, &base->buf[baselen],
191 ctx->filter);
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000192 if (r & LOFR_MARK_SEEN)
193 obj->flags |= SEEN;
194 if (r & LOFR_DO_SHOW)
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +0000195 show_object(ctx, obj, base->buf);
Jeff King13528ab2016-02-11 17:26:18 -0500196 if (base->len)
197 strbuf_addch(base, '/');
Elijah Newrencc5fa2f2010-12-17 20:26:47 +0700198
Matthew DeVore8b10a202018-10-17 17:39:15 -0700199 if (r & LOFR_SKIP_TREE)
200 trace_printf("Skipping contents of tree %s...\n", base->buf);
201 else if (!failed_parse)
Matthew DeVore7c0fe332018-10-05 14:31:23 -0700202 process_tree_contents(ctx, tree, base);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700203
Matthew DeVore94301472019-06-27 15:54:05 -0700204 r = list_objects_filter__filter_object(ctx->revs->repo,
205 LOFS_END_TREE, obj,
206 base->buf, &base->buf[baselen],
207 ctx->filter);
208 if (r & LOFR_MARK_SEEN)
209 obj->flags |= SEEN;
210 if (r & LOFR_DO_SHOW)
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +0000211 show_object(ctx, obj, base->buf);
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000212
Elijah Newrencc5fa2f2010-12-17 20:26:47 +0700213 strbuf_setlen(base, baselen);
Jeff King6e454b92013-06-05 18:37:39 -0400214 free_tree_buffer(tree);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700215}
216
Patrick Steinhardt628d81b2021-04-09 13:28:02 +0200217static void process_tag(struct traversal_context *ctx,
218 struct tag *tag,
219 const char *name)
220{
Patrick Steinhardt9a2a4f92021-04-12 15:37:35 +0200221 enum list_objects_filter_result r;
222
223 r = list_objects_filter__filter_object(ctx->revs->repo, LOFS_TAG,
224 &tag->object, NULL, NULL,
225 ctx->filter);
226 if (r & LOFR_MARK_SEEN)
227 tag->object.flags |= SEEN;
228 if (r & LOFR_DO_SHOW)
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +0000229 show_object(ctx, &tag->object, name);
Patrick Steinhardt628d81b2021-04-09 13:28:02 +0200230}
231
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700232static void mark_edge_parents_uninteresting(struct commit *commit,
233 struct rev_info *revs,
234 show_edge_fn show_edge)
235{
236 struct commit_list *parents;
237
238 for (parents = commit->parents; parents; parents = parents->next) {
239 struct commit *parent = parents->item;
240 if (!(parent->object.flags & UNINTERESTING))
241 continue;
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200242 mark_tree_uninteresting(revs->repo,
243 repo_get_commit_tree(the_repository, parent));
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700244 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
245 parent->object.flags |= SHOWN;
246 show_edge(parent);
247 }
248 }
249}
250
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800251static void add_edge_parents(struct commit *commit,
252 struct rev_info *revs,
253 show_edge_fn show_edge,
254 struct oidset *set)
255{
256 struct commit_list *parents;
257
258 for (parents = commit->parents; parents; parents = parents->next) {
259 struct commit *parent = parents->item;
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200260 struct tree *tree = repo_get_commit_tree(the_repository,
261 parent);
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800262
263 if (!tree)
264 continue;
265
266 oidset_insert(set, &tree->object.oid);
267
268 if (!(parent->object.flags & UNINTERESTING))
269 continue;
270 tree->object.flags |= UNINTERESTING;
271
272 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
273 parent->object.flags |= SHOWN;
274 show_edge(parent);
275 }
276 }
277}
278
279void mark_edges_uninteresting(struct rev_info *revs,
280 show_edge_fn show_edge,
281 int sparse)
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700282{
Nguyễn Thái Ngọc Duye76a5fb2013-08-16 16:52:06 +0700283 struct commit_list *list;
Nguyễn Thái Ngọc Duyfbd4a702013-08-16 16:52:07 +0700284 int i;
285
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800286 if (sparse) {
287 struct oidset set;
288 oidset_init(&set, 16);
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700289
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800290 for (list = revs->commits; list; list = list->next) {
291 struct commit *commit = list->item;
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200292 struct tree *tree = repo_get_commit_tree(the_repository,
293 commit);
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800294
295 if (commit->object.flags & UNINTERESTING)
296 tree->object.flags |= UNINTERESTING;
297
298 oidset_insert(&set, &tree->object.oid);
299 add_edge_parents(commit, revs, show_edge, &set);
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700300 }
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800301
302 mark_trees_uninteresting_sparse(revs->repo, &set);
303 oidset_clear(&set);
304 } else {
305 for (list = revs->commits; list; list = list->next) {
306 struct commit *commit = list->item;
307 if (commit->object.flags & UNINTERESTING) {
308 mark_tree_uninteresting(revs->repo,
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200309 repo_get_commit_tree(the_repository, commit));
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800310 if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
311 commit->object.flags |= SHOWN;
312 show_edge(commit);
313 }
314 continue;
315 }
316 mark_edge_parents_uninteresting(commit, revs, show_edge);
317 }
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700318 }
Derrick Stolee4f6d26b2019-01-16 10:25:58 -0800319
brian m. carlson1684c1b2014-12-24 23:05:39 +0000320 if (revs->edge_hint_aggressive) {
Jeff King200abe72014-01-20 21:25:40 -0500321 for (i = 0; i < revs->cmdline.nr; i++) {
322 struct object *obj = revs->cmdline.rev[i].item;
323 struct commit *commit = (struct commit *)obj;
324 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
325 continue;
Nguyễn Thái Ngọc Duyb3c7eef2018-09-21 17:57:39 +0200326 mark_tree_uninteresting(revs->repo,
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200327 repo_get_commit_tree(the_repository, commit));
Jeff King200abe72014-01-20 21:25:40 -0500328 if (!(obj->flags & SHOWN)) {
329 obj->flags |= SHOWN;
330 show_edge(commit);
331 }
Nguyễn Thái Ngọc Duyfbd4a702013-08-16 16:52:07 +0700332 }
333 }
Junio C Hamano8d1d8f82006-09-06 01:42:23 -0700334}
335
Linus Torvalds8d2dfc42009-04-10 17:27:58 -0700336static void add_pending_tree(struct rev_info *revs, struct tree *tree)
337{
338 add_pending_object(revs, &tree->object, "");
339}
340
Teng Longb3e36df2021-08-12 16:59:31 +0800341static void traverse_non_commits(struct traversal_context *ctx,
342 struct strbuf *base)
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700343{
344 int i;
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700345
Stefan Beller91904f52017-11-02 12:41:43 -0700346 assert(base->len == 0);
347
Matthew DeVoref447a492018-08-13 11:14:28 -0700348 for (i = 0; i < ctx->revs->pending.nr; i++) {
349 struct object_array_entry *pending = ctx->revs->pending.objects + i;
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700350 struct object *obj = pending->item;
351 const char *name = pending->name;
Jeff King20739492014-10-15 18:43:19 -0400352 const char *path = pending->path;
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700353 if (obj->flags & (UNINTERESTING | SEEN))
354 continue;
355 if (obj->type == OBJ_TAG) {
Patrick Steinhardt628d81b2021-04-09 13:28:02 +0200356 process_tag(ctx, (struct tag *)obj, name);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700357 continue;
358 }
Jeff King20739492014-10-15 18:43:19 -0400359 if (!path)
360 path = "";
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700361 if (obj->type == OBJ_TREE) {
Jeff King670a1da2023-08-31 02:22:03 -0400362 ctx->depth = 0;
Matthew DeVoref447a492018-08-13 11:14:28 -0700363 process_tree(ctx, (struct tree *)obj, base, path);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700364 continue;
365 }
366 if (obj->type == OBJ_BLOB) {
Matthew DeVoref447a492018-08-13 11:14:28 -0700367 process_blob(ctx, (struct blob *)obj, base, path);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700368 continue;
369 }
370 die("unknown pending object %s (%s)",
brian m. carlsonf2fd0762015-11-10 02:22:28 +0000371 oid_to_hex(&obj->oid), name);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700372 }
Matthew DeVoref447a492018-08-13 11:14:28 -0700373 object_array_clear(&ctx->revs->pending);
Stefan Beller91904f52017-11-02 12:41:43 -0700374}
375
Matthew DeVoref447a492018-08-13 11:14:28 -0700376static void do_traverse(struct traversal_context *ctx)
Stefan Beller91904f52017-11-02 12:41:43 -0700377{
378 struct commit *commit;
379 struct strbuf csp; /* callee's scratch pad */
380 strbuf_init(&csp, PATH_MAX);
381
Matthew DeVoref447a492018-08-13 11:14:28 -0700382 while ((commit = get_revision(ctx->revs)) != NULL) {
Patrick Steinhardt9a2a4f92021-04-12 15:37:35 +0200383 enum list_objects_filter_result r;
384
385 r = list_objects_filter__filter_object(ctx->revs->repo,
386 LOFS_COMMIT, &commit->object,
387 NULL, NULL, ctx->filter);
388
Stefan Beller91904f52017-11-02 12:41:43 -0700389 /*
390 * an uninteresting boundary commit may not have its tree
391 * parsed yet, but we are not going to show them anyway
392 */
Jeff King72ed80c2019-09-11 21:11:37 -0400393 if (!ctx->revs->tree_objects)
394 ; /* do not bother loading tree */
Karthik Nayak98309262023-10-27 09:59:29 +0200395 else if (ctx->revs->do_not_die_on_missing_objects &&
396 oidset_contains(&ctx->revs->missing_commits, &commit->object.oid))
397 ;
Ævar Arnfjörð Bjarmasonecb50912023-03-28 15:58:48 +0200398 else if (repo_get_commit_tree(the_repository, commit)) {
399 struct tree *tree = repo_get_commit_tree(the_repository,
400 commit);
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700401 tree->object.flags |= NOT_USER_GIVEN;
402 add_pending_tree(ctx->revs, tree);
Jeff King97dd5122019-04-09 19:13:25 -0700403 } else if (commit->object.parsed) {
404 die(_("unable to load root tree for commit %s"),
405 oid_to_hex(&commit->object.oid));
Matthew DeVore99c9aa92018-10-05 14:31:24 -0700406 }
Patrick Steinhardt9a2a4f92021-04-12 15:37:35 +0200407
408 if (r & LOFR_MARK_SEEN)
409 commit->object.flags |= SEEN;
410 if (r & LOFR_DO_SHOW)
Ævar Arnfjörð Bjarmason4f33a632022-03-09 16:01:38 +0000411 show_commit(ctx, commit);
Stefan Bellerce5b6f92017-11-15 18:00:35 -0800412
Matthew DeVoref447a492018-08-13 11:14:28 -0700413 if (ctx->revs->tree_blobs_in_commit_order)
Stefan Bellerce5b6f92017-11-15 18:00:35 -0800414 /*
415 * NEEDSWORK: Adding the tree and then flushing it here
416 * needs a reallocation for each commit. Can we pass the
417 * tree directory without allocation churn?
418 */
Teng Longb3e36df2021-08-12 16:59:31 +0800419 traverse_non_commits(ctx, &csp);
Stefan Beller91904f52017-11-02 12:41:43 -0700420 }
Teng Longb3e36df2021-08-12 16:59:31 +0800421 traverse_non_commits(ctx, &csp);
Stefan Beller91904f52017-11-02 12:41:43 -0700422 strbuf_release(&csp);
Junio C Hamanoc64ed702006-09-04 21:50:12 -0700423}
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000424
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000425void traverse_commit_list_filtered(
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000426 struct rev_info *revs,
427 show_commit_fn show_commit,
428 show_object_fn show_object,
429 void *show_data,
430 struct oidset *omitted)
431{
Derrick Stolee3e0370a2022-03-09 16:01:36 +0000432 struct traversal_context ctx = {
433 .revs = revs,
434 .show_object = show_object,
435 .show_commit = show_commit,
436 .show_data = show_data,
437 };
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000438
Derrick Stolee3e0370a2022-03-09 16:01:36 +0000439 if (revs->filter.choice)
440 ctx.filter = list_objects_filter__init(omitted, &revs->filter);
441
Matthew DeVoref447a492018-08-13 11:14:28 -0700442 do_traverse(&ctx);
Derrick Stolee3e0370a2022-03-09 16:01:36 +0000443
444 if (ctx.filter)
445 list_objects_filter__free(ctx.filter);
Jeff Hostetler25ec7bc2017-11-21 20:58:50 +0000446}