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