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, |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 14 | struct name_path *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; |
| 19 | |
| 20 | if (!revs->blob_objects) |
| 21 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 22 | if (!obj) |
| 23 | die("bad blob object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 24 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 25 | return; |
| 26 | obj->flags |= SEEN; |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 27 | show(obj, path, name, cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 30 | /* |
| 31 | * Processing a gitlink entry currently does nothing, since |
| 32 | * we do not recurse into the subproject. |
| 33 | * |
| 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 |
| 40 | * recursively. |
| 41 | * |
| 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!). |
| 47 | * |
| 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. |
| 51 | */ |
| 52 | static void process_gitlink(struct rev_info *revs, |
| 53 | const unsigned char *sha1, |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 54 | show_object_fn show, |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 55 | struct name_path *path, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 56 | const char *name, |
| 57 | void *cb_data) |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 58 | { |
| 59 | /* Nothing to do */ |
| 60 | } |
| 61 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 62 | static void process_tree(struct rev_info *revs, |
| 63 | struct tree *tree, |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 64 | show_object_fn show, |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 65 | struct name_path *path, |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 66 | struct strbuf *base, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 67 | const char *name, |
| 68 | void *cb_data) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 69 | { |
| 70 | struct object *obj = &tree->object; |
| 71 | struct tree_desc desc; |
| 72 | struct name_entry entry; |
| 73 | struct name_path me; |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 74 | enum interesting match = revs->diffopt.pathspec.nr == 0 ? |
| 75 | all_entries_interesting: entry_not_interesting; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 76 | int baselen = base->len; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 77 | |
| 78 | if (!revs->tree_objects) |
| 79 | return; |
Martin Koegler | a301b0c | 2008-02-18 21:47:56 +0100 | [diff] [blame] | 80 | if (!obj) |
| 81 | die("bad tree object"); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 82 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 83 | return; |
| 84 | if (parse_tree(tree) < 0) |
| 85 | die("bad tree object %s", sha1_to_hex(obj->sha1)); |
| 86 | obj->flags |= SEEN; |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 87 | show(obj, path, name, cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 88 | me.up = path; |
| 89 | me.elem = name; |
| 90 | me.elem_len = strlen(name); |
| 91 | |
Nguyễn Thái Ngọc Duy | 97d0b74 | 2011-03-25 16:34:20 +0700 | [diff] [blame] | 92 | if (!match) { |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 93 | strbuf_addstr(base, name); |
| 94 | if (base->len) |
| 95 | strbuf_addch(base, '/'); |
| 96 | } |
| 97 | |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 98 | init_tree_desc(&desc, tree->buffer, tree->size); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 99 | |
| 100 | while (tree_entry(&desc, &entry)) { |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 101 | if (match != all_entries_interesting) { |
Nguyễn Thái Ngọc Duy | 97d0b74 | 2011-03-25 16:34:20 +0700 | [diff] [blame] | 102 | match = tree_entry_interesting(&entry, base, 0, |
| 103 | &revs->diffopt.pathspec); |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 104 | if (match == all_entries_not_interesting) |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 105 | break; |
Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 17:36:10 +1100 | [diff] [blame] | 106 | if (match == entry_not_interesting) |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 107 | continue; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 108 | } |
| 109 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 110 | if (S_ISDIR(entry.mode)) |
| 111 | process_tree(revs, |
| 112 | lookup_tree(entry.sha1), |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 113 | show, &me, base, entry.path, |
| 114 | cb_data); |
Martin Waitz | 302b928 | 2007-05-21 22:08:28 +0200 | [diff] [blame] | 115 | else if (S_ISGITLINK(entry.mode)) |
Linus Torvalds | 6e2f441 | 2007-04-13 09:25:01 -0700 | [diff] [blame] | 116 | process_gitlink(revs, entry.sha1, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 117 | show, &me, entry.path, |
| 118 | cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 119 | else |
| 120 | process_blob(revs, |
| 121 | lookup_blob(entry.sha1), |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 122 | show, &me, entry.path, |
| 123 | cb_data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 124 | } |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 125 | strbuf_setlen(base, baselen); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 126 | free(tree->buffer); |
| 127 | tree->buffer = NULL; |
| 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 | |
| 148 | void mark_edges_uninteresting(struct commit_list *list, |
| 149 | struct rev_info *revs, |
| 150 | show_edge_fn show_edge) |
| 151 | { |
| 152 | for ( ; list; list = list->next) { |
| 153 | struct commit *commit = list->item; |
| 154 | |
| 155 | if (commit->object.flags & UNINTERESTING) { |
| 156 | mark_tree_uninteresting(commit->tree); |
| 157 | continue; |
| 158 | } |
| 159 | mark_edge_parents_uninteresting(commit, revs, show_edge); |
| 160 | } |
| 161 | } |
| 162 | |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 163 | static void add_pending_tree(struct rev_info *revs, struct tree *tree) |
| 164 | { |
| 165 | add_pending_object(revs, &tree->object, ""); |
| 166 | } |
| 167 | |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 168 | void traverse_commit_list(struct rev_info *revs, |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 169 | show_commit_fn show_commit, |
| 170 | show_object_fn show_object, |
| 171 | void *data) |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 172 | { |
| 173 | int i; |
| 174 | struct commit *commit; |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 175 | struct strbuf base; |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 176 | |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 177 | strbuf_init(&base, PATH_MAX); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 178 | while ((commit = get_revision(revs)) != NULL) { |
Junio C Hamano | 6e7d0ef | 2011-03-14 12:29:50 -0700 | [diff] [blame] | 179 | /* |
| 180 | * an uninteresting boundary commit may not have its tree |
| 181 | * parsed yet, but we are not going to show them anyway |
| 182 | */ |
| 183 | if (commit->tree) |
| 184 | add_pending_tree(revs, commit->tree); |
Christian Couder | 11c211f | 2009-04-06 21:28:36 +0200 | [diff] [blame] | 185 | show_commit(commit, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 186 | } |
| 187 | for (i = 0; i < revs->pending.nr; i++) { |
| 188 | struct object_array_entry *pending = revs->pending.objects + i; |
| 189 | struct object *obj = pending->item; |
| 190 | const char *name = pending->name; |
| 191 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 192 | continue; |
| 193 | if (obj->type == OBJ_TAG) { |
| 194 | obj->flags |= SEEN; |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 195 | show_object(obj, NULL, name, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 196 | continue; |
| 197 | } |
| 198 | if (obj->type == OBJ_TREE) { |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 199 | process_tree(revs, (struct tree *)obj, show_object, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 200 | NULL, &base, name, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 201 | continue; |
| 202 | } |
| 203 | if (obj->type == OBJ_BLOB) { |
Linus Torvalds | 8d2dfc4 | 2009-04-10 17:27:58 -0700 | [diff] [blame] | 204 | process_blob(revs, (struct blob *)obj, show_object, |
Junio C Hamano | 4947367 | 2011-09-01 15:43:33 -0700 | [diff] [blame] | 205 | NULL, name, data); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 206 | continue; |
| 207 | } |
| 208 | die("unknown pending object %s (%s)", |
| 209 | sha1_to_hex(obj->sha1), name); |
| 210 | } |
Shawn O. Pearce | 295dd2a | 2007-11-09 06:06:10 -0500 | [diff] [blame] | 211 | if (revs->pending.nr) { |
| 212 | free(revs->pending.objects); |
| 213 | revs->pending.nr = 0; |
| 214 | revs->pending.alloc = 0; |
| 215 | revs->pending.objects = NULL; |
| 216 | } |
Elijah Newren | cc5fa2f | 2010-12-17 20:26:47 +0700 | [diff] [blame] | 217 | strbuf_release(&base); |
Junio C Hamano | c64ed70 | 2006-09-04 21:50:12 -0700 | [diff] [blame] | 218 | } |