9 #include "list-objects.h"
11 static void process_blob(struct rev_info
*revs
,
14 struct name_path
*path
,
18 struct object
*obj
= &blob
->object
;
20 if (!revs
->blob_objects
)
23 die("bad blob object");
24 if (obj
->flags
& (UNINTERESTING
| SEEN
))
27 show(obj
, path
, name
, cb_data
);
31 * Processing a gitlink entry currently does nothing, since
32 * we do not recurse into the subproject.
34 * We *could* eventually add a flag that actually does that,
35 * which would involve:
36 * - is the subproject actually checked out?
37 * - if so, see if the subproject has already been added
38 * to the alternates list, and add it if not.
39 * - process the commit (or tag) the gitlink points to
42 * However, it's unclear whether there is really ever any
43 * reason to see superprojects and subprojects as such a
44 * "unified" object pool (potentially resulting in a totally
45 * humongous pack - avoiding which was the whole point of
46 * having gitlinks in the first place!).
48 * So for now, there is just a note that we *could* follow
49 * the link, and how to do it. Whether it necessarily makes
50 * any sense what-so-ever to ever do that is another issue.
52 static void process_gitlink(struct rev_info
*revs
,
53 const unsigned char *sha1
,
55 struct name_path
*path
,
62 static void process_tree(struct rev_info
*revs
,
65 struct name_path
*path
,
70 struct object
*obj
= &tree
->object
;
71 struct tree_desc desc
;
72 struct name_entry entry
;
74 enum interesting match
= revs
->diffopt
.pathspec
.nr
== 0 ?
75 all_entries_interesting
: entry_not_interesting
;
76 int baselen
= base
->len
;
78 if (!revs
->tree_objects
)
81 die("bad tree object");
82 if (obj
->flags
& (UNINTERESTING
| SEEN
))
84 if (parse_tree(tree
) < 0) {
85 if (revs
->ignore_missing_links
)
87 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
90 show(obj
, path
, name
, cb_data
);
93 me
.elem_len
= strlen(name
);
96 strbuf_addstr(base
, name
);
98 strbuf_addch(base
, '/');
101 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
103 while (tree_entry(&desc
, &entry
)) {
104 if (match
!= all_entries_interesting
) {
105 match
= tree_entry_interesting(&entry
, base
, 0,
106 &revs
->diffopt
.pathspec
);
107 if (match
== all_entries_not_interesting
)
109 if (match
== entry_not_interesting
)
113 if (S_ISDIR(entry
.mode
))
115 lookup_tree(entry
.sha1
),
116 show
, &me
, base
, entry
.path
,
118 else if (S_ISGITLINK(entry
.mode
))
119 process_gitlink(revs
, entry
.sha1
,
120 show
, &me
, entry
.path
,
124 lookup_blob(entry
.sha1
),
125 show
, &me
, entry
.path
,
128 strbuf_setlen(base
, baselen
);
129 free_tree_buffer(tree
);
132 static void mark_edge_parents_uninteresting(struct commit
*commit
,
133 struct rev_info
*revs
,
134 show_edge_fn show_edge
)
136 struct commit_list
*parents
;
138 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
139 struct commit
*parent
= parents
->item
;
140 if (!(parent
->object
.flags
& UNINTERESTING
))
142 mark_tree_uninteresting(parent
->tree
);
143 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
144 parent
->object
.flags
|= SHOWN
;
150 void mark_edges_uninteresting(struct rev_info
*revs
, show_edge_fn show_edge
)
152 struct commit_list
*list
;
155 for (list
= revs
->commits
; list
; list
= list
->next
) {
156 struct commit
*commit
= list
->item
;
158 if (commit
->object
.flags
& UNINTERESTING
) {
159 mark_tree_uninteresting(commit
->tree
);
160 if (revs
->edge_hint_aggressive
&& !(commit
->object
.flags
& SHOWN
)) {
161 commit
->object
.flags
|= SHOWN
;
166 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
168 if (revs
->edge_hint_aggressive
) {
169 for (i
= 0; i
< revs
->cmdline
.nr
; i
++) {
170 struct object
*obj
= revs
->cmdline
.rev
[i
].item
;
171 struct commit
*commit
= (struct commit
*)obj
;
172 if (obj
->type
!= OBJ_COMMIT
|| !(obj
->flags
& UNINTERESTING
))
174 mark_tree_uninteresting(commit
->tree
);
175 if (!(obj
->flags
& SHOWN
)) {
183 static void add_pending_tree(struct rev_info
*revs
, struct tree
*tree
)
185 add_pending_object(revs
, &tree
->object
, "");
188 void traverse_commit_list(struct rev_info
*revs
,
189 show_commit_fn show_commit
,
190 show_object_fn show_object
,
194 struct commit
*commit
;
197 strbuf_init(&base
, PATH_MAX
);
198 while ((commit
= get_revision(revs
)) != NULL
) {
200 * an uninteresting boundary commit may not have its tree
201 * parsed yet, but we are not going to show them anyway
204 add_pending_tree(revs
, commit
->tree
);
205 show_commit(commit
, data
);
207 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
208 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
209 struct object
*obj
= pending
->item
;
210 const char *name
= pending
->name
;
211 const char *path
= pending
->path
;
212 if (obj
->flags
& (UNINTERESTING
| SEEN
))
214 if (obj
->type
== OBJ_TAG
) {
216 show_object(obj
, NULL
, name
, data
);
221 if (obj
->type
== OBJ_TREE
) {
222 process_tree(revs
, (struct tree
*)obj
, show_object
,
223 NULL
, &base
, path
, data
);
226 if (obj
->type
== OBJ_BLOB
) {
227 process_blob(revs
, (struct blob
*)obj
, show_object
,
231 die("unknown pending object %s (%s)",
232 sha1_to_hex(obj
->sha1
), name
);
234 object_array_clear(&revs
->pending
);
235 strbuf_release(&base
);