list-objects: pass callback data to show_objects()

The traverse_commit_list() API takes two callback functions, one to show commit objects, and the other to show other kinds of objects. Even though the former has a callback data parameter, so that the callback does not have to rely on global state, the latter does not. Give the show_objects() callback the same callback data parameter. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 1, 2011 at 15:43 UTC 4947367267cbcd0ca528711b2393613e2e817878
5 files changed +32 -19
builtin/pack-objects.c
+3 -1
@@ -1936,7 +1936,9 @@ static void show_commit(struct commit *commit, void *data)
1936 commit->object.flags |= OBJECT_ADDED;
1937 }
1938
1939 -static void show_object(struct object *obj, const struct name_path *path, const char *last)
1939 +static void show_object(struct object *obj,
1940 + const struct name_path *path, const char *last,
1941 + void *data)
1942 {
1943 char *name = path_name(path, last);
1944
builtin/rev-list.c
+7 -3
@@ -168,15 +168,19 @@ static void finish_commit(struct commit *commit, void *data)
168 commit->buffer = NULL;
169 }
170
171 -static void finish_object(struct object *obj, const struct name_path *path, const char *name)
171 +static void finish_object(struct object *obj,
172 + const struct name_path *path, const char *name,
173 + void *cb_data)
174 {
175 if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
176 die("missing blob object '%s'", sha1_to_hex(obj->sha1));
177 }
178
177 -static void show_object(struct object *obj, const struct name_path *path, const char *component)
179 +static void show_object(struct object *obj,
180 + const struct name_path *path, const char *component,
181 + void *cb_data)
182 {
179 - finish_object(obj, path, component);
183 + finish_object(obj, path, component, cb_data);
184 show_object_with_name(stdout, obj, path, component);
185 }
186
list-objects.c
+17 -11
@@ -12,7 +12,8 @@ static void process_blob(struct rev_info *revs,
12 struct blob *blob,
13 show_object_fn show,
14 struct name_path *path,
15 - const char *name)
15 + const char *name,
16 + void *cb_data)
17 {
18 struct object *obj = &blob->object;
19
@@ -23,7 +24,7 @@ static void process_blob(struct rev_info *revs,
24 if (obj->flags & (UNINTERESTING | SEEN))
25 return;
26 obj->flags |= SEEN;
26 - show(obj, path, name);
27 + show(obj, path, name, cb_data);
28 }
29
30 /*
@@ -52,7 +53,8 @@ static void process_gitlink(struct rev_info *revs,
53 const unsigned char *sha1,
54 show_object_fn show,
55 struct name_path *path,
55 - const char *name)
56 + const char *name,
57 + void *cb_data)
58 {
59 /* Nothing to do */
60 }
@@ -62,7 +64,8 @@ static void process_tree(struct rev_info *revs,
64 show_object_fn show,
65 struct name_path *path,
66 struct strbuf *base,
65 - const char *name)
67 + const char *name,
68 + void *cb_data)
69 {
70 struct object *obj = &tree->object;
71 struct tree_desc desc;
@@ -80,7 +83,7 @@ static void process_tree(struct rev_info *revs,
83 if (parse_tree(tree) < 0)
84 die("bad tree object %s", sha1_to_hex(obj->sha1));
85 obj->flags |= SEEN;
83 - show(obj, path, name);
86 + show(obj, path, name, cb_data);
87 me.up = path;
88 me.elem = name;
89 me.elem_len = strlen(name);
@@ -106,14 +109,17 @@ static void process_tree(struct rev_info *revs,
109 if (S_ISDIR(entry.mode))
110 process_tree(revs,
111 lookup_tree(entry.sha1),
109 - show, &me, base, entry.path);
112 + show, &me, base, entry.path,
113 + cb_data);
114 else if (S_ISGITLINK(entry.mode))
115 process_gitlink(revs, entry.sha1,
112 - show, &me, entry.path);
116 + show, &me, entry.path,
117 + cb_data);
118 else
119 process_blob(revs,
120 lookup_blob(entry.sha1),
116 - show, &me, entry.path);
121 + show, &me, entry.path,
122 + cb_data);
123 }
124 strbuf_setlen(base, baselen);
125 free(tree->buffer);
@@ -185,17 +191,17 @@ void traverse_commit_list(struct rev_info *revs,
191 continue;
192 if (obj->type == OBJ_TAG) {
193 obj->flags |= SEEN;
188 - show_object(obj, NULL, name);
194 + show_object(obj, NULL, name, data);
195 continue;
196 }
197 if (obj->type == OBJ_TREE) {
198 process_tree(revs, (struct tree *)obj, show_object,
193 - NULL, &base, name);
199 + NULL, &base, name, data);
200 continue;
201 }
202 if (obj->type == OBJ_BLOB) {
203 process_blob(revs, (struct blob *)obj, show_object,
198 - NULL, name);
204 + NULL, name, data);
205 continue;
206 }
207 die("unknown pending object %s (%s)",
list-objects.h
+2 -3
@@ -2,11 +2,10 @@
2 #define LIST_OBJECTS_H
3
4 typedef void (*show_commit_fn)(struct commit *, void *);
5 -typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *);
6 -typedef void (*show_edge_fn)(struct commit *);
7 -
5 +typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *, void *);
6 void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
7
8 +typedef void (*show_edge_fn)(struct commit *);
9 void mark_edges_uninteresting(struct commit_list *, struct rev_info *, show_edge_fn);
10
11 #endif
upload-pack.c
+3 -1
@@ -83,7 +83,9 @@ static void show_commit(struct commit *commit, void *data)
83 commit->buffer = NULL;
84 }
85
86 -static void show_object(struct object *obj, const struct name_path *path, const char *component)
86 +static void show_object(struct object *obj,
87 + const struct name_path *path, const char *component,
88 + void *cb_data)
89 {
90 show_object_with_name(pack_pipe, obj, path, component);
91 }