Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 239 lines (221 sloc) 6.2 kb
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
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,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
13 show_object_fn show,
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
14 struct name_path *path,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
15 const char *name,
16 void *cb_data)
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
17 {
18 struct object *obj = &blob->object;
19
20 if (!revs->blob_objects)
21 return;
a301b0c8 »
2008-02-18 list-objects.c::process_tree/blob: check for NULL
22 if (!obj)
23 die("bad blob object");
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
24 if (obj->flags & (UNINTERESTING | SEEN))
25 return;
26 obj->flags |= SEEN;
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
27 show(obj, path, name, cb_data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
28 }
29
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
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,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
54 show_object_fn show,
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
55 struct name_path *path,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
56 const char *name,
57 void *cb_data)
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
58 {
59 /* Nothing to do */
60 }
61
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
62 static void process_tree(struct rev_info *revs,
63 struct tree *tree,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
64 show_object_fn show,
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
65 struct name_path *path,
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
66 struct strbuf *base,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
67 const char *name,
68 void *cb_data)
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
69 {
70 struct object *obj = &tree->object;
71 struct tree_desc desc;
72 struct name_entry entry;
73 struct name_path me;
d688cf07 »
2011-10-24 tree_entry_interesting(): give meaningful names to return values
74 enum interesting match = revs->diffopt.pathspec.nr == 0 ?
75 all_entries_interesting: entry_not_interesting;
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
76 int baselen = base->len;
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
77
78 if (!revs->tree_objects)
79 return;
a301b0c8 »
2008-02-18 list-objects.c::process_tree/blob: check for NULL
80 if (!obj)
81 die("bad tree object");
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
82 if (obj->flags & (UNINTERESTING | SEEN))
83 return;
2db1a43f »
2014-03-28 add `ignore_missing_links` mode to revwalk
84 if (parse_tree(tree) < 0) {
85 if (revs->ignore_missing_links)
86 return;
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
87 die("bad tree object %s", sha1_to_hex(obj->sha1));
2db1a43f »
2014-03-28 add `ignore_missing_links` mode to revwalk
88 }
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
89 obj->flags |= SEEN;
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
90 show(obj, path, name, cb_data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
91 me.up = path;
92 me.elem = name;
93 me.elem_len = strlen(name);
94
97d0b74a »
2011-03-25 Improve tree_entry_interesting() handling code
95 if (!match) {
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
96 strbuf_addstr(base, name);
97 if (base->len)
98 strbuf_addch(base, '/');
99 }
100
6fda5e51 »
2007-03-21 Initialize tree descriptors with a helper function rather than by hand.
101 init_tree_desc(&desc, tree->buffer, tree->size);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
102
103 while (tree_entry(&desc, &entry)) {
d688cf07 »
2011-10-24 tree_entry_interesting(): give meaningful names to return values
104 if (match != all_entries_interesting) {
97d0b74a »
2011-03-25 Improve tree_entry_interesting() handling code
105 match = tree_entry_interesting(&entry, base, 0,
106 &revs->diffopt.pathspec);
d688cf07 »
2011-10-24 tree_entry_interesting(): give meaningful names to return values
107 if (match == all_entries_not_interesting)
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
108 break;
d688cf07 »
2011-10-24 tree_entry_interesting(): give meaningful names to return values
109 if (match == entry_not_interesting)
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
110 continue;
111 }
112
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
113 if (S_ISDIR(entry.mode))
114 process_tree(revs,
115 lookup_tree(entry.sha1),
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
116 show, &me, base, entry.path,
117 cb_data);
302b9282 »
2007-05-21 rename dirlink to gitlink.
118 else if (S_ISGITLINK(entry.mode))
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
119 process_gitlink(revs, entry.sha1,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
120 show, &me, entry.path,
121 cb_data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
122 else
123 process_blob(revs,
124 lookup_blob(entry.sha1),
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
125 show, &me, entry.path,
126 cb_data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
127 }
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
128 strbuf_setlen(base, baselen);
6e454b9a »
2013-06-05 clear parsed flag when we free tree buffers
129 free_tree_buffer(tree);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
130 }
131
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
132 static void mark_edge_parents_uninteresting(struct commit *commit,
133 struct rev_info *revs,
134 show_edge_fn show_edge)
135 {
136 struct commit_list *parents;
137
138 for (parents = commit->parents; parents; parents = parents->next) {
139 struct commit *parent = parents->item;
140 if (!(parent->object.flags & UNINTERESTING))
141 continue;
142 mark_tree_uninteresting(parent->tree);
143 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
144 parent->object.flags |= SHOWN;
145 show_edge(parent);
146 }
147 }
148 }
149
e76a5fb4 »
2013-08-16 list-objects: reduce one argument in mark_edges_uninteresting
150 void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
151 {
e76a5fb4 »
2013-08-16 list-objects: reduce one argument in mark_edges_uninteresting
152 struct commit_list *list;
fbd4a703 »
2013-08-16 list-objects: mark more commits as edges in mark_edges_uninteresting
153 int i;
154
e76a5fb4 »
2013-08-16 list-objects: reduce one argument in mark_edges_uninteresting
155 for (list = revs->commits; list; list = list->next) {
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
156 struct commit *commit = list->item;
157
158 if (commit->object.flags & UNINTERESTING) {
159 mark_tree_uninteresting(commit->tree);
fbd4a703 »
2013-08-16 list-objects: mark more commits as edges in mark_edges_uninteresting
160 if (revs->edge_hint && !(commit->object.flags & SHOWN)) {
161 commit->object.flags |= SHOWN;
162 show_edge(commit);
163 }
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
164 continue;
165 }
166 mark_edge_parents_uninteresting(commit, revs, show_edge);
167 }
200abe74 »
2014-01-20 list-objects: only look at cmdline trees with edge_hint
168 if (revs->edge_hint) {
169 for (i = 0; i < revs->cmdline.nr; i++) {
170 struct object *obj = revs->cmdline.rev[i].item;
171 struct commit *commit = (struct commit *)obj;
172 if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
173 continue;
174 mark_tree_uninteresting(commit->tree);
175 if (!(obj->flags & SHOWN)) {
176 obj->flags |= SHOWN;
177 show_edge(commit);
178 }
fbd4a703 »
2013-08-16 list-objects: mark more commits as edges in mark_edges_uninteresting
179 }
180 }
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
181 }
182
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
183 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
184 {
185 add_pending_object(revs, &tree->object, "");
186 }
187
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
188 void traverse_commit_list(struct rev_info *revs,
11c211fa »
2009-04-06 list-objects: add "void *data" parameter to show functions
189 show_commit_fn show_commit,
190 show_object_fn show_object,
191 void *data)
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
192 {
193 int i;
194 struct commit *commit;
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
195 struct strbuf base;
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
196
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
197 strbuf_init(&base, PATH_MAX);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
198 while ((commit = get_revision(revs)) != NULL) {
6e7d0efa »
2011-03-14 list-objects.c: don't add an unparsed NULL as a pending tree
199 /*
200 * an uninteresting boundary commit may not have its tree
201 * parsed yet, but we are not going to show them anyway
202 */
203 if (commit->tree)
204 add_pending_tree(revs, commit->tree);
11c211fa »
2009-04-06 list-objects: add "void *data" parameter to show functions
205 show_commit(commit, data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
206 }
207 for (i = 0; i < revs->pending.nr; i++) {
208 struct object_array_entry *pending = revs->pending.objects + i;
209 struct object *obj = pending->item;
210 const char *name = pending->name;
211 if (obj->flags & (UNINTERESTING | SEEN))
212 continue;
213 if (obj->type == OBJ_TAG) {
214 obj->flags |= SEEN;
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
215 show_object(obj, NULL, name, data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
216 continue;
217 }
218 if (obj->type == OBJ_TREE) {
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
219 process_tree(revs, (struct tree *)obj, show_object,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
220 NULL, &base, name, data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
221 continue;
222 }
223 if (obj->type == OBJ_BLOB) {
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
224 process_blob(revs, (struct blob *)obj, show_object,
49473672 »
2011-09-01 list-objects: pass callback data to show_objects()
225 NULL, name, data);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
226 continue;
227 }
228 die("unknown pending object %s (%s)",
229 sha1_to_hex(obj->sha1), name);
230 }
295dd2ad »
2007-11-09 Fix memory leak in traverse_commit_list
231 if (revs->pending.nr) {
232 free(revs->pending.objects);
233 revs->pending.nr = 0;
234 revs->pending.alloc = 0;
235 revs->pending.objects = NULL;
236 }
cc5fa2fd »
2010-12-17 Make rev-list --objects work together with pathspecs
237 strbuf_release(&base);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
238 }
Something went wrong with that request. Please try again.