Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 211 lines (193 sloc) 5.32 kb
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
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,
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
13 show_object_fn show,
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
14 struct name_path *path,
15 const char *name)
16 {
17 struct object *obj = &blob->object;
18
19 if (!revs->blob_objects)
20 return;
a301b0c list-objects.c::process_tree/blob: check for NULL
Martin Koegler authored
21 if (!obj)
22 die("bad blob object");
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
23 if (obj->flags & (UNINTERESTING | SEEN))
24 return;
25 obj->flags |= SEEN;
cf2ab91 Linus Torvalds show_object(): push path_name() call further down
torvalds authored
26 show(obj, path, name);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
27 }
28
6e2f441 Linus Torvalds Teach git list-objects logic to not follow gitlinks
torvalds authored
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,
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
53 show_object_fn show,
6e2f441 Linus Torvalds Teach git list-objects logic to not follow gitlinks
torvalds authored
54 struct name_path *path,
55 const char *name)
56 {
57 /* Nothing to do */
58 }
59
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
60 static void process_tree(struct rev_info *revs,
61 struct tree *tree,
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
62 show_object_fn show,
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
63 struct name_path *path,
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
64 struct strbuf *base,
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
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;
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
71 int all_interesting = (revs->diffopt.pathspec.nr == 0);
72 int baselen = base->len;
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
73
74 if (!revs->tree_objects)
75 return;
a301b0c list-objects.c::process_tree/blob: check for NULL
Martin Koegler authored
76 if (!obj)
77 die("bad tree object");
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
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;
cf2ab91 Linus Torvalds show_object(): push path_name() call further down
torvalds authored
83 show(obj, path, name);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
84 me.up = path;
85 me.elem = name;
86 me.elem_len = strlen(name);
87
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
88 if (!all_interesting) {
89 strbuf_addstr(base, name);
90 if (base->len)
91 strbuf_addch(base, '/');
92 }
93
6fda5e5 Linus Torvalds Initialize tree descriptors with a helper function rather than by hand.
torvalds authored
94 init_tree_desc(&desc, tree->buffer, tree->size);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
95
96 while (tree_entry(&desc, &entry)) {
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
97 if (!all_interesting) {
98 int showit = tree_entry_interesting(&entry,
99 base, 0,
100 &revs->diffopt.pathspec);
101
102 if (showit < 0)
103 break;
104 else if (!showit)
105 continue;
106 else if (showit == 2)
107 all_interesting = 1;
108 }
109
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
110 if (S_ISDIR(entry.mode))
111 process_tree(revs,
112 lookup_tree(entry.sha1),
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
113 show, &me, base, entry.path);
302b928 Martin Waitz rename dirlink to gitlink.
tali authored
114 else if (S_ISGITLINK(entry.mode))
6e2f441 Linus Torvalds Teach git list-objects logic to not follow gitlinks
torvalds authored
115 process_gitlink(revs, entry.sha1,
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
116 show, &me, entry.path);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
117 else
118 process_blob(revs,
119 lookup_blob(entry.sha1),
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
120 show, &me, entry.path);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
121 }
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
122 strbuf_setlen(base, baselen);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
123 free(tree->buffer);
124 tree->buffer = NULL;
125 }
126
8d1d8f8 pack-objects: further work on internal rev-list logic.
Junio C Hamano authored
127 static void mark_edge_parents_uninteresting(struct commit *commit,
128 struct rev_info *revs,
129 show_edge_fn show_edge)
130 {
131 struct commit_list *parents;
132
133 for (parents = commit->parents; parents; parents = parents->next) {
134 struct commit *parent = parents->item;
135 if (!(parent->object.flags & UNINTERESTING))
136 continue;
137 mark_tree_uninteresting(parent->tree);
138 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
139 parent->object.flags |= SHOWN;
140 show_edge(parent);
141 }
142 }
143 }
144
145 void mark_edges_uninteresting(struct commit_list *list,
146 struct rev_info *revs,
147 show_edge_fn show_edge)
148 {
149 for ( ; list; list = list->next) {
150 struct commit *commit = list->item;
151
152 if (commit->object.flags & UNINTERESTING) {
153 mark_tree_uninteresting(commit->tree);
154 continue;
155 }
156 mark_edge_parents_uninteresting(commit, revs, show_edge);
157 }
158 }
159
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
160 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
161 {
162 add_pending_object(revs, &tree->object, "");
163 }
164
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
165 void traverse_commit_list(struct rev_info *revs,
11c211f Christian Couder list-objects: add "void *data" parameter to show functions
chriscool authored
166 show_commit_fn show_commit,
167 show_object_fn show_object,
168 void *data)
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
169 {
170 int i;
171 struct commit *commit;
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
172 struct strbuf base;
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
173
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
174 strbuf_init(&base, PATH_MAX);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
175 while ((commit = get_revision(revs)) != NULL) {
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
176 add_pending_tree(revs, commit->tree);
11c211f Christian Couder list-objects: add "void *data" parameter to show functions
chriscool authored
177 show_commit(commit, data);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
178 }
179 for (i = 0; i < revs->pending.nr; i++) {
180 struct object_array_entry *pending = revs->pending.objects + i;
181 struct object *obj = pending->item;
182 const char *name = pending->name;
183 if (obj->flags & (UNINTERESTING | SEEN))
184 continue;
185 if (obj->type == OBJ_TAG) {
186 obj->flags |= SEEN;
cf2ab91 Linus Torvalds show_object(): push path_name() call further down
torvalds authored
187 show_object(obj, NULL, name);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
188 continue;
189 }
190 if (obj->type == OBJ_TREE) {
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
191 process_tree(revs, (struct tree *)obj, show_object,
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
192 NULL, &base, name);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
193 continue;
194 }
195 if (obj->type == OBJ_BLOB) {
8d2dfc4 Linus Torvalds process_{tree,blob}: show objects without buffering
torvalds authored
196 process_blob(revs, (struct blob *)obj, show_object,
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
197 NULL, name);
198 continue;
199 }
200 die("unknown pending object %s (%s)",
201 sha1_to_hex(obj->sha1), name);
202 }
295dd2a Shawn O. Pearce Fix memory leak in traverse_commit_list
spearce authored
203 if (revs->pending.nr) {
204 free(revs->pending.objects);
205 revs->pending.nr = 0;
206 revs->pending.alloc = 0;
207 revs->pending.objects = NULL;
208 }
cc5fa2f newren Make rev-list --objects work together with pathspecs
newren authored
209 strbuf_release(&base);
c64ed70 Separate object listing routines out of rev-list
Junio C Hamano authored
210 }
Something went wrong with that request. Please try again.