9 #include "list-objects.h"
10 #include "list-objects-filter.h"
11 #include "list-objects-filter-options.h"
13 static void process_blob(struct rev_info *revs,
19 filter_object_fn filter_fn,
22 struct object *obj = &blob->object;
24 enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
26 if (!revs->blob_objects)
29 die("bad blob object");
30 if (obj->flags & (UNINTERESTING | SEEN))
34 strbuf_addstr(path, name);
36 r = filter_fn(LOFS_BLOB, obj,
37 path->buf, &path->buf[pathlen],
39 if (r & LOFR_MARK_SEEN)
42 show(obj, path->buf, cb_data);
43 strbuf_setlen(path, pathlen);
47 * Processing a gitlink entry currently does nothing, since
48 * we do not recurse into the subproject.
50 * We *could* eventually add a flag that actually does that,
51 * which would involve:
52 * - is the subproject actually checked out?
53 * - if so, see if the subproject has already been added
54 * to the alternates list, and add it if not.
55 * - process the commit (or tag) the gitlink points to
58 * However, it's unclear whether there is really ever any
59 * reason to see superprojects and subprojects as such a
60 * "unified" object pool (potentially resulting in a totally
61 * humongous pack - avoiding which was the whole point of
62 * having gitlinks in the first place!).
64 * So for now, there is just a note that we *could* follow
65 * the link, and how to do it. Whether it necessarily makes
66 * any sense what-so-ever to ever do that is another issue.
68 static void process_gitlink(struct rev_info *revs,
69 const unsigned char *sha1,
78 static void process_tree(struct rev_info *revs,
84 filter_object_fn filter_fn,
87 struct object *obj = &tree->object;
88 struct tree_desc desc;
89 struct name_entry entry;
90 enum interesting match = revs->diffopt.pathspec.nr == 0 ?
91 all_entries_interesting: entry_not_interesting;
92 int baselen = base->len;
93 enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
95 if (!revs->tree_objects)
98 die("bad tree object");
99 if (obj->flags & (UNINTERESTING | SEEN))
101 if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
102 if (revs->ignore_missing_links)
104 die("bad tree object %s", oid_to_hex(&obj->oid));
107 strbuf_addstr(base, name);
109 r = filter_fn(LOFS_BEGIN_TREE, obj,
110 base->buf, &base->buf[baselen],
112 if (r & LOFR_MARK_SEEN)
114 if (r & LOFR_DO_SHOW)
115 show(obj, base->buf, cb_data);
117 strbuf_addch(base, '/');
119 init_tree_desc(&desc, tree->buffer, tree->size);
121 while (tree_entry(&desc, &entry)) {
122 if (match != all_entries_interesting) {
123 match = tree_entry_interesting(&entry, base, 0,
124 &revs->diffopt.pathspec);
125 if (match == all_entries_not_interesting)
127 if (match == entry_not_interesting)
131 if (S_ISDIR(entry.mode))
133 lookup_tree(entry.oid),
134 show, base, entry.path,
135 cb_data, filter_fn, filter_data);
136 else if (S_ISGITLINK(entry.mode))
137 process_gitlink(revs, entry.oid->hash,
138 show, base, entry.path,
142 lookup_blob(entry.oid),
143 show, base, entry.path,
144 cb_data, filter_fn, filter_data);
148 r = filter_fn(LOFS_END_TREE, obj,
149 base->buf, &base->buf[baselen],
151 if (r & LOFR_MARK_SEEN)
153 if (r & LOFR_DO_SHOW)
154 show(obj, base->buf, cb_data);
157 strbuf_setlen(base, baselen);
158 free_tree_buffer(tree);
161 static void mark_edge_parents_uninteresting(struct commit *commit,
162 struct rev_info *revs,
163 show_edge_fn show_edge)
165 struct commit_list *parents;
167 for (parents = commit->parents; parents; parents = parents->next) {
168 struct commit *parent = parents->item;
169 if (!(parent->object.flags & UNINTERESTING))
171 mark_tree_uninteresting(parent->tree);
172 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
173 parent->object.flags |= SHOWN;
179 void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
181 struct commit_list *list;
184 for (list = revs->commits; list; list = list->next) {
185 struct commit *commit = list->item;
187 if (commit->object.flags & UNINTERESTING) {
188 mark_tree_uninteresting(commit->tree);
189 if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
190 commit->object.flags |= SHOWN;
195 mark_edge_parents_uninteresting(commit, revs, show_edge);
197 if (revs->edge_hint_aggressive) {
198 for (i = 0; i < revs->cmdline.nr; i++) {
199 struct object *obj = revs->cmdline.rev[i].item;
200 struct commit *commit = (struct commit *)obj;
201 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
203 mark_tree_uninteresting(commit->tree);
204 if (!(obj->flags & SHOWN)) {
212 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
214 add_pending_object(revs, &tree->object, "");
217 static void do_traverse(struct rev_info *revs,
218 show_commit_fn show_commit,
219 show_object_fn show_object,
221 filter_object_fn filter_fn,
225 struct commit *commit;
228 strbuf_init(&base, PATH_MAX);
229 while ((commit = get_revision(revs)) != NULL) {
231 * an uninteresting boundary commit may not have its tree
232 * parsed yet, but we are not going to show them anyway
235 add_pending_tree(revs, commit->tree);
236 show_commit(commit, show_data);
238 for (i = 0; i < revs->pending.nr; i++) {
239 struct object_array_entry *pending = revs->pending.objects + i;
240 struct object *obj = pending->item;
241 const char *name = pending->name;
242 const char *path = pending->path;
243 if (obj->flags & (UNINTERESTING | SEEN))
245 if (obj->type == OBJ_TAG) {
247 show_object(obj, name, show_data);
252 if (obj->type == OBJ_TREE) {
253 process_tree(revs, (struct tree *)obj, show_object,
254 &base, path, show_data,
255 filter_fn, filter_data);
258 if (obj->type == OBJ_BLOB) {
259 process_blob(revs, (struct blob *)obj, show_object,
260 &base, path, show_data,
261 filter_fn, filter_data);
264 die("unknown pending object %s (%s)",
265 oid_to_hex(&obj->oid), name);
267 object_array_clear(&revs->pending);
268 strbuf_release(&base);
271 void traverse_commit_list(struct rev_info *revs,
272 show_commit_fn show_commit,
273 show_object_fn show_object,
276 do_traverse(revs, show_commit, show_object, show_data, NULL, NULL);
279 void traverse_commit_list_filtered(
280 struct list_objects_filter_options *filter_options,
281 struct rev_info *revs,
282 show_commit_fn show_commit,
283 show_object_fn show_object,
285 struct oidset *omitted)
287 filter_object_fn filter_fn = NULL;
288 filter_free_fn filter_free_fn = NULL;
289 void *filter_data = NULL;
291 filter_data = list_objects_filter__init(omitted, filter_options,
292 &filter_fn, &filter_free_fn);
293 do_traverse(revs, show_commit, show_object, show_data,
294 filter_fn, filter_data);
295 if (filter_data && filter_free_fn)
296 filter_free_fn(filter_data);