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 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
54 while (tree_entry(&desc
, &entry
)) {
55 if (S_ISDIR(entry
.mode
))
57 lookup_tree(entry
.sha1
),
61 lookup_blob(entry
.sha1
),
68 static void mark_edge_parents_uninteresting(struct commit
*commit
,
69 struct rev_info
*revs
,
70 show_edge_fn show_edge
)
72 struct commit_list
*parents
;
74 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
75 struct commit
*parent
= parents
->item
;
76 if (!(parent
->object
.flags
& UNINTERESTING
))
78 mark_tree_uninteresting(parent
->tree
);
79 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
80 parent
->object
.flags
|= SHOWN
;
86 void mark_edges_uninteresting(struct commit_list
*list
,
87 struct rev_info
*revs
,
88 show_edge_fn show_edge
)
90 for ( ; list
; list
= list
->next
) {
91 struct commit
*commit
= list
->item
;
93 if (commit
->object
.flags
& UNINTERESTING
) {
94 mark_tree_uninteresting(commit
->tree
);
97 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
101 void traverse_commit_list(struct rev_info
*revs
,
102 void (*show_commit
)(struct commit
*),
103 void (*show_object
)(struct object_array_entry
*))
106 struct commit
*commit
;
107 struct object_array objects
= { 0, 0, NULL
};
109 while ((commit
= get_revision(revs
)) != NULL
) {
110 process_tree(revs
, commit
->tree
, &objects
, NULL
, "");
113 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
114 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
115 struct object
*obj
= pending
->item
;
116 const char *name
= pending
->name
;
117 if (obj
->flags
& (UNINTERESTING
| SEEN
))
119 if (obj
->type
== OBJ_TAG
) {
121 add_object_array(obj
, name
, &objects
);
124 if (obj
->type
== OBJ_TREE
) {
125 process_tree(revs
, (struct tree
*)obj
, &objects
,
129 if (obj
->type
== OBJ_BLOB
) {
130 process_blob(revs
, (struct blob
*)obj
, &objects
,
134 die("unknown pending object %s (%s)",
135 sha1_to_hex(obj
->sha1
), name
);
137 for (i
= 0; i
< objects
.nr
; i
++)
138 show_object(&objects
.objects
[i
]);