]>
Commit | Line | Data |
---|---|---|
c64ed70d JH |
1 | #include "cache.h" |
2 | #include "tag.h" | |
3 | #include "commit.h" | |
4 | #include "tree.h" | |
5 | #include "blob.h" | |
6 | #include "diff.h" | |
7 | #include "tree-walk.h" | |
8 | #include "revision.h" | |
9 | #include "list-objects.h" | |
25ec7bca JH |
10 | #include "list-objects-filter.h" |
11 | #include "list-objects-filter-options.h" | |
df11e196 | 12 | #include "packfile.h" |
cbd53a21 | 13 | #include "object-store.h" |
c64ed70d JH |
14 | |
15 | static void process_blob(struct rev_info *revs, | |
16 | struct blob *blob, | |
8d2dfc49 | 17 | show_object_fn show, |
bd64516a | 18 | struct strbuf *path, |
49473672 | 19 | const char *name, |
25ec7bca JH |
20 | void *cb_data, |
21 | filter_object_fn filter_fn, | |
22 | void *filter_data) | |
c64ed70d JH |
23 | { |
24 | struct object *obj = &blob->object; | |
de1e67d0 | 25 | size_t pathlen; |
25ec7bca | 26 | enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW; |
c64ed70d JH |
27 | |
28 | if (!revs->blob_objects) | |
29 | return; | |
a301b0c8 MK |
30 | if (!obj) |
31 | die("bad blob object"); | |
c64ed70d JH |
32 | if (obj->flags & (UNINTERESTING | SEEN)) |
33 | return; | |
de1e67d0 | 34 | |
df11e196 JT |
35 | /* |
36 | * Pre-filter known-missing objects when explicitly requested. | |
37 | * Otherwise, a missing object error message may be reported | |
38 | * later (depending on other filtering criteria). | |
39 | * | |
40 | * Note that this "--exclude-promisor-objects" pre-filtering | |
41 | * may cause the actual filter to report an incomplete list | |
42 | * of missing objects. | |
43 | */ | |
44 | if (revs->exclude_promisor_objects && | |
45 | !has_object_file(&obj->oid) && | |
46 | is_promisor_object(&obj->oid)) | |
47 | return; | |
48 | ||
de1e67d0 JK |
49 | pathlen = path->len; |
50 | strbuf_addstr(path, name); | |
a0c9016a | 51 | if (!(obj->flags & USER_GIVEN) && filter_fn) |
25ec7bca JH |
52 | r = filter_fn(LOFS_BLOB, obj, |
53 | path->buf, &path->buf[pathlen], | |
54 | filter_data); | |
55 | if (r & LOFR_MARK_SEEN) | |
56 | obj->flags |= SEEN; | |
57 | if (r & LOFR_DO_SHOW) | |
58 | show(obj, path->buf, cb_data); | |
de1e67d0 | 59 | strbuf_setlen(path, pathlen); |
c64ed70d JH |
60 | } |
61 | ||
6e2f441b LT |
62 | /* |
63 | * Processing a gitlink entry currently does nothing, since | |
64 | * we do not recurse into the subproject. | |
65 | * | |
66 | * We *could* eventually add a flag that actually does that, | |
67 | * which would involve: | |
68 | * - is the subproject actually checked out? | |
69 | * - if so, see if the subproject has already been added | |
70 | * to the alternates list, and add it if not. | |
71 | * - process the commit (or tag) the gitlink points to | |
72 | * recursively. | |
73 | * | |
74 | * However, it's unclear whether there is really ever any | |
75 | * reason to see superprojects and subprojects as such a | |
76 | * "unified" object pool (potentially resulting in a totally | |
77 | * humongous pack - avoiding which was the whole point of | |
78 | * having gitlinks in the first place!). | |
79 | * | |
80 | * So for now, there is just a note that we *could* follow | |
81 | * the link, and how to do it. Whether it necessarily makes | |
82 | * any sense what-so-ever to ever do that is another issue. | |
83 | */ | |
84 | static void process_gitlink(struct rev_info *revs, | |
85 | const unsigned char *sha1, | |
8d2dfc49 | 86 | show_object_fn show, |
bd64516a | 87 | struct strbuf *path, |
49473672 JH |
88 | const char *name, |
89 | void *cb_data) | |
6e2f441b LT |
90 | { |
91 | /* Nothing to do */ | |
92 | } | |
93 | ||
c64ed70d JH |
94 | static void process_tree(struct rev_info *revs, |
95 | struct tree *tree, | |
8d2dfc49 | 96 | show_object_fn show, |
cc5fa2fd | 97 | struct strbuf *base, |
49473672 | 98 | const char *name, |
25ec7bca JH |
99 | void *cb_data, |
100 | filter_object_fn filter_fn, | |
101 | void *filter_data) | |
c64ed70d JH |
102 | { |
103 | struct object *obj = &tree->object; | |
104 | struct tree_desc desc; | |
105 | struct name_entry entry; | |
d688cf07 NTND |
106 | enum interesting match = revs->diffopt.pathspec.nr == 0 ? |
107 | all_entries_interesting: entry_not_interesting; | |
cc5fa2fd | 108 | int baselen = base->len; |
25ec7bca | 109 | enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW; |
df11e196 JT |
110 | int gently = revs->ignore_missing_links || |
111 | revs->exclude_promisor_objects; | |
c64ed70d JH |
112 | |
113 | if (!revs->tree_objects) | |
114 | return; | |
a301b0c8 MK |
115 | if (!obj) |
116 | die("bad tree object"); | |
c64ed70d JH |
117 | if (obj->flags & (UNINTERESTING | SEEN)) |
118 | return; | |
df11e196 | 119 | if (parse_tree_gently(tree, gently) < 0) { |
2db1a43f VM |
120 | if (revs->ignore_missing_links) |
121 | return; | |
df11e196 JT |
122 | |
123 | /* | |
124 | * Pre-filter known-missing tree objects when explicitly | |
125 | * requested. This may cause the actual filter to report | |
126 | * an incomplete list of missing objects. | |
127 | */ | |
128 | if (revs->exclude_promisor_objects && | |
129 | is_promisor_object(&obj->oid)) | |
130 | return; | |
131 | ||
f2fd0760 | 132 | die("bad tree object %s", oid_to_hex(&obj->oid)); |
2db1a43f | 133 | } |
13528ab3 | 134 | |
13528ab3 | 135 | strbuf_addstr(base, name); |
a0c9016a | 136 | if (!(obj->flags & USER_GIVEN) && filter_fn) |
25ec7bca JH |
137 | r = filter_fn(LOFS_BEGIN_TREE, obj, |
138 | base->buf, &base->buf[baselen], | |
139 | filter_data); | |
140 | if (r & LOFR_MARK_SEEN) | |
141 | obj->flags |= SEEN; | |
142 | if (r & LOFR_DO_SHOW) | |
143 | show(obj, base->buf, cb_data); | |
13528ab3 JK |
144 | if (base->len) |
145 | strbuf_addch(base, '/'); | |
cc5fa2fd | 146 | |
6fda5e51 | 147 | init_tree_desc(&desc, tree->buffer, tree->size); |
c64ed70d JH |
148 | |
149 | while (tree_entry(&desc, &entry)) { | |
d688cf07 | 150 | if (match != all_entries_interesting) { |
97d0b74a NTND |
151 | match = tree_entry_interesting(&entry, base, 0, |
152 | &revs->diffopt.pathspec); | |
d688cf07 | 153 | if (match == all_entries_not_interesting) |
cc5fa2fd | 154 | break; |
d688cf07 | 155 | if (match == entry_not_interesting) |
cc5fa2fd | 156 | continue; |
cc5fa2fd EN |
157 | } |
158 | ||
c64ed70d JH |
159 | if (S_ISDIR(entry.mode)) |
160 | process_tree(revs, | |
f86bcc7b | 161 | lookup_tree(the_repository, entry.oid), |
13528ab3 | 162 | show, base, entry.path, |
25ec7bca | 163 | cb_data, filter_fn, filter_data); |
302b9282 | 164 | else if (S_ISGITLINK(entry.mode)) |
7d924c91 | 165 | process_gitlink(revs, entry.oid->hash, |
bd64516a | 166 | show, base, entry.path, |
49473672 | 167 | cb_data); |
c64ed70d JH |
168 | else |
169 | process_blob(revs, | |
da14a7ff | 170 | lookup_blob(the_repository, entry.oid), |
bd64516a | 171 | show, base, entry.path, |
25ec7bca | 172 | cb_data, filter_fn, filter_data); |
c64ed70d | 173 | } |
25ec7bca | 174 | |
a0c9016a | 175 | if (!(obj->flags & USER_GIVEN) && filter_fn) { |
25ec7bca JH |
176 | r = filter_fn(LOFS_END_TREE, obj, |
177 | base->buf, &base->buf[baselen], | |
178 | filter_data); | |
179 | if (r & LOFR_MARK_SEEN) | |
180 | obj->flags |= SEEN; | |
181 | if (r & LOFR_DO_SHOW) | |
182 | show(obj, base->buf, cb_data); | |
183 | } | |
184 | ||
cc5fa2fd | 185 | strbuf_setlen(base, baselen); |
6e454b9a | 186 | free_tree_buffer(tree); |
c64ed70d JH |
187 | } |
188 | ||
8d1d8f83 JH |
189 | static void mark_edge_parents_uninteresting(struct commit *commit, |
190 | struct rev_info *revs, | |
191 | show_edge_fn show_edge) | |
192 | { | |
193 | struct commit_list *parents; | |
194 | ||
195 | for (parents = commit->parents; parents; parents = parents->next) { | |
196 | struct commit *parent = parents->item; | |
197 | if (!(parent->object.flags & UNINTERESTING)) | |
198 | continue; | |
2e27bd77 | 199 | mark_tree_uninteresting(get_commit_tree(parent)); |
8d1d8f83 JH |
200 | if (revs->edge_hint && !(parent->object.flags & SHOWN)) { |
201 | parent->object.flags |= SHOWN; | |
202 | show_edge(parent); | |
203 | } | |
204 | } | |
205 | } | |
206 | ||
e76a5fb4 | 207 | void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge) |
8d1d8f83 | 208 | { |
e76a5fb4 | 209 | struct commit_list *list; |
fbd4a703 NTND |
210 | int i; |
211 | ||
e76a5fb4 | 212 | for (list = revs->commits; list; list = list->next) { |
8d1d8f83 JH |
213 | struct commit *commit = list->item; |
214 | ||
215 | if (commit->object.flags & UNINTERESTING) { | |
2e27bd77 | 216 | mark_tree_uninteresting(get_commit_tree(commit)); |
1684c1b2 | 217 | if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) { |
fbd4a703 NTND |
218 | commit->object.flags |= SHOWN; |
219 | show_edge(commit); | |
220 | } | |
8d1d8f83 JH |
221 | continue; |
222 | } | |
223 | mark_edge_parents_uninteresting(commit, revs, show_edge); | |
224 | } | |
1684c1b2 | 225 | if (revs->edge_hint_aggressive) { |
200abe74 JK |
226 | for (i = 0; i < revs->cmdline.nr; i++) { |
227 | struct object *obj = revs->cmdline.rev[i].item; | |
228 | struct commit *commit = (struct commit *)obj; | |
229 | if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING)) | |
230 | continue; | |
2e27bd77 | 231 | mark_tree_uninteresting(get_commit_tree(commit)); |
200abe74 JK |
232 | if (!(obj->flags & SHOWN)) { |
233 | obj->flags |= SHOWN; | |
234 | show_edge(commit); | |
235 | } | |
fbd4a703 NTND |
236 | } |
237 | } | |
8d1d8f83 JH |
238 | } |
239 | ||
8d2dfc49 LT |
240 | static void add_pending_tree(struct rev_info *revs, struct tree *tree) |
241 | { | |
242 | add_pending_object(revs, &tree->object, ""); | |
243 | } | |
244 | ||
91904f56 SB |
245 | static void traverse_trees_and_blobs(struct rev_info *revs, |
246 | struct strbuf *base, | |
247 | show_object_fn show_object, | |
556de1a8 JH |
248 | void *show_data, |
249 | filter_object_fn filter_fn, | |
250 | void *filter_data) | |
c64ed70d JH |
251 | { |
252 | int i; | |
c64ed70d | 253 | |
91904f56 SB |
254 | assert(base->len == 0); |
255 | ||
c64ed70d JH |
256 | for (i = 0; i < revs->pending.nr; i++) { |
257 | struct object_array_entry *pending = revs->pending.objects + i; | |
258 | struct object *obj = pending->item; | |
259 | const char *name = pending->name; | |
20739490 | 260 | const char *path = pending->path; |
c64ed70d JH |
261 | if (obj->flags & (UNINTERESTING | SEEN)) |
262 | continue; | |
263 | if (obj->type == OBJ_TAG) { | |
264 | obj->flags |= SEEN; | |
25ec7bca | 265 | show_object(obj, name, show_data); |
c64ed70d JH |
266 | continue; |
267 | } | |
20739490 JK |
268 | if (!path) |
269 | path = ""; | |
c64ed70d | 270 | if (obj->type == OBJ_TREE) { |
8d2dfc49 | 271 | process_tree(revs, (struct tree *)obj, show_object, |
556de1a8 | 272 | base, path, show_data, |
25ec7bca | 273 | filter_fn, filter_data); |
c64ed70d JH |
274 | continue; |
275 | } | |
276 | if (obj->type == OBJ_BLOB) { | |
8d2dfc49 | 277 | process_blob(revs, (struct blob *)obj, show_object, |
556de1a8 | 278 | base, path, show_data, |
25ec7bca | 279 | filter_fn, filter_data); |
c64ed70d JH |
280 | continue; |
281 | } | |
282 | die("unknown pending object %s (%s)", | |
f2fd0760 | 283 | oid_to_hex(&obj->oid), name); |
c64ed70d | 284 | } |
46be8231 | 285 | object_array_clear(&revs->pending); |
91904f56 SB |
286 | } |
287 | ||
556de1a8 JH |
288 | static void do_traverse(struct rev_info *revs, |
289 | show_commit_fn show_commit, | |
290 | show_object_fn show_object, | |
291 | void *show_data, | |
292 | filter_object_fn filter_fn, | |
293 | void *filter_data) | |
91904f56 SB |
294 | { |
295 | struct commit *commit; | |
296 | struct strbuf csp; /* callee's scratch pad */ | |
297 | strbuf_init(&csp, PATH_MAX); | |
298 | ||
299 | while ((commit = get_revision(revs)) != NULL) { | |
300 | /* | |
301 | * an uninteresting boundary commit may not have its tree | |
302 | * parsed yet, but we are not going to show them anyway | |
303 | */ | |
2e27bd77 DS |
304 | if (get_commit_tree(commit)) |
305 | add_pending_tree(revs, get_commit_tree(commit)); | |
556de1a8 | 306 | show_commit(commit, show_data); |
ce5b6f9b SB |
307 | |
308 | if (revs->tree_blobs_in_commit_order) | |
309 | /* | |
310 | * NEEDSWORK: Adding the tree and then flushing it here | |
311 | * needs a reallocation for each commit. Can we pass the | |
312 | * tree directory without allocation churn? | |
313 | */ | |
556de1a8 JH |
314 | traverse_trees_and_blobs(revs, &csp, |
315 | show_object, show_data, | |
316 | filter_fn, filter_data); | |
91904f56 | 317 | } |
556de1a8 JH |
318 | traverse_trees_and_blobs(revs, &csp, |
319 | show_object, show_data, | |
320 | filter_fn, filter_data); | |
91904f56 | 321 | strbuf_release(&csp); |
c64ed70d | 322 | } |
25ec7bca JH |
323 | |
324 | void traverse_commit_list(struct rev_info *revs, | |
325 | show_commit_fn show_commit, | |
326 | show_object_fn show_object, | |
327 | void *show_data) | |
328 | { | |
329 | do_traverse(revs, show_commit, show_object, show_data, NULL, NULL); | |
330 | } | |
331 | ||
332 | void traverse_commit_list_filtered( | |
333 | struct list_objects_filter_options *filter_options, | |
334 | struct rev_info *revs, | |
335 | show_commit_fn show_commit, | |
336 | show_object_fn show_object, | |
337 | void *show_data, | |
338 | struct oidset *omitted) | |
339 | { | |
340 | filter_object_fn filter_fn = NULL; | |
341 | filter_free_fn filter_free_fn = NULL; | |
342 | void *filter_data = NULL; | |
343 | ||
344 | filter_data = list_objects_filter__init(omitted, filter_options, | |
345 | &filter_fn, &filter_free_fn); | |
346 | do_traverse(revs, show_commit, show_object, show_data, | |
347 | filter_fn, filter_data); | |
348 | if (filter_data && filter_free_fn) | |
349 | filter_free_fn(filter_data); | |
350 | } |