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
);
29 * Processing a gitlink entry currently does nothing, since
30 * we do not recurse into the subproject.
32 * We *could* eventually add a flag that actually does that,
33 * which would involve:
34 * - is the subproject actually checked out?
35 * - if so, see if the subproject has already been added
36 * to the alternates list, and add it if not.
37 * - process the commit (or tag) the gitlink points to
40 * However, it's unclear whether there is really ever any
41 * reason to see superprojects and subprojects as such a
42 * "unified" object pool (potentially resulting in a totally
43 * humongous pack - avoiding which was the whole point of
44 * having gitlinks in the first place!).
46 * So for now, there is just a note that we *could* follow
47 * the link, and how to do it. Whether it necessarily makes
48 * any sense what-so-ever to ever do that is another issue.
50 static void process_gitlink(struct rev_info
*revs
,
51 const unsigned char *sha1
,
52 struct object_array
*p
,
53 struct name_path
*path
,
59 static void process_tree(struct rev_info
*revs
,
61 struct object_array
*p
,
62 struct name_path
*path
,
65 struct object
*obj
= &tree
->object
;
66 struct tree_desc desc
;
67 struct name_entry entry
;
70 if (!revs
->tree_objects
)
72 if (obj
->flags
& (UNINTERESTING
| SEEN
))
74 if (parse_tree(tree
) < 0)
75 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
78 add_object(obj
, p
, path
, name
);
81 me
.elem_len
= strlen(name
);
83 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
85 while (tree_entry(&desc
, &entry
)) {
86 if (S_ISDIR(entry
.mode
))
88 lookup_tree(entry
.sha1
),
90 else if (S_ISDIRLNK(entry
.mode
))
91 process_gitlink(revs
, entry
.sha1
,
95 lookup_blob(entry
.sha1
),
102 static void mark_edge_parents_uninteresting(struct commit
*commit
,
103 struct rev_info
*revs
,
104 show_edge_fn show_edge
)
106 struct commit_list
*parents
;
108 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
109 struct commit
*parent
= parents
->item
;
110 if (!(parent
->object
.flags
& UNINTERESTING
))
112 mark_tree_uninteresting(parent
->tree
);
113 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
114 parent
->object
.flags
|= SHOWN
;
120 void mark_edges_uninteresting(struct commit_list
*list
,
121 struct rev_info
*revs
,
122 show_edge_fn show_edge
)
124 for ( ; list
; list
= list
->next
) {
125 struct commit
*commit
= list
->item
;
127 if (commit
->object
.flags
& UNINTERESTING
) {
128 mark_tree_uninteresting(commit
->tree
);
131 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
135 void traverse_commit_list(struct rev_info
*revs
,
136 void (*show_commit
)(struct commit
*),
137 void (*show_object
)(struct object_array_entry
*))
140 struct commit
*commit
;
141 struct object_array objects
= { 0, 0, NULL
};
143 while ((commit
= get_revision(revs
)) != NULL
) {
144 process_tree(revs
, commit
->tree
, &objects
, NULL
, "");
147 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
148 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
149 struct object
*obj
= pending
->item
;
150 const char *name
= pending
->name
;
151 if (obj
->flags
& (UNINTERESTING
| SEEN
))
153 if (obj
->type
== OBJ_TAG
) {
155 add_object_array(obj
, name
, &objects
);
158 if (obj
->type
== OBJ_TREE
) {
159 process_tree(revs
, (struct tree
*)obj
, &objects
,
163 if (obj
->type
== OBJ_BLOB
) {
164 process_blob(revs
, (struct blob
*)obj
, &objects
,
168 die("unknown pending object %s (%s)",
169 sha1_to_hex(obj
->sha1
), name
);
171 for (i
= 0; i
< objects
.nr
; i
++)
172 show_object(&objects
.objects
[i
]);