Skip to content

Commit 4947367

Browse files
committed
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 <[email protected]>
1 parent beba25a commit 4947367

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,9 @@ static void show_commit(struct commit *commit, void *data)
19361936
commit->object.flags |= OBJECT_ADDED;
19371937
}
19381938

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)
19401942
{
19411943
char *name = path_name(path, last);
19421944

builtin/rev-list.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,19 @@ static void finish_commit(struct commit *commit, void *data)
168168
commit->buffer = NULL;
169169
}
170170

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)
172174
{
173175
if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
174176
die("missing blob object '%s'", sha1_to_hex(obj->sha1));
175177
}
176178

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)
178182
{
179-
finish_object(obj, path, component);
183+
finish_object(obj, path, component, cb_data);
180184
show_object_with_name(stdout, obj, path, component);
181185
}
182186

list-objects.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ static void process_blob(struct rev_info *revs,
1212
struct blob *blob,
1313
show_object_fn show,
1414
struct name_path *path,
15-
const char *name)
15+
const char *name,
16+
void *cb_data)
1617
{
1718
struct object *obj = &blob->object;
1819

@@ -23,7 +24,7 @@ static void process_blob(struct rev_info *revs,
2324
if (obj->flags & (UNINTERESTING | SEEN))
2425
return;
2526
obj->flags |= SEEN;
26-
show(obj, path, name);
27+
show(obj, path, name, cb_data);
2728
}
2829

2930
/*
@@ -52,7 +53,8 @@ static void process_gitlink(struct rev_info *revs,
5253
const unsigned char *sha1,
5354
show_object_fn show,
5455
struct name_path *path,
55-
const char *name)
56+
const char *name,
57+
void *cb_data)
5658
{
5759
/* Nothing to do */
5860
}
@@ -62,7 +64,8 @@ static void process_tree(struct rev_info *revs,
6264
show_object_fn show,
6365
struct name_path *path,
6466
struct strbuf *base,
65-
const char *name)
67+
const char *name,
68+
void *cb_data)
6669
{
6770
struct object *obj = &tree->object;
6871
struct tree_desc desc;
@@ -80,7 +83,7 @@ static void process_tree(struct rev_info *revs,
8083
if (parse_tree(tree) < 0)
8184
die("bad tree object %s", sha1_to_hex(obj->sha1));
8285
obj->flags |= SEEN;
83-
show(obj, path, name);
86+
show(obj, path, name, cb_data);
8487
me.up = path;
8588
me.elem = name;
8689
me.elem_len = strlen(name);
@@ -106,14 +109,17 @@ static void process_tree(struct rev_info *revs,
106109
if (S_ISDIR(entry.mode))
107110
process_tree(revs,
108111
lookup_tree(entry.sha1),
109-
show, &me, base, entry.path);
112+
show, &me, base, entry.path,
113+
cb_data);
110114
else if (S_ISGITLINK(entry.mode))
111115
process_gitlink(revs, entry.sha1,
112-
show, &me, entry.path);
116+
show, &me, entry.path,
117+
cb_data);
113118
else
114119
process_blob(revs,
115120
lookup_blob(entry.sha1),
116-
show, &me, entry.path);
121+
show, &me, entry.path,
122+
cb_data);
117123
}
118124
strbuf_setlen(base, baselen);
119125
free(tree->buffer);
@@ -185,17 +191,17 @@ void traverse_commit_list(struct rev_info *revs,
185191
continue;
186192
if (obj->type == OBJ_TAG) {
187193
obj->flags |= SEEN;
188-
show_object(obj, NULL, name);
194+
show_object(obj, NULL, name, data);
189195
continue;
190196
}
191197
if (obj->type == OBJ_TREE) {
192198
process_tree(revs, (struct tree *)obj, show_object,
193-
NULL, &base, name);
199+
NULL, &base, name, data);
194200
continue;
195201
}
196202
if (obj->type == OBJ_BLOB) {
197203
process_blob(revs, (struct blob *)obj, show_object,
198-
NULL, name);
204+
NULL, name, data);
199205
continue;
200206
}
201207
die("unknown pending object %s (%s)",

list-objects.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#define LIST_OBJECTS_H
33

44
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 *);
86
void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
97

8+
typedef void (*show_edge_fn)(struct commit *);
109
void mark_edges_uninteresting(struct commit_list *, struct rev_info *, show_edge_fn);
1110

1211
#endif

upload-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ static void show_commit(struct commit *commit, void *data)
8383
commit->buffer = NULL;
8484
}
8585

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)
8789
{
8890
show_object_with_name(pack_pipe, obj, path, component);
8991
}

0 commit comments

Comments
 (0)