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
)
22 die("bad blob object");
23 if (obj
->flags
& (UNINTERESTING
| SEEN
))
27 add_object(obj
, p
, path
, name
);
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
,
54 struct object_array
*p
,
55 struct name_path
*path
,
61 static void process_tree(struct rev_info
*revs
,
63 struct object_array
*p
,
64 struct name_path
*path
,
67 struct object
*obj
= &tree
->object
;
68 struct tree_desc desc
;
69 struct name_entry entry
;
72 if (!revs
->tree_objects
)
75 die("bad tree object");
76 if (obj
->flags
& (UNINTERESTING
| SEEN
))
78 if (parse_tree(tree
) < 0)
79 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
82 add_object(obj
, p
, path
, name
);
85 me
.elem_len
= strlen(name
);
87 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
89 while (tree_entry(&desc
, &entry
)) {
90 if (S_ISDIR(entry
.mode
))
92 lookup_tree(entry
.sha1
),
94 else if (S_ISGITLINK(entry
.mode
))
95 process_gitlink(revs
, entry
.sha1
,
99 lookup_blob(entry
.sha1
),
106 static void mark_edge_parents_uninteresting(struct commit
*commit
,
107 struct rev_info
*revs
,
108 show_edge_fn show_edge
)
110 struct commit_list
*parents
;
112 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
113 struct commit
*parent
= parents
->item
;
114 if (!(parent
->object
.flags
& UNINTERESTING
))
116 mark_tree_uninteresting(parent
->tree
);
117 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
118 parent
->object
.flags
|= SHOWN
;
124 void mark_edges_uninteresting(struct commit_list
*list
,
125 struct rev_info
*revs
,
126 show_edge_fn show_edge
)
128 for ( ; list
; list
= list
->next
) {
129 struct commit
*commit
= list
->item
;
131 if (commit
->object
.flags
& UNINTERESTING
) {
132 mark_tree_uninteresting(commit
->tree
);
135 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
139 void traverse_commit_list(struct rev_info
*revs
,
140 void (*show_commit
)(struct commit
*),
141 void (*show_object
)(struct object_array_entry
*))
144 struct commit
*commit
;
145 struct object_array objects
= { 0, 0, NULL
};
147 while ((commit
= get_revision(revs
)) != NULL
) {
148 process_tree(revs
, commit
->tree
, &objects
, NULL
, "");
151 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
152 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
153 struct object
*obj
= pending
->item
;
154 const char *name
= pending
->name
;
155 if (obj
->flags
& (UNINTERESTING
| SEEN
))
157 if (obj
->type
== OBJ_TAG
) {
159 add_object_array(obj
, name
, &objects
);
162 if (obj
->type
== OBJ_TREE
) {
163 process_tree(revs
, (struct tree
*)obj
, &objects
,
167 if (obj
->type
== OBJ_BLOB
) {
168 process_blob(revs
, (struct blob
*)obj
, &objects
,
172 die("unknown pending object %s (%s)",
173 sha1_to_hex(obj
->sha1
), name
);
175 for (i
= 0; i
< objects
.nr
; i
++)
176 show_object(&objects
.objects
[i
]);
177 free(objects
.objects
);
178 if (revs
->pending
.nr
) {
179 free(revs
->pending
.objects
);
180 revs
->pending
.nr
= 0;
181 revs
->pending
.alloc
= 0;
182 revs
->pending
.objects
= NULL
;