]>
git.ipfire.org Git - thirdparty/git.git/blob - list-objects.c
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
))
26 add_object(obj
, p
, path
, name
);
30 * Processing a gitlink entry currently does nothing, since
31 * we do not recurse into the subproject.
33 * We *could* eventually add a flag that actually does that,
34 * which would involve:
35 * - is the subproject actually checked out?
36 * - if so, see if the subproject has already been added
37 * to the alternates list, and add it if not.
38 * - process the commit (or tag) the gitlink points to
41 * However, it's unclear whether there is really ever any
42 * reason to see superprojects and subprojects as such a
43 * "unified" object pool (potentially resulting in a totally
44 * humongous pack - avoiding which was the whole point of
45 * having gitlinks in the first place!).
47 * So for now, there is just a note that we *could* follow
48 * the link, and how to do it. Whether it necessarily makes
49 * any sense what-so-ever to ever do that is another issue.
51 static void process_gitlink(struct rev_info
*revs
,
52 const unsigned char *sha1
,
53 struct object_array
*p
,
54 struct name_path
*path
,
60 static void process_tree(struct rev_info
*revs
,
62 struct object_array
*p
,
63 struct name_path
*path
,
66 struct object
*obj
= &tree
->object
;
67 struct tree_desc desc
;
68 struct name_entry entry
;
71 if (!revs
->tree_objects
)
74 die("bad tree object");
75 if (obj
->flags
& (UNINTERESTING
| SEEN
))
77 if (parse_tree(tree
) < 0)
78 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
80 add_object(obj
, p
, path
, name
);
83 me
.elem_len
= strlen(name
);
85 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
87 while (tree_entry(&desc
, &entry
)) {
88 if (S_ISDIR(entry
.mode
))
90 lookup_tree(entry
.sha1
),
92 else if (S_ISGITLINK(entry
.mode
))
93 process_gitlink(revs
, entry
.sha1
,
97 lookup_blob(entry
.sha1
),
104 static void mark_edge_parents_uninteresting(struct commit
*commit
,
105 struct rev_info
*revs
,
106 show_edge_fn show_edge
)
108 struct commit_list
*parents
;
110 for (parents
= commit
->parents
; parents
; parents
= parents
->next
) {
111 struct commit
*parent
= parents
->item
;
112 if (!(parent
->object
.flags
& UNINTERESTING
))
114 mark_tree_uninteresting(parent
->tree
);
115 if (revs
->edge_hint
&& !(parent
->object
.flags
& SHOWN
)) {
116 parent
->object
.flags
|= SHOWN
;
122 void mark_edges_uninteresting(struct commit_list
*list
,
123 struct rev_info
*revs
,
124 show_edge_fn show_edge
)
126 for ( ; list
; list
= list
->next
) {
127 struct commit
*commit
= list
->item
;
129 if (commit
->object
.flags
& UNINTERESTING
) {
130 mark_tree_uninteresting(commit
->tree
);
133 mark_edge_parents_uninteresting(commit
, revs
, show_edge
);
137 void traverse_commit_list(struct rev_info
*revs
,
138 void (*show_commit
)(struct commit
*),
139 void (*show_object
)(struct object_array_entry
*))
142 struct commit
*commit
;
143 struct object_array objects
= { 0, 0, NULL
};
145 while ((commit
= get_revision(revs
)) != NULL
) {
146 process_tree(revs
, commit
->tree
, &objects
, NULL
, "");
149 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
150 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
151 struct object
*obj
= pending
->item
;
152 const char *name
= pending
->name
;
153 if (obj
->flags
& (UNINTERESTING
| SEEN
))
155 if (obj
->type
== OBJ_TAG
) {
157 add_object_array(obj
, name
, &objects
);
160 if (obj
->type
== OBJ_TREE
) {
161 process_tree(revs
, (struct tree
*)obj
, &objects
,
165 if (obj
->type
== OBJ_BLOB
) {
166 process_blob(revs
, (struct blob
*)obj
, &objects
,
170 die("unknown pending object %s (%s)",
171 sha1_to_hex(obj
->sha1
), name
);
173 for (i
= 0; i
< objects
.nr
; i
++)
174 show_object(&objects
.objects
[i
]);
175 free(objects
.objects
);
176 if (revs
->pending
.nr
) {
177 free(revs
->pending
.objects
);
178 revs
->pending
.nr
= 0;
179 revs
->pending
.alloc
= 0;
180 revs
->pending
.objects
= NULL
;