9 #include "list-objects.h"
11 static void process_blob(struct rev_info *revs,
14 struct name_path *path,
17 struct object *obj = &blob->object;
19 if (!revs->blob_objects)
22 die("bad blob object");
23 if (obj->flags & (UNINTERESTING | SEEN))
26 show(obj, path, name);
30 * Processing a gitlink entry currently does nothing, since
31 * we do not recurse into the subproject.
33 * We *could* eventually add a flag that actually does that,
34 * which would involve:
35 * - is the subproject actually checked out?
36 * - if so, see if the subproject has already been added
37 * to the alternates list, and add it if not.
38 * - process the commit (or tag) the gitlink points to
41 * However, it's unclear whether there is really ever any
42 * reason to see superprojects and subprojects as such a
43 * "unified" object pool (potentially resulting in a totally
44 * humongous pack - avoiding which was the whole point of
45 * having gitlinks in the first place!).
47 * So for now, there is just a note that we *could* follow
48 * the link, and how to do it. Whether it necessarily makes
49 * any sense what-so-ever to ever do that is another issue.
51 static void process_gitlink(struct rev_info *revs,
52 const unsigned char *sha1,
54 struct name_path *path,
60 static void process_tree(struct rev_info *revs,
63 struct name_path *path,
67 struct object *obj = &tree->object;
68 struct tree_desc desc;
69 struct name_entry entry;
71 int all_interesting = (revs->diffopt.pathspec.nr == 0);
72 int baselen = base->len;
74 if (!revs->tree_objects)
77 die("bad tree object");
78 if (obj->flags & (UNINTERESTING | SEEN))
80 if (parse_tree(tree) < 0)
81 die("bad tree object %s", sha1_to_hex(obj->sha1));
83 show(obj, path, name);
86 me.elem_len = strlen(name);
88 if (!all_interesting) {
89 strbuf_addstr(base, name);
91 strbuf_addch(base, '/');
94 init_tree_desc(&desc, tree->buffer, tree->size);
96 while (tree_entry(&desc, &entry)) {
97 if (!all_interesting) {
98 int showit = tree_entry_interesting(&entry,
100 &revs->diffopt.pathspec);
106 else if (showit == 2)
110 if (S_ISDIR(entry.mode))
112 lookup_tree(entry.sha1),
113 show, &me, base, entry.path);
114 else if (S_ISGITLINK(entry.mode))
115 process_gitlink(revs, entry.sha1,
116 show, &me, entry.path);
119 lookup_blob(entry.sha1),
120 show, &me, entry.path);
122 strbuf_setlen(base, baselen);
127 static void mark_edge_parents_uninteresting(struct commit *commit,
128 struct rev_info *revs,
129 show_edge_fn show_edge)
131 struct commit_list *parents;
133 for (parents = commit->parents; parents; parents = parents->next) {
134 struct commit *parent = parents->item;
135 if (!(parent->object.flags & UNINTERESTING))
137 mark_tree_uninteresting(parent->tree);
138 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
139 parent->object.flags |= SHOWN;
145 void mark_edges_uninteresting(struct commit_list *list,
146 struct rev_info *revs,
147 show_edge_fn show_edge)
149 for ( ; list; list = list->next) {
150 struct commit *commit = list->item;
152 if (commit->object.flags & UNINTERESTING) {
153 mark_tree_uninteresting(commit->tree);
156 mark_edge_parents_uninteresting(commit, revs, show_edge);
160 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
162 add_pending_object(revs, &tree->object, "");
165 void traverse_commit_list(struct rev_info *revs,
166 show_commit_fn show_commit,
167 show_object_fn show_object,
171 struct commit *commit;
174 strbuf_init(&base, PATH_MAX);
175 while ((commit = get_revision(revs)) != NULL) {
177 * an uninteresting boundary commit may not have its tree
178 * parsed yet, but we are not going to show them anyway
181 add_pending_tree(revs, commit->tree);
182 show_commit(commit, data);
184 for (i = 0; i < revs->pending.nr; i++) {
185 struct object_array_entry *pending = revs->pending.objects + i;
186 struct object *obj = pending->item;
187 const char *name = pending->name;
188 if (obj->flags & (UNINTERESTING | SEEN))
190 if (obj->type == OBJ_TAG) {
192 show_object(obj, NULL, name);
195 if (obj->type == OBJ_TREE) {
196 process_tree(revs, (struct tree *)obj, show_object,
200 if (obj->type == OBJ_BLOB) {
201 process_blob(revs, (struct blob *)obj, show_object,
205 die("unknown pending object %s (%s)",
206 sha1_to_hex(obj->sha1), name);
208 if (revs->pending.nr) {
209 free(revs->pending.objects);
210 revs->pending.nr = 0;
211 revs->pending.alloc = 0;
212 revs->pending.objects = NULL;
214 strbuf_release(&base);