9 #include "list-objects.h"
11 static void process_blob(struct rev_info *revs,
18 struct object *obj = &blob->object;
21 if (!revs->blob_objects)
24 die("bad blob object");
25 if (obj->flags & (UNINTERESTING | SEEN))
30 strbuf_addstr(path, name);
31 show(obj, path->buf, cb_data);
32 strbuf_setlen(path, pathlen);
36 * Processing a gitlink entry currently does nothing, since
37 * we do not recurse into the subproject.
39 * We *could* eventually add a flag that actually does that,
40 * which would involve:
41 * - is the subproject actually checked out?
42 * - if so, see if the subproject has already been added
43 * to the alternates list, and add it if not.
44 * - process the commit (or tag) the gitlink points to
47 * However, it's unclear whether there is really ever any
48 * reason to see superprojects and subprojects as such a
49 * "unified" object pool (potentially resulting in a totally
50 * humongous pack - avoiding which was the whole point of
51 * having gitlinks in the first place!).
53 * So for now, there is just a note that we *could* follow
54 * the link, and how to do it. Whether it necessarily makes
55 * any sense what-so-ever to ever do that is another issue.
57 static void process_gitlink(struct rev_info *revs,
58 const unsigned char *sha1,
67 static void process_tree(struct rev_info *revs,
74 struct object *obj = &tree->object;
75 struct tree_desc desc;
76 struct name_entry entry;
77 enum interesting match = revs->diffopt.pathspec.nr == 0 ?
78 all_entries_interesting: entry_not_interesting;
79 int baselen = base->len;
81 if (!revs->tree_objects)
84 die("bad tree object");
85 if (obj->flags & (UNINTERESTING | SEEN))
87 if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
88 if (revs->ignore_missing_links)
90 die("bad tree object %s", oid_to_hex(&obj->oid));
94 strbuf_addstr(base, name);
95 show(obj, base->buf, cb_data);
97 strbuf_addch(base, '/');
99 init_tree_desc(&desc, tree->buffer, tree->size);
101 while (tree_entry(&desc, &entry)) {
102 if (match != all_entries_interesting) {
103 match = tree_entry_interesting(&entry, base, 0,
104 &revs->diffopt.pathspec);
105 if (match == all_entries_not_interesting)
107 if (match == entry_not_interesting)
111 if (S_ISDIR(entry.mode))
113 lookup_tree(entry.oid),
114 show, base, entry.path,
116 else if (S_ISGITLINK(entry.mode))
117 process_gitlink(revs, entry.oid->hash,
118 show, base, entry.path,
122 lookup_blob(entry.oid),
123 show, base, entry.path,
126 strbuf_setlen(base, baselen);
127 free_tree_buffer(tree);
130 static void mark_edge_parents_uninteresting(struct commit *commit,
131 struct rev_info *revs,
132 show_edge_fn show_edge)
134 struct commit_list *parents;
136 for (parents = commit->parents; parents; parents = parents->next) {
137 struct commit *parent = parents->item;
138 if (!(parent->object.flags & UNINTERESTING))
140 mark_tree_uninteresting(parent->tree);
141 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
142 parent->object.flags |= SHOWN;
148 void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
150 struct commit_list *list;
153 for (list = revs->commits; list; list = list->next) {
154 struct commit *commit = list->item;
156 if (commit->object.flags & UNINTERESTING) {
157 mark_tree_uninteresting(commit->tree);
158 if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
159 commit->object.flags |= SHOWN;
164 mark_edge_parents_uninteresting(commit, revs, show_edge);
166 if (revs->edge_hint_aggressive) {
167 for (i = 0; i < revs->cmdline.nr; i++) {
168 struct object *obj = revs->cmdline.rev[i].item;
169 struct commit *commit = (struct commit *)obj;
170 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
172 mark_tree_uninteresting(commit->tree);
173 if (!(obj->flags & SHOWN)) {
181 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
183 add_pending_object(revs, &tree->object, "");
186 static void traverse_trees_and_blobs(struct rev_info *revs,
188 show_object_fn show_object,
193 assert(base->len == 0);
195 for (i = 0; i < revs->pending.nr; i++) {
196 struct object_array_entry *pending = revs->pending.objects + i;
197 struct object *obj = pending->item;
198 const char *name = pending->name;
199 const char *path = pending->path;
200 if (obj->flags & (UNINTERESTING | SEEN))
202 if (obj->type == OBJ_TAG) {
204 show_object(obj, name, data);
209 if (obj->type == OBJ_TREE) {
210 process_tree(revs, (struct tree *)obj, show_object,
214 if (obj->type == OBJ_BLOB) {
215 process_blob(revs, (struct blob *)obj, show_object,
219 die("unknown pending object %s (%s)",
220 oid_to_hex(&obj->oid), name);
222 object_array_clear(&revs->pending);
225 void traverse_commit_list(struct rev_info *revs,
226 show_commit_fn show_commit,
227 show_object_fn show_object,
230 struct commit *commit;
231 struct strbuf csp; /* callee's scratch pad */
232 strbuf_init(&csp, PATH_MAX);
234 while ((commit = get_revision(revs)) != NULL) {
236 * an uninteresting boundary commit may not have its tree
237 * parsed yet, but we are not going to show them anyway
240 add_pending_tree(revs, commit->tree);
241 show_commit(commit, data);
243 if (revs->tree_blobs_in_commit_order)
245 * NEEDSWORK: Adding the tree and then flushing it here
246 * needs a reallocation for each commit. Can we pass the
247 * tree directory without allocation churn?
249 traverse_trees_and_blobs(revs, &csp, show_object, data);
251 traverse_trees_and_blobs(revs, &csp, show_object, data);
253 strbuf_release(&csp);