Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 184 lines (169 sloc) 4.765 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,
15 const char *name)
16 {
17 struct object *obj = &blob->object;
18
19 if (!revs->blob_objects)
20 return;
a301b0c8 »
2008-02-18 list-objects.c::process_tree/blob: check for NULL
21 if (!obj)
22 die("bad blob object");
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
23 if (obj->flags & (UNINTERESTING | SEEN))
24 return;
25 obj->flags |= SEEN;
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
26 show(obj, path_name(path, name));
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
27 }
28
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
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,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
53 show_object_fn show,
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
54 struct name_path *path,
55 const char *name)
56 {
57 /* Nothing to do */
58 }
59
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
60 static void process_tree(struct rev_info *revs,
61 struct tree *tree,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
62 show_object_fn show,
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
63 struct name_path *path,
64 const char *name)
65 {
66 struct object *obj = &tree->object;
67 struct tree_desc desc;
68 struct name_entry entry;
69 struct name_path me;
70
71 if (!revs->tree_objects)
72 return;
a301b0c8 »
2008-02-18 list-objects.c::process_tree/blob: check for NULL
73 if (!obj)
74 die("bad tree object");
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
75 if (obj->flags & (UNINTERESTING | SEEN))
76 return;
77 if (parse_tree(tree) < 0)
78 die("bad tree object %s", sha1_to_hex(obj->sha1));
79 obj->flags |= SEEN;
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
80 show(obj, path_name(path, name));
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
81 me.up = path;
82 me.elem = name;
83 me.elem_len = strlen(name);
84
6fda5e51 »
2007-03-21 Initialize tree descriptors with a helper function rather than by hand.
85 init_tree_desc(&desc, tree->buffer, tree->size);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
86
87 while (tree_entry(&desc, &entry)) {
88 if (S_ISDIR(entry.mode))
89 process_tree(revs,
90 lookup_tree(entry.sha1),
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
91 show, &me, entry.path);
302b9282 »
2007-05-21 rename dirlink to gitlink.
92 else if (S_ISGITLINK(entry.mode))
6e2f441b »
2007-04-13 Teach git list-objects logic to not follow gitlinks
93 process_gitlink(revs, entry.sha1,
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
94 show, &me, entry.path);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
95 else
96 process_blob(revs,
97 lookup_blob(entry.sha1),
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
98 show, &me, entry.path);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
99 }
100 free(tree->buffer);
101 tree->buffer = NULL;
102 }
103
8d1d8f83 »
2006-09-06 pack-objects: further work on internal rev-list logic.
104 static void mark_edge_parents_uninteresting(struct commit *commit,
105 struct rev_info *revs,
106 show_edge_fn show_edge)
107 {
108 struct commit_list *parents;
109
110 for (parents = commit->parents; parents; parents = parents->next) {
111 struct commit *parent = parents->item;
112 if (!(parent->object.flags & UNINTERESTING))
113 continue;
114 mark_tree_uninteresting(parent->tree);
115 if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
116 parent->object.flags |= SHOWN;
117 show_edge(parent);
118 }
119 }
120 }
121
122 void mark_edges_uninteresting(struct commit_list *list,
123 struct rev_info *revs,
124 show_edge_fn show_edge)
125 {
126 for ( ; list; list = list->next) {
127 struct commit *commit = list->item;
128
129 if (commit->object.flags & UNINTERESTING) {
130 mark_tree_uninteresting(commit->tree);
131 continue;
132 }
133 mark_edge_parents_uninteresting(commit, revs, show_edge);
134 }
135 }
136
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
137 static void add_pending_tree(struct rev_info *revs, struct tree *tree)
138 {
139 add_pending_object(revs, &tree->object, "");
140 }
141
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
142 void traverse_commit_list(struct rev_info *revs,
143 void (*show_commit)(struct commit *),
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
144 void (*show_object)(struct object *, const char *))
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
145 {
146 int i;
147 struct commit *commit;
148
149 while ((commit = get_revision(revs)) != NULL) {
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
150 add_pending_tree(revs, commit->tree);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
151 show_commit(commit);
152 }
153 for (i = 0; i < revs->pending.nr; i++) {
154 struct object_array_entry *pending = revs->pending.objects + i;
155 struct object *obj = pending->item;
156 const char *name = pending->name;
157 if (obj->flags & (UNINTERESTING | SEEN))
158 continue;
159 if (obj->type == OBJ_TAG) {
160 obj->flags |= SEEN;
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
161 show_object(obj, name);
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
162 continue;
163 }
164 if (obj->type == OBJ_TREE) {
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
165 process_tree(revs, (struct tree *)obj, show_object,
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
166 NULL, name);
167 continue;
168 }
169 if (obj->type == OBJ_BLOB) {
8d2dfc49 »
2009-04-10 process_{tree,blob}: show objects without buffering
170 process_blob(revs, (struct blob *)obj, show_object,
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
171 NULL, name);
172 continue;
173 }
174 die("unknown pending object %s (%s)",
175 sha1_to_hex(obj->sha1), name);
176 }
295dd2ad »
2007-11-09 Fix memory leak in traverse_commit_list
177 if (revs->pending.nr) {
178 free(revs->pending.objects);
179 revs->pending.nr = 0;
180 revs->pending.alloc = 0;
181 revs->pending.objects = NULL;
182 }
c64ed70d »
2006-09-04 Separate object listing routines out of rev-list
183 }
Something went wrong with that request. Please try again.