list-objects: add "void *data" parameter to show functions

The goal of this patch is to get rid of the "static struct rev_info
revs" static variable in "builtin-rev-list.c".

To do that, we need to pass the revs to the "show_commit" function
in "builtin-rev-list.c" and this in turn means that the
"traverse_commit_list" function in "list-objects.c" must be passed
functions pointers to functions with 2 parameters instead of one.

So we have to change all the callers and all the functions passed
to "traverse_commit_list".

Anyway this makes the code more clean and more generic, so it
should be a good thing in the long run.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Christian Couder 2009-04-06 21:28:36 +02:00 committed by Junio C Hamano
parent e89aa6d2f5
commit 11c211fa06
5 changed files with 49 additions and 46 deletions

View File

@ -1901,13 +1901,13 @@ static void read_object_list_from_stdin(void)


#define OBJECT_ADDED (1u<<20) #define OBJECT_ADDED (1u<<20)


static void show_commit(struct commit *commit) static void show_commit(struct commit *commit, void *data)
{ {
add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0); add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0);
commit->object.flags |= OBJECT_ADDED; commit->object.flags |= OBJECT_ADDED;
} }


static void show_object(struct object_array_entry *p) static void show_object(struct object_array_entry *p, void *data)
{ {
add_preferred_base_object(p->name); add_preferred_base_object(p->name);
add_object_entry(p->item->sha1, p->item->type, p->name, 0); add_object_entry(p->item->sha1, p->item->type, p->name, 0);
@ -2071,7 +2071,7 @@ static void get_object_list(int ac, const char **av)
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
die("revision walk setup failed"); die("revision walk setup failed");
mark_edges_uninteresting(revs.commits, &revs, show_edge); mark_edges_uninteresting(revs.commits, &revs, show_edge);
traverse_commit_list(&revs, show_commit, show_object); traverse_commit_list(&revs, show_commit, show_object, NULL);


if (keep_unreachable) if (keep_unreachable)
add_objects_in_unpacked_packs(&revs); add_objects_in_unpacked_packs(&revs);

View File

@ -42,72 +42,72 @@ static const char rev_list_usage[] =
" --bisect-all" " --bisect-all"
; ;


static struct rev_info revs;

static int show_timestamp; static int show_timestamp;
static int hdr_termination; static int hdr_termination;
static const char *header_prefix; static const char *header_prefix;


static void finish_commit(struct commit *commit); static void finish_commit(struct commit *commit, void *data);
static void show_commit(struct commit *commit) static void show_commit(struct commit *commit, void *data)
{ {
graph_show_commit(revs.graph); struct rev_info *revs = data;

graph_show_commit(revs->graph);


if (show_timestamp) if (show_timestamp)
printf("%lu ", commit->date); printf("%lu ", commit->date);
if (header_prefix) if (header_prefix)
fputs(header_prefix, stdout); fputs(header_prefix, stdout);


if (!revs.graph) { if (!revs->graph) {
if (commit->object.flags & BOUNDARY) if (commit->object.flags & BOUNDARY)
putchar('-'); putchar('-');
else if (commit->object.flags & UNINTERESTING) else if (commit->object.flags & UNINTERESTING)
putchar('^'); putchar('^');
else if (revs.left_right) { else if (revs->left_right) {
if (commit->object.flags & SYMMETRIC_LEFT) if (commit->object.flags & SYMMETRIC_LEFT)
putchar('<'); putchar('<');
else else
putchar('>'); putchar('>');
} }
} }
if (revs.abbrev_commit && revs.abbrev) if (revs->abbrev_commit && revs->abbrev)
fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev), fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
stdout); stdout);
else else
fputs(sha1_to_hex(commit->object.sha1), stdout); fputs(sha1_to_hex(commit->object.sha1), stdout);
if (revs.print_parents) { if (revs->print_parents) {
struct commit_list *parents = commit->parents; struct commit_list *parents = commit->parents;
while (parents) { while (parents) {
printf(" %s", sha1_to_hex(parents->item->object.sha1)); printf(" %s", sha1_to_hex(parents->item->object.sha1));
parents = parents->next; parents = parents->next;
} }
} }
if (revs.children.name) { if (revs->children.name) {
struct commit_list *children; struct commit_list *children;


children = lookup_decoration(&revs.children, &commit->object); children = lookup_decoration(&revs->children, &commit->object);
while (children) { while (children) {
printf(" %s", sha1_to_hex(children->item->object.sha1)); printf(" %s", sha1_to_hex(children->item->object.sha1));
children = children->next; children = children->next;
} }
} }
show_decorations(&revs, commit); show_decorations(revs, commit);
if (revs.commit_format == CMIT_FMT_ONELINE) if (revs->commit_format == CMIT_FMT_ONELINE)
putchar(' '); putchar(' ');
else else
putchar('\n'); putchar('\n');


if (revs.verbose_header && commit->buffer) { if (revs->verbose_header && commit->buffer) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
pretty_print_commit(revs.commit_format, commit, pretty_print_commit(revs->commit_format, commit,
&buf, revs.abbrev, NULL, NULL, &buf, revs->abbrev, NULL, NULL,
revs.date_mode, 0); revs->date_mode, 0);
if (revs.graph) { if (revs->graph) {
if (buf.len) { if (buf.len) {
if (revs.commit_format != CMIT_FMT_ONELINE) if (revs->commit_format != CMIT_FMT_ONELINE)
graph_show_oneline(revs.graph); graph_show_oneline(revs->graph);


graph_show_commit_msg(revs.graph, &buf); graph_show_commit_msg(revs->graph, &buf);


/* /*
* Add a newline after the commit message. * Add a newline after the commit message.
@ -125,7 +125,7 @@ static void show_commit(struct commit *commit)
* format doesn't explicitly end in a newline.) * format doesn't explicitly end in a newline.)
*/ */
if (buf.len && buf.buf[buf.len - 1] == '\n') if (buf.len && buf.buf[buf.len - 1] == '\n')
graph_show_padding(revs.graph); graph_show_padding(revs->graph);
putchar('\n'); putchar('\n');
} else { } else {
/* /*
@ -133,7 +133,7 @@ static void show_commit(struct commit *commit)
* the rest of the graph output for this * the rest of the graph output for this
* commit. * commit.
*/ */
if (graph_show_remainder(revs.graph)) if (graph_show_remainder(revs->graph))
putchar('\n'); putchar('\n');
} }
} else { } else {
@ -142,14 +142,14 @@ static void show_commit(struct commit *commit)
} }
strbuf_release(&buf); strbuf_release(&buf);
} else { } else {
if (graph_show_remainder(revs.graph)) if (graph_show_remainder(revs->graph))
putchar('\n'); putchar('\n');
} }
maybe_flush_or_die(stdout, "stdout"); maybe_flush_or_die(stdout, "stdout");
finish_commit(commit); finish_commit(commit, data);
} }


static void finish_commit(struct commit *commit) static void finish_commit(struct commit *commit, void *data)
{ {
if (commit->parents) { if (commit->parents) {
free_commit_list(commit->parents); free_commit_list(commit->parents);
@ -159,20 +159,20 @@ static void finish_commit(struct commit *commit)
commit->buffer = NULL; commit->buffer = NULL;
} }


static void finish_object(struct object_array_entry *p) static void finish_object(struct object_array_entry *p, void *data)
{ {
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1)) if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
die("missing blob object '%s'", sha1_to_hex(p->item->sha1)); die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
} }


static void show_object(struct object_array_entry *p) static void show_object(struct object_array_entry *p, void *data)
{ {
/* An object with name "foo\n0000000..." can be used to /* An object with name "foo\n0000000..." can be used to
* confuse downstream "git pack-objects" very badly. * confuse downstream "git pack-objects" very badly.
*/ */
const char *ep = strchr(p->name, '\n'); const char *ep = strchr(p->name, '\n');


finish_object(p); finish_object(p, data);
if (ep) { if (ep) {
printf("%s %.*s\n", sha1_to_hex(p->item->sha1), printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
(int) (ep - p->name), (int) (ep - p->name),
@ -264,7 +264,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1)); strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));


if (flags & BISECT_SHOW_ALL) { if (flags & BISECT_SHOW_ALL) {
traverse_commit_list(revs, show_commit, show_object); traverse_commit_list(revs, show_commit, show_object, revs);
printf("------\n"); printf("------\n");
} }


@ -297,6 +297,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)


int cmd_rev_list(int argc, const char **argv, const char *prefix) int cmd_rev_list(int argc, const char **argv, const char *prefix)
{ {
struct rev_info revs;
struct commit_list *list; struct commit_list *list;
int i; int i;
int read_from_stdin = 0; int read_from_stdin = 0;
@ -391,8 +392,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
} }


traverse_commit_list(&revs, traverse_commit_list(&revs,
quiet ? finish_commit : show_commit, quiet ? finish_commit : show_commit,
quiet ? finish_object : show_object); quiet ? finish_object : show_object,
&revs);


return 0; return 0;
} }

View File

@ -137,8 +137,9 @@ void mark_edges_uninteresting(struct commit_list *list,
} }


void traverse_commit_list(struct rev_info *revs, void traverse_commit_list(struct rev_info *revs,
void (*show_commit)(struct commit *), show_commit_fn show_commit,
void (*show_object)(struct object_array_entry *)) show_object_fn show_object,
void *data)
{ {
int i; int i;
struct commit *commit; struct commit *commit;
@ -146,7 +147,7 @@ void traverse_commit_list(struct rev_info *revs,


while ((commit = get_revision(revs)) != NULL) { while ((commit = get_revision(revs)) != NULL) {
process_tree(revs, commit->tree, &objects, NULL, ""); process_tree(revs, commit->tree, &objects, NULL, "");
show_commit(commit); show_commit(commit, data);
} }
for (i = 0; i < revs->pending.nr; i++) { for (i = 0; i < revs->pending.nr; i++) {
struct object_array_entry *pending = revs->pending.objects + i; struct object_array_entry *pending = revs->pending.objects + i;
@ -173,7 +174,7 @@ void traverse_commit_list(struct rev_info *revs,
sha1_to_hex(obj->sha1), name); sha1_to_hex(obj->sha1), name);
} }
for (i = 0; i < objects.nr; i++) for (i = 0; i < objects.nr; i++)
show_object(&objects.objects[i]); show_object(&objects.objects[i], data);
free(objects.objects); free(objects.objects);
if (revs->pending.nr) { if (revs->pending.nr) {
free(revs->pending.objects); free(revs->pending.objects);

View File

@ -1,11 +1,11 @@
#ifndef LIST_OBJECTS_H #ifndef LIST_OBJECTS_H
#define LIST_OBJECTS_H #define LIST_OBJECTS_H


typedef void (*show_commit_fn)(struct commit *); typedef void (*show_commit_fn)(struct commit *, void *);
typedef void (*show_object_fn)(struct object_array_entry *); typedef void (*show_object_fn)(struct object_array_entry *, void *);
typedef void (*show_edge_fn)(struct commit *); typedef void (*show_edge_fn)(struct commit *);


void traverse_commit_list(struct rev_info *revs, show_commit_fn, show_object_fn); void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);


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);



View File

@ -66,7 +66,7 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
} }


static FILE *pack_pipe = NULL; static FILE *pack_pipe = NULL;
static void show_commit(struct commit *commit) static void show_commit(struct commit *commit, void *data)
{ {
if (commit->object.flags & BOUNDARY) if (commit->object.flags & BOUNDARY)
fputc('-', pack_pipe); fputc('-', pack_pipe);
@ -78,7 +78,7 @@ static void show_commit(struct commit *commit)
commit->buffer = NULL; commit->buffer = NULL;
} }


static void show_object(struct object_array_entry *p) static void show_object(struct object_array_entry *p, void *data)
{ {
/* An object with name "foo\n0000000..." can be used to /* An object with name "foo\n0000000..." can be used to
* confuse downstream git-pack-objects very badly. * confuse downstream git-pack-objects very badly.
@ -134,7 +134,7 @@ static int do_rev_list(int fd, void *create_full_pack)
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
die("revision walk setup failed"); die("revision walk setup failed");
mark_edges_uninteresting(revs.commits, &revs, show_edge); mark_edges_uninteresting(revs.commits, &revs, show_edge);
traverse_commit_list(&revs, show_commit, show_object); traverse_commit_list(&revs, show_commit, show_object, NULL);
fflush(pack_pipe); fflush(pack_pipe);
fclose(pack_pipe); fclose(pack_pipe);
return 0; return 0;