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>
This commit is contained in:
Junio C Hamano
2011-09-01 15:43:33 -07:00
parent beba25abbc
commit 4947367267
5 changed files with 32 additions and 19 deletions

View File

@ -1936,7 +1936,9 @@ static void show_commit(struct commit *commit, void *data)
commit->object.flags |= OBJECT_ADDED; commit->object.flags |= OBJECT_ADDED;
} }
static void show_object(struct object *obj, const struct name_path *path, const char *last) static void show_object(struct object *obj,
const struct name_path *path, const char *last,
void *data)
{ {
char *name = path_name(path, last); char *name = path_name(path, last);

View File

@ -168,15 +168,19 @@ static void finish_commit(struct commit *commit, void *data)
commit->buffer = NULL; commit->buffer = NULL;
} }
static void finish_object(struct object *obj, const struct name_path *path, const char *name) static void finish_object(struct object *obj,
const struct name_path *path, const char *name,
void *cb_data)
{ {
if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1)) if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
die("missing blob object '%s'", sha1_to_hex(obj->sha1)); die("missing blob object '%s'", sha1_to_hex(obj->sha1));
} }
static void show_object(struct object *obj, const struct name_path *path, const char *component) static void show_object(struct object *obj,
const struct name_path *path, const char *component,
void *cb_data)
{ {
finish_object(obj, path, component); finish_object(obj, path, component, cb_data);
show_object_with_name(stdout, obj, path, component); show_object_with_name(stdout, obj, path, component);
} }

View File

@ -12,7 +12,8 @@ static void process_blob(struct rev_info *revs,
struct blob *blob, struct blob *blob,
show_object_fn show, show_object_fn show,
struct name_path *path, struct name_path *path,
const char *name) const char *name,
void *cb_data)
{ {
struct object *obj = &blob->object; struct object *obj = &blob->object;
@ -23,7 +24,7 @@ static void process_blob(struct rev_info *revs,
if (obj->flags & (UNINTERESTING | SEEN)) if (obj->flags & (UNINTERESTING | SEEN))
return; return;
obj->flags |= SEEN; obj->flags |= SEEN;
show(obj, path, name); show(obj, path, name, cb_data);
} }
/* /*
@ -52,7 +53,8 @@ static void process_gitlink(struct rev_info *revs,
const unsigned char *sha1, const unsigned char *sha1,
show_object_fn show, show_object_fn show,
struct name_path *path, struct name_path *path,
const char *name) const char *name,
void *cb_data)
{ {
/* Nothing to do */ /* Nothing to do */
} }
@ -62,7 +64,8 @@ static void process_tree(struct rev_info *revs,
show_object_fn show, show_object_fn show,
struct name_path *path, struct name_path *path,
struct strbuf *base, struct strbuf *base,
const char *name) const char *name,
void *cb_data)
{ {
struct object *obj = &tree->object; struct object *obj = &tree->object;
struct tree_desc desc; struct tree_desc desc;
@ -80,7 +83,7 @@ static void process_tree(struct rev_info *revs,
if (parse_tree(tree) < 0) if (parse_tree(tree) < 0)
die("bad tree object %s", sha1_to_hex(obj->sha1)); die("bad tree object %s", sha1_to_hex(obj->sha1));
obj->flags |= SEEN; obj->flags |= SEEN;
show(obj, path, name); show(obj, path, name, cb_data);
me.up = path; me.up = path;
me.elem = name; me.elem = name;
me.elem_len = strlen(name); me.elem_len = strlen(name);
@ -106,14 +109,17 @@ static void process_tree(struct rev_info *revs,
if (S_ISDIR(entry.mode)) if (S_ISDIR(entry.mode))
process_tree(revs, process_tree(revs,
lookup_tree(entry.sha1), lookup_tree(entry.sha1),
show, &me, base, entry.path); show, &me, base, entry.path,
cb_data);
else if (S_ISGITLINK(entry.mode)) else if (S_ISGITLINK(entry.mode))
process_gitlink(revs, entry.sha1, process_gitlink(revs, entry.sha1,
show, &me, entry.path); show, &me, entry.path,
cb_data);
else else
process_blob(revs, process_blob(revs,
lookup_blob(entry.sha1), lookup_blob(entry.sha1),
show, &me, entry.path); show, &me, entry.path,
cb_data);
} }
strbuf_setlen(base, baselen); strbuf_setlen(base, baselen);
free(tree->buffer); free(tree->buffer);
@ -185,17 +191,17 @@ void traverse_commit_list(struct rev_info *revs,
continue; continue;
if (obj->type == OBJ_TAG) { if (obj->type == OBJ_TAG) {
obj->flags |= SEEN; obj->flags |= SEEN;
show_object(obj, NULL, name); show_object(obj, NULL, name, data);
continue; continue;
} }
if (obj->type == OBJ_TREE) { if (obj->type == OBJ_TREE) {
process_tree(revs, (struct tree *)obj, show_object, process_tree(revs, (struct tree *)obj, show_object,
NULL, &base, name); NULL, &base, name, data);
continue; continue;
} }
if (obj->type == OBJ_BLOB) { if (obj->type == OBJ_BLOB) {
process_blob(revs, (struct blob *)obj, show_object, process_blob(revs, (struct blob *)obj, show_object,
NULL, name); NULL, name, data);
continue; continue;
} }
die("unknown pending object %s (%s)", die("unknown pending object %s (%s)",

View File

@ -2,11 +2,10 @@
#define LIST_OBJECTS_H #define LIST_OBJECTS_H
typedef void (*show_commit_fn)(struct commit *, void *); typedef void (*show_commit_fn)(struct commit *, void *);
typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *); typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *, void *);
typedef void (*show_edge_fn)(struct commit *);
void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *); void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
typedef void (*show_edge_fn)(struct commit *);
void mark_edges_uninteresting(struct commit_list *, struct rev_info *, show_edge_fn); void mark_edges_uninteresting(struct commit_list *, struct rev_info *, show_edge_fn);
#endif #endif

View File

@ -83,7 +83,9 @@ static void show_commit(struct commit *commit, void *data)
commit->buffer = NULL; commit->buffer = NULL;
} }
static void show_object(struct object *obj, const struct name_path *path, const char *component) static void show_object(struct object *obj,
const struct name_path *path, const char *component,
void *cb_data)
{ {
show_object_with_name(pack_pipe, obj, path, component); show_object_with_name(pack_pipe, obj, path, component);
} }