9 #include "list-objects.h"
11 static void process_blob(struct rev_info
*revs
,
13 struct object_array
*p
,
14 struct name_path
*path
,
17 struct object
*obj
= &blob
->object
;
19 if (!revs
->blob_objects
)
21 if (obj
->flags
& (UNINTERESTING
| SEEN
))
25 add_object(obj
, p
, path
, name
);
28 static void process_tree(struct rev_info
*revs
,
30 struct object_array
*p
,
31 struct name_path
*path
,
34 struct object
*obj
= &tree
->object
;
35 struct tree_desc desc
;
36 struct name_entry entry
;
39 if (!revs
->tree_objects
)
41 if (obj
->flags
& (UNINTERESTING
| SEEN
))
43 if (parse_tree(tree
) < 0)
44 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
47 add_object(obj
, p
, path
, name
);
50 me
.elem_len
= strlen(name
);
52 desc
.buf
= tree
->buffer
;
53 desc
.size
= tree
->size
;
55 while (tree_entry(&desc
, &entry
)) {
56 if (S_ISDIR(entry
.mode
))
58 lookup_tree(entry
.sha1
),
62 lookup_blob(entry
.sha1
),
69 static void mark_edge_parents_uninteresting(struct commit
*commit
,
70 struct rev_info
*revs
,
71 show_edge_fn show_edge
)
73 struct commit_list
*parents
;
75 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
76 struct commit
*parent
= parents
->item
;
77 if (!(parent
->object
.flags
& UNINTERESTING
))
79 mark_tree_uninteresting(parent
->tree
);
80 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
81 parent
->object
.flags
|= SHOWN
;
87 void mark_edges_uninteresting(struct commit_list
*list
,
88 struct rev_info
*revs
,
89 show_edge_fn show_edge
)
91 for ( ; list
; list
= list
->next
) {
92 struct commit
*commit
= list
->item
;
94 if (commit
->object
.flags
& UNINTERESTING
) {
95 mark_tree_uninteresting(commit
->tree
);
98 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
102 void traverse_commit_list(struct rev_info
*revs
,
103 void (*show_commit
)(struct commit
*),
104 void (*show_object
)(struct object_array_entry
*))
107 struct commit
*commit
;
108 struct object_array objects
= { 0, 0, NULL
};
110 while ((commit
= get_revision(revs
)) != NULL
) {
111 process_tree(revs
, commit
->tree
, &objects
, NULL
, "");
114 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
115 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
116 struct object
*obj
= pending
->item
;
117 const char *name
= pending
->name
;
118 if (obj
->flags
& (UNINTERESTING
| SEEN
))
120 if (obj
->type
== OBJ_TAG
) {
122 add_object_array(obj
, name
, &objects
);
125 if (obj
->type
== OBJ_TREE
) {
126 process_tree(revs
, (struct tree
*)obj
, &objects
,
130 if (obj
->type
== OBJ_BLOB
) {
131 process_blob(revs
, (struct blob
*)obj
, &objects
,
135 die("unknown pending object %s (%s)",
136 sha1_to_hex(obj
->sha1
), name
);
138 for (i
= 0; i
< objects
.nr
; i
++)
139 show_object(&objects
.objects
[i
]);