Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 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" |
| 10 | |
| 11 | static void process_blob(struct rev_info *revs, |
| 12 | struct blob *blob, |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 13 | show_object_fn show, |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 14 | struct strbuf *path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 15 | const char *name, |
| 16 | void *cb_data) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 17 | { |
| 18 | struct object *obj = &blob->object; |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 19 | size_t pathlen; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 20 | |
| 21 | if (!revs->blob_objects) |
| 22 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 23 | if (!obj) |
| 24 | die("bad blob object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 25 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 26 | return; |
| 27 | obj->flags |= SEEN; |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 28 | |
| 29 | pathlen = path->len; |
| 30 | strbuf_addstr(path, name); |
| 31 | show(obj, path->buf, cb_data); |
| 32 | strbuf_setlen(path, pathlen); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Processing a gitlink entry currently does nothing, since |
| 37 | * we do not recurse into the subproject. |
| 38 | * |
| 39 | * We *could* eventually add a flag that actually does that, |
| 40 | * which would involve: |
| 41 | * - is the subproject actually checked out? |
| 42 | * - if so, see if the subproject has already been added |
| 43 | * to the alternates list, and add it if not. |
| 44 | * - process the commit (or tag) the gitlink points to |
| 45 | * recursively. |
| 46 | * |
| 47 | * However, it's unclear whether there is really ever any |
| 48 | * reason to see superprojects and subprojects as such a |
| 49 | * "unified" object pool (potentially resulting in a totally |
| 50 | * humongous pack - avoiding which was the whole point of |
| 51 | * having gitlinks in the first place!). |
| 52 | * |
| 53 | * So for now, there is just a note that we *could* follow |
| 54 | * the link, and how to do it. Whether it necessarily makes |
| 55 | * any sense what-so-ever to ever do that is another issue. |
| 56 | */ |
| 57 | static void process_gitlink(struct rev_info *revs, |
| 58 | const unsigned char *sha1, |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 59 | show_object_fn show, |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 60 | struct strbuf *path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 61 | const char *name, |
| 62 | void *cb_data) |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 63 | { |
| 64 | /* Nothing to do */ |
| 65 | } |
| 66 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 67 | static void process_tree(struct rev_info *revs, |
| 68 | struct tree *tree, |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 69 | show_object_fn show, |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 70 | struct strbuf *base, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 71 | const char *name, |
| 72 | void *cb_data) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 73 | { |
| 74 | struct object *obj = &tree->object; |
| 75 | struct tree_desc desc; |
| 76 | struct name_entry entry; |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 77 | enum interesting match = revs->diffopt.pathspec.nr == 0 ? |
| 78 | all_entries_interesting: entry_not_interesting; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 79 | int baselen = base->len; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 80 | |
| 81 | if (!revs->tree_objects) |
| 82 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 83 | if (!obj) |
| 84 | die("bad tree object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 85 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 86 | return; |
Jeff King | daf7d86 | 2015-06-01 05:56:37 -0400 | [diff] [blame] | 87 | if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) { |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 88 | if (revs->ignore_missing_links) |
| 89 | return; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 90 | die("bad tree object %s", oid_to_hex(&obj->oid)); |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 91 | } |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 92 | |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 93 | obj->flags |= SEEN; |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 94 | strbuf_addstr(base, name); |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 95 | show(obj, base->buf, cb_data); |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 96 | if (base->len) |
| 97 | strbuf_addch(base, '/'); |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 98 | |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 99 | init_tree_desc(&desc, tree->buffer, tree->size); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 100 | |
| 101 | while (tree_entry(&desc, &entry)) { |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 102 | if (match != all_entries_interesting) { |
Nguyễn Thái Ngọc Duy | 97d0b74 | 2011-03-25 16:34:20 +0700 | [diff] [blame] | 103 | match = tree_entry_interesting(&entry, base, 0, |
| 104 | &revs->diffopt.pathspec); |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 105 | if (match == all_entries_not_interesting) |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 106 | break; |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 107 | if (match == entry_not_interesting) |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 108 | continue; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 109 | } |
| 110 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 111 | if (S_ISDIR(entry.mode)) |
| 112 | process_tree(revs, |
brian m. carlson | 7d924c9 | 2016-04-17 23:10:39 +0000 | [diff] [blame] | 113 | lookup_tree(entry.oid->hash), |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 114 | show, base, entry.path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 115 | cb_data); |
Martin Waitz | 302b928 | 2007-05-21 22:08:28 +0200 | [diff] [blame] | 116 | else if (S_ISGITLINK(entry.mode)) |
brian m. carlson | 7d924c9 | 2016-04-17 23:10:39 +0000 | [diff] [blame] | 117 | process_gitlink(revs, entry.oid->hash, |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 118 | show, base, entry.path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 119 | cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 120 | else |
| 121 | process_blob(revs, |
brian m. carlson | 7d924c9 | 2016-04-17 23:10:39 +0000 | [diff] [blame] | 122 | lookup_blob(entry.oid->hash), |
Jeff King | bd64516 | 2016-02-11 17:26:44 -0500 | [diff] [blame] | 123 | show, base, entry.path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 124 | cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 125 | } |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 126 | strbuf_setlen(base, baselen); |
Jeff King | 6e454b9 | 2013-06-05 18:37:39 -0400 | [diff] [blame] | 127 | free_tree_buffer(tree); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 130 | static void mark_edge_parents_uninteresting(struct commit *commit, |
| 131 | struct rev_info *revs, |
| 132 | show_edge_fn show_edge) |
| 133 | { |
| 134 | struct commit_list *parents; |
| 135 | |
| 136 | for (parents = commit->parents; parents; parents = parents->next) { |
| 137 | struct commit *parent = parents->item; |
| 138 | if (!(parent->object.flags & UNINTERESTING)) |
| 139 | continue; |
| 140 | mark_tree_uninteresting(parent->tree); |
| 141 | if (revs->edge_hint && !(parent->object.flags & SHOWN)) { |
| 142 | parent->object.flags |= SHOWN; |
| 143 | show_edge(parent); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
Nguyễn Thái Ngọc Duy | e76a5fb | 2013-08-16 16:52:06 +0700 | [diff] [blame] | 148 | void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge) |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 149 | { |
Nguyễn Thái Ngọc Duy | e76a5fb | 2013-08-16 16:52:06 +0700 | [diff] [blame] | 150 | struct commit_list *list; |
Nguyễn Thái Ngọc Duy | fbd4a70 | 2013-08-16 16:52:07 +0700 | [diff] [blame] | 151 | int i; |
| 152 | |
Nguyễn Thái Ngọc Duy | e76a5fb | 2013-08-16 16:52:06 +0700 | [diff] [blame] | 153 | for (list = revs->commits; list; list = list->next) { |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 154 | struct commit *commit = list->item; |
| 155 | |
| 156 | if (commit->object.flags & UNINTERESTING) { |
| 157 | mark_tree_uninteresting(commit->tree); |
brian m. carlson | 1684c1b | 2014-12-24 23:05:39 +0000 | [diff] [blame] | 158 | if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) { |
Nguyễn Thái Ngọc Duy | fbd4a70 | 2013-08-16 16:52:07 +0700 | [diff] [blame] | 159 | commit->object.flags |= SHOWN; |
| 160 | show_edge(commit); |
| 161 | } |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 162 | continue; |
| 163 | } |
| 164 | mark_edge_parents_uninteresting(commit, revs, show_edge); |
| 165 | } |
brian m. carlson | 1684c1b | 2014-12-24 23:05:39 +0000 | [diff] [blame] | 166 | if (revs->edge_hint_aggressive) { |
Jeff King | 200abe7 | 2014-01-20 21:25:40 -0500 | [diff] [blame] | 167 | for (i = 0; i < revs->cmdline.nr; i++) { |
| 168 | struct object *obj = revs->cmdline.rev[i].item; |
| 169 | struct commit *commit = (struct commit *)obj; |
| 170 | if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING)) |
| 171 | continue; |
| 172 | mark_tree_uninteresting(commit->tree); |
| 173 | if (!(obj->flags & SHOWN)) { |
| 174 | obj->flags |= SHOWN; |
| 175 | show_edge(commit); |
| 176 | } |
Nguyễn Thái Ngọc Duy | fbd4a70 | 2013-08-16 16:52:07 +0700 | [diff] [blame] | 177 | } |
| 178 | } |
Junio C Hamano | 8d1d8f8 | 2006-09-06 01:42:23 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 181 | static void add_pending_tree(struct rev_info *revs, struct tree *tree) |
| 182 | { |
| 183 | add_pending_object(revs, &tree->object, ""); |
| 184 | } |
| 185 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 186 | void traverse_commit_list(struct rev_info *revs, |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 187 | show_commit_fn show_commit, |
| 188 | show_object_fn show_object, |
| 189 | void *data) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 190 | { |
| 191 | int i; |
| 192 | struct commit *commit; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 193 | struct strbuf base; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 194 | |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 195 | strbuf_init(&base, PATH_MAX); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 196 | while ((commit = get_revision(revs)) != NULL) { |
Junio C Hamano | 6e7d0ef | 2011-03-14 12:29:50 -0700 | [diff] [blame] | 197 | /* |
| 198 | * an uninteresting boundary commit may not have its tree |
| 199 | * parsed yet, but we are not going to show them anyway |
| 200 | */ |
| 201 | if (commit->tree) |
| 202 | add_pending_tree(revs, commit->tree); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 203 | show_commit(commit, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 204 | } |
| 205 | for (i = 0; i < revs->pending.nr; i++) { |
| 206 | struct object_array_entry *pending = revs->pending.objects + i; |
| 207 | struct object *obj = pending->item; |
| 208 | const char *name = pending->name; |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 209 | const char *path = pending->path; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 210 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 211 | continue; |
| 212 | if (obj->type == OBJ_TAG) { |
| 213 | obj->flags |= SEEN; |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 214 | show_object(obj, name, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 215 | continue; |
| 216 | } |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 217 | if (!path) |
| 218 | path = ""; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 219 | if (obj->type == OBJ_TREE) { |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 220 | process_tree(revs, (struct tree *)obj, show_object, |
Jeff King | 13528ab | 2016-02-11 17:26:18 -0500 | [diff] [blame] | 221 | &base, path, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 222 | continue; |
| 223 | } |
| 224 | if (obj->type == OBJ_BLOB) { |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 225 | process_blob(revs, (struct blob *)obj, show_object, |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 226 | &base, path, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 227 | continue; |
| 228 | } |
| 229 | die("unknown pending object %s (%s)", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 230 | oid_to_hex(&obj->oid), name); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 231 | } |
Jeff King | 46be823 | 2014-10-15 18:34:34 -0400 | [diff] [blame] | 232 | object_array_clear(&revs->pending); |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 233 | strbuf_release(&base); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 234 | } |