summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e89aa6d)
raw | patch | inline | side by side (parent: e89aa6d)
author | Christian Couder <chriscool@tuxfamily.org> | |
Mon, 6 Apr 2009 19:28:36 +0000 (21:28 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 8 Apr 2009 05:12:38 +0000 (22:12 -0700) |
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>
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>
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 9fc3b355470466bd5663e1fca1fe759e18869ee2..82536359d6738463a8173f8100355117c825ec58 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
#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);
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_object_entry(p->item->sha1, p->item->type, p->name, 0);
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
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)
add_objects_in_unpacked_packs(&revs);
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index eb341477caa47ff11f969761d4a528444453a6ae..cd6f6b8fbbf3c246b53ee2308baad37a97987002 100644 (file)
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
" --bisect-all"
;
-static struct rev_info revs;
-
static int show_timestamp;
static int hdr_termination;
static const char *header_prefix;
-static void finish_commit(struct commit *commit);
-static void show_commit(struct commit *commit)
+static void finish_commit(struct commit *commit, void *data);
+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)
printf("%lu ", commit->date);
if (header_prefix)
fputs(header_prefix, stdout);
- if (!revs.graph) {
+ if (!revs->graph) {
if (commit->object.flags & BOUNDARY)
putchar('-');
else if (commit->object.flags & UNINTERESTING)
putchar('^');
- else if (revs.left_right) {
+ else if (revs->left_right) {
if (commit->object.flags & SYMMETRIC_LEFT)
putchar('<');
else
putchar('>');
}
}
- if (revs.abbrev_commit && revs.abbrev)
- fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
+ if (revs->abbrev_commit && revs->abbrev)
+ fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
stdout);
else
fputs(sha1_to_hex(commit->object.sha1), stdout);
- if (revs.print_parents) {
+ if (revs->print_parents) {
struct commit_list *parents = commit->parents;
while (parents) {
printf(" %s", sha1_to_hex(parents->item->object.sha1));
parents = parents->next;
}
}
- if (revs.children.name) {
+ if (revs->children.name) {
struct commit_list *children;
- children = lookup_decoration(&revs.children, &commit->object);
+ children = lookup_decoration(&revs->children, &commit->object);
while (children) {
printf(" %s", sha1_to_hex(children->item->object.sha1));
children = children->next;
}
}
- show_decorations(&revs, commit);
- if (revs.commit_format == CMIT_FMT_ONELINE)
+ show_decorations(revs, commit);
+ if (revs->commit_format == CMIT_FMT_ONELINE)
putchar(' ');
else
putchar('\n');
- if (revs.verbose_header && commit->buffer) {
+ if (revs->verbose_header && commit->buffer) {
struct strbuf buf = STRBUF_INIT;
- pretty_print_commit(revs.commit_format, commit,
- &buf, revs.abbrev, NULL, NULL,
- revs.date_mode, 0);
- if (revs.graph) {
+ pretty_print_commit(revs->commit_format, commit,
+ &buf, revs->abbrev, NULL, NULL,
+ revs->date_mode, 0);
+ if (revs->graph) {
if (buf.len) {
- if (revs.commit_format != CMIT_FMT_ONELINE)
- graph_show_oneline(revs.graph);
+ if (revs->commit_format != CMIT_FMT_ONELINE)
+ 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.
* format doesn't explicitly end in a newline.)
*/
if (buf.len && buf.buf[buf.len - 1] == '\n')
- graph_show_padding(revs.graph);
+ graph_show_padding(revs->graph);
putchar('\n');
} else {
/*
* the rest of the graph output for this
* commit.
*/
- if (graph_show_remainder(revs.graph))
+ if (graph_show_remainder(revs->graph))
putchar('\n');
}
} else {
}
strbuf_release(&buf);
} else {
- if (graph_show_remainder(revs.graph))
+ if (graph_show_remainder(revs->graph))
putchar('\n');
}
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) {
free_commit_list(commit->parents);
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))
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
* confuse downstream "git pack-objects" very badly.
*/
const char *ep = strchr(p->name, '\n');
- finish_object(p);
+ finish_object(p, data);
if (ep) {
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
(int) (ep - p->name),
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
if (flags & BISECT_SHOW_ALL) {
- traverse_commit_list(revs, show_commit, show_object);
+ traverse_commit_list(revs, show_commit, show_object, revs);
printf("------\n");
}
int cmd_rev_list(int argc, const char **argv, const char *prefix)
{
+ struct rev_info revs;
struct commit_list *list;
int i;
int read_from_stdin = 0;
}
traverse_commit_list(&revs,
- quiet ? finish_commit : show_commit,
- quiet ? finish_object : show_object);
+ quiet ? finish_commit : show_commit,
+ quiet ? finish_object : show_object,
+ &revs);
return 0;
}
diff --git a/list-objects.c b/list-objects.c
index c8b8375e4983794e601ba69a1c217a3c711835e9..208a4cb0027eeb3ded2d16905ad2029df70cd84a 100644 (file)
--- a/list-objects.c
+++ b/list-objects.c
}
void traverse_commit_list(struct rev_info *revs,
- void (*show_commit)(struct commit *),
- void (*show_object)(struct object_array_entry *))
+ show_commit_fn show_commit,
+ show_object_fn show_object,
+ void *data)
{
int i;
struct commit *commit;
while ((commit = get_revision(revs)) != NULL) {
process_tree(revs, commit->tree, &objects, NULL, "");
- show_commit(commit);
+ show_commit(commit, data);
}
for (i = 0; i < revs->pending.nr; i++) {
struct object_array_entry *pending = revs->pending.objects + i;
sha1_to_hex(obj->sha1), name);
}
for (i = 0; i < objects.nr; i++)
- show_object(&objects.objects[i]);
+ show_object(&objects.objects[i], data);
free(objects.objects);
if (revs->pending.nr) {
free(revs->pending.objects);
diff --git a/list-objects.h b/list-objects.h
index 0f41391ecc00eac324ea76de7654781c4fce094e..47fae2e4683e604b81c530a80494033a2e36ca35 100644 (file)
--- a/list-objects.h
+++ b/list-objects.h
#ifndef LIST_OBJECTS_H
#define LIST_OBJECTS_H
-typedef void (*show_commit_fn)(struct commit *);
-typedef void (*show_object_fn)(struct object_array_entry *);
+typedef void (*show_commit_fn)(struct commit *, void *);
+typedef void (*show_object_fn)(struct object_array_entry *, void *);
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);
diff --git a/upload-pack.c b/upload-pack.c
index a49d87244706a4faacaadf7916ec86f2e2c0f04e..495c99f80a9de2e28f0875560d920e5bb4155d7c 100644 (file)
--- a/upload-pack.c
+++ b/upload-pack.c
}
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)
fputc('-', pack_pipe);
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
* confuse downstream git-pack-objects very badly.
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
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);
fclose(pack_pipe);
return 0;