9 #include "list-objects.h"
10 #include "list-objects-filter.h"
11 #include "list-objects-filter-options.h"
14 static void process_blob(struct rev_info *revs,
20 filter_object_fn filter_fn,
23 struct object *obj = &blob->object;
25 enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
27 if (!revs->blob_objects)
30 die("bad blob object");
31 if (obj->flags & (UNINTERESTING | SEEN))
35 * Pre-filter known-missing objects when explicitly requested.
36 * Otherwise, a missing object error message may be reported
37 * later (depending on other filtering criteria).
39 * Note that this "--exclude-promisor-objects" pre-filtering
40 * may cause the actual filter to report an incomplete list
43 if (revs->exclude_promisor_objects &&
44 !has_object_file(&obj->oid) &&
45 is_promisor_object(&obj->oid))
49 strbuf_addstr(path, name);
51 r = filter_fn(LOFS_BLOB, obj,
52 path->buf, &path->buf[pathlen],
54 if (r & LOFR_MARK_SEEN)
57 show(obj, path->buf, cb_data);
58 strbuf_setlen(path, pathlen);
62 * Processing a gitlink entry currently does nothing, since
63 * we do not recurse into the subproject.
65 * We *could* eventually add a flag that actually does that,
66 * which would involve:
67 * - is the subproject actually checked out?
68 * - if so, see if the subproject has already been added
69 * to the alternates list, and add it if not.
70 * - process the commit (or tag) the gitlink points to
73 * However, it's unclear whether there is really ever any
74 * reason to see superprojects and subprojects as such a
75 * "unified" object pool (potentially resulting in a totally
76 * humongous pack - avoiding which was the whole point of
77 * having gitlinks in the first place!).
79 * So for now, there is just a note that we *could* follow
80 * the link, and how to do it. Whether it necessarily makes
81 * any sense what-so-ever to ever do that is another issue.
83 static void process_gitlink(struct rev_info *revs,
84 const unsigned char *sha1,
93 static void process_tree(struct rev_info *revs,
99 filter_object_fn filter_fn,
102 struct object *obj = &tree->object;
103 struct tree_desc desc;
104 struct name_entry entry;
105 enum interesting match = revs->diffopt.pathspec.nr == 0 ?
106 all_entries_interesting: entry_not_interesting;
107 int baselen = base->len;
108 enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
109 int gently = revs->ignore_missing_links ||
110 revs->exclude_promisor_objects;
112 if (!revs->tree_objects)
115 die("bad tree object");
116 if (obj->flags & (UNINTERESTING | SEEN))
118 if (parse_tree_gently(tree, gently) < 0) {
119 if (revs->ignore_missing_links)
123 * Pre-filter known-missing tree objects when explicitly
124 * requested. This may cause the actual filter to report
125 * an incomplete list of missing objects.
127 if (revs->exclude_promisor_objects &&
128 is_promisor_object(&obj->oid))
131 die("bad tree object %s", oid_to_hex(&obj->oid));
134 strbuf_addstr(base, name);
136 r = filter_fn(LOFS_BEGIN_TREE, obj,
137 base->buf, &base->buf[baselen],
139 if (r & LOFR_MARK_SEEN)
141 if (r & LOFR_DO_SHOW)
142 show(obj, base->buf, cb_data);
144 strbuf_addch(base, '/');
146 init_tree_desc(&desc, tree->buffer, tree->size);
148 while (tree_entry(&desc, &entry)) {
149 if (match != all_entries_interesting) {
150 match = tree_entry_interesting(&entry, base, 0,
151 &revs->diffopt.pathspec);
152 if (match == all_entries_not_interesting)
154 if (match == entry_not_interesting)
158 if (S_ISDIR(entry.mode))
160 lookup_tree(entry.oid),
161 show, base, entry.path,
162 cb_data, filter_fn, filter_data);
163 else if (S_ISGITLINK(entry.mode))
164 process_gitlink(revs, entry.oid->hash,
165 show, base, entry.path,
169 lookup_blob(entry.oid),
170 show, base, entry.path,
171 cb_data, filter_fn, filter_data);
175 r = filter_fn(LOFS_END_TREE, obj,
176 base->buf, &base->buf[baselen],
178 if (r & LOFR_MARK_SEEN)
180 if (r & LOFR_DO_SHOW)
181 show(obj, base->buf, cb_data);
184 strbuf_setlen(base, baselen);
185 free_tree_buffer(tree);
188 static void mark_edge_parents_uninteresting(struct commit *commit,
189 struct rev_info *revs,
190 show_edge_fn show_edge)
192 struct commit_list *parents;
194 for (parents = commit->parents; parents; parents = parents->next) {
195 struct commit *parent = parents->item;
196 if (!(parent->object.flags & UNINTERESTING))
198 mark_tree_uninteresting(parent->tree);
199 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
200 parent->object.flags |= SHOWN;
206 void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
208 struct commit_list *list;
211 for (list = revs->commits; list; list = list->next) {
212 struct commit *commit = list->item;
214 if (commit->object.flags & UNINTERESTING) {
215 mark_tree_uninteresting(commit->tree);
216 if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
217 commit->object.flags |= SHOWN;
222 mark_edge_parents_uninteresting(commit, revs, show_edge);
224 if (revs->edge_hint_aggressive) {
225 for (i = 0; i < revs->cmdline.nr; i++) {
226 struct object *obj = revs->cmdline.rev[i].item;
227 struct commit *commit = (struct commit *)obj;
228 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
230 mark_tree_uninteresting(commit->tree);
231 if (!(obj->flags & SHOWN)) {
239 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
241 add_pending_object(revs, &tree->object, "");
244 static void do_traverse(struct rev_info *revs,
245 show_commit_fn show_commit,
246 show_object_fn show_object,
248 filter_object_fn filter_fn,
252 struct commit *commit;
255 strbuf_init(&base, PATH_MAX);
256 while ((commit = get_revision(revs)) != NULL) {
258 * an uninteresting boundary commit may not have its tree
259 * parsed yet, but we are not going to show them anyway
262 add_pending_tree(revs, commit->tree);
263 show_commit(commit, show_data);
265 for (i = 0; i < revs->pending.nr; i++) {
266 struct object_array_entry *pending = revs->pending.objects + i;
267 struct object *obj = pending->item;
268 const char *name = pending->name;
269 const char *path = pending->path;
270 if (obj->flags & (UNINTERESTING | SEEN))
272 if (obj->type == OBJ_TAG) {
274 show_object(obj, name, show_data);
279 if (obj->type == OBJ_TREE) {
280 process_tree(revs, (struct tree *)obj, show_object,
281 &base, path, show_data,
282 filter_fn, filter_data);
285 if (obj->type == OBJ_BLOB) {
286 process_blob(revs, (struct blob *)obj, show_object,
287 &base, path, show_data,
288 filter_fn, filter_data);
291 die("unknown pending object %s (%s)",
292 oid_to_hex(&obj->oid), name);
294 object_array_clear(&revs->pending);
295 strbuf_release(&base);
298 void traverse_commit_list(struct rev_info *revs,
299 show_commit_fn show_commit,
300 show_object_fn show_object,
303 do_traverse(revs, show_commit, show_object, show_data, NULL, NULL);
306 void traverse_commit_list_filtered(
307 struct list_objects_filter_options *filter_options,
308 struct rev_info *revs,
309 show_commit_fn show_commit,
310 show_object_fn show_object,
312 struct oidset *omitted)
314 filter_object_fn filter_fn = NULL;
315 filter_free_fn filter_free_fn = NULL;
316 void *filter_data = NULL;
318 filter_data = list_objects_filter__init(omitted, filter_options,
319 &filter_fn, &filter_free_fn);
320 do_traverse(revs, show_commit, show_object, show_data,
321 filter_fn, filter_data);
322 if (filter_data && filter_free_fn)
323 filter_free_fn(filter_data);