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>
Christian Couder committed
Apr 6, 2009 at 21:28 UTC
11c211fa06fc396e8ee8132ef83e2f2763ff6976
5 files changed
+49
-46
builtin-pack-objects.c
+3
-3
@@ -1901,13 +1901,13 @@ static void read_object_list_from_stdin(void)
1901
1902
#define OBJECT_ADDED (1u<<20)
1903
1904
-static void show_commit(struct commit *commit)
1904
+static void show_commit(struct commit *commit, void *data)
1905
{
1906
add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0);
1907
commit->object.flags |= OBJECT_ADDED;
1908
}
1909
1910
-static void show_object(struct object_array_entry *p)
1910
+static void show_object(struct object_array_entry *p, void *data)
1911
{
1912
add_preferred_base_object(p->name);
1913
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)
2071
if (prepare_revision_walk(&revs))
2072
die("revision walk setup failed");
2073
mark_edges_uninteresting(revs.commits, &revs, show_edge);
2074
- traverse_commit_list(&revs, show_commit, show_object);
2074
+ traverse_commit_list(&revs, show_commit, show_object, NULL);
2075
2076
if (keep_unreachable)
2077
add_objects_in_unpacked_packs(&revs);
builtin-rev-list.c
+35
-33
@@ -42,72 +42,72 @@ static const char rev_list_usage[] =
42
" --bisect-all"
43
;
44
45
-static struct rev_info revs;
46
-
45
static int show_timestamp;
46
static int hdr_termination;
47
static const char *header_prefix;
48
51
-static void finish_commit(struct commit *commit);
52
-static void show_commit(struct commit *commit)
49
+static void finish_commit(struct commit *commit, void *data);
50
+static void show_commit(struct commit *commit, void *data)
51
{
54
- graph_show_commit(revs.graph);
52
+ struct rev_info *revs = data;
53
+
54
+ graph_show_commit(revs->graph);
55
56
if (show_timestamp)
57
printf("%lu ", commit->date);
58
if (header_prefix)
59
fputs(header_prefix, stdout);
60
61
- if (!revs.graph) {
61
+ if (!revs->graph) {
62
if (commit->object.flags & BOUNDARY)
63
putchar('-');
64
else if (commit->object.flags & UNINTERESTING)
65
putchar('^');
66
- else if (revs.left_right) {
66
+ else if (revs->left_right) {
67
if (commit->object.flags & SYMMETRIC_LEFT)
68
putchar('<');
69
else
70
putchar('>');
71
}
72
}
73
- if (revs.abbrev_commit && revs.abbrev)
74
- fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
73
+ if (revs->abbrev_commit && revs->abbrev)
74
+ fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
75
stdout);
76
else
77
fputs(sha1_to_hex(commit->object.sha1), stdout);
78
- if (revs.print_parents) {
78
+ if (revs->print_parents) {
79
struct commit_list *parents = commit->parents;
80
while (parents) {
81
printf(" %s", sha1_to_hex(parents->item->object.sha1));
82
parents = parents->next;
83
}
84
}
85
- if (revs.children.name) {
85
+ if (revs->children.name) {
86
struct commit_list *children;
87
88
- children = lookup_decoration(&revs.children, &commit->object);
88
+ children = lookup_decoration(&revs->children, &commit->object);
89
while (children) {
90
printf(" %s", sha1_to_hex(children->item->object.sha1));
91
children = children->next;
92
}
93
}
94
- show_decorations(&revs, commit);
95
- if (revs.commit_format == CMIT_FMT_ONELINE)
94
+ show_decorations(revs, commit);
95
+ if (revs->commit_format == CMIT_FMT_ONELINE)
96
putchar(' ');
97
else
98
putchar('\n');
99
100
- if (revs.verbose_header && commit->buffer) {
100
+ if (revs->verbose_header && commit->buffer) {
101
struct strbuf buf = STRBUF_INIT;
102
- pretty_print_commit(revs.commit_format, commit,
103
- &buf, revs.abbrev, NULL, NULL,
104
- revs.date_mode, 0);
105
- if (revs.graph) {
102
+ pretty_print_commit(revs->commit_format, commit,
103
+ &buf, revs->abbrev, NULL, NULL,
104
+ revs->date_mode, 0);
105
+ if (revs->graph) {
106
if (buf.len) {
107
- if (revs.commit_format != CMIT_FMT_ONELINE)
108
- graph_show_oneline(revs.graph);
107
+ if (revs->commit_format != CMIT_FMT_ONELINE)
108
+ graph_show_oneline(revs->graph);
109
110
- graph_show_commit_msg(revs.graph, &buf);
110
+ graph_show_commit_msg(revs->graph, &buf);
111
112
/*
113
* Add a newline after the commit message.
@@ -125,7 +125,7 @@ static void show_commit(struct commit *commit)
125
* format doesn't explicitly end in a newline.)
126
*/
127
if (buf.len && buf.buf[buf.len - 1] == '\n')
128
- graph_show_padding(revs.graph);
128
+ graph_show_padding(revs->graph);
129
putchar('\n');
130
} else {
131
/*
@@ -133,7 +133,7 @@ static void show_commit(struct commit *commit)
133
* the rest of the graph output for this
134
* commit.
135
*/
136
- if (graph_show_remainder(revs.graph))
136
+ if (graph_show_remainder(revs->graph))
137
putchar('\n');
138
}
139
} else {
@@ -142,14 +142,14 @@ static void show_commit(struct commit *commit)
142
}
143
strbuf_release(&buf);
144
} else {
145
- if (graph_show_remainder(revs.graph))
145
+ if (graph_show_remainder(revs->graph))
146
putchar('\n');
147
}
148
maybe_flush_or_die(stdout, "stdout");
149
- finish_commit(commit);
149
+ finish_commit(commit, data);
150
}
151
152
-static void finish_commit(struct commit *commit)
152
+static void finish_commit(struct commit *commit, void *data)
153
{
154
if (commit->parents) {
155
free_commit_list(commit->parents);
@@ -159,20 +159,20 @@ static void finish_commit(struct commit *commit)
159
commit->buffer = NULL;
160
}
161
162
-static void finish_object(struct object_array_entry *p)
162
+static void finish_object(struct object_array_entry *p, void *data)
163
{
164
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
165
die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
166
}
167
168
-static void show_object(struct object_array_entry *p)
168
+static void show_object(struct object_array_entry *p, void *data)
169
{
170
/* An object with name "foo\n0000000..." can be used to
171
* confuse downstream "git pack-objects" very badly.
172
*/
173
const char *ep = strchr(p->name, '\n');
174
175
- finish_object(p);
175
+ finish_object(p, data);
176
if (ep) {
177
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
178
(int) (ep - p->name),
@@ -264,7 +264,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
264
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
265
266
if (flags & BISECT_SHOW_ALL) {
267
- traverse_commit_list(revs, show_commit, show_object);
267
+ traverse_commit_list(revs, show_commit, show_object, revs);
268
printf("------\n");
269
}
270
@@ -297,6 +297,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
297
298
int cmd_rev_list(int argc, const char **argv, const char *prefix)
299
{
300
+ struct rev_info revs;
301
struct commit_list *list;
302
int i;
303
int read_from_stdin = 0;
@@ -391,8 +392,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
392
}
393
394
traverse_commit_list(&revs,
394
- quiet ? finish_commit : show_commit,
395
- quiet ? finish_object : show_object);
395
+ quiet ? finish_commit : show_commit,
396
+ quiet ? finish_object : show_object,
397
+ &revs);
398
399
return 0;
400
}
list-objects.c
+5
-4
@@ -137,8 +137,9 @@ void mark_edges_uninteresting(struct commit_list *list,
137
}
138
139
void traverse_commit_list(struct rev_info *revs,
140
- void (*show_commit)(struct commit *),
141
- void (*show_object)(struct object_array_entry *))
140
+ show_commit_fn show_commit,
141
+ show_object_fn show_object,
142
+ void *data)
143
{
144
int i;
145
struct commit *commit;
@@ -146,7 +147,7 @@ void traverse_commit_list(struct rev_info *revs,
147
148
while ((commit = get_revision(revs)) != NULL) {
149
process_tree(revs, commit->tree, &objects, NULL, "");
149
- show_commit(commit);
150
+ show_commit(commit, data);
151
}
152
for (i = 0; i < revs->pending.nr; i++) {
153
struct object_array_entry *pending = revs->pending.objects + i;
@@ -173,7 +174,7 @@ void traverse_commit_list(struct rev_info *revs,
174
sha1_to_hex(obj->sha1), name);
175
}
176
for (i = 0; i < objects.nr; i++)
176
- show_object(&objects.objects[i]);
177
+ show_object(&objects.objects[i], data);
178
free(objects.objects);
179
if (revs->pending.nr) {
180
free(revs->pending.objects);
list-objects.h
+3
-3
@@ -1,11 +1,11 @@
1
#ifndef LIST_OBJECTS_H
2
#define LIST_OBJECTS_H
3
4
-typedef void (*show_commit_fn)(struct commit *);
5
-typedef void (*show_object_fn)(struct object_array_entry *);
4
+typedef void (*show_commit_fn)(struct commit *, void *);
5
+typedef void (*show_object_fn)(struct object_array_entry *, void *);
6
typedef void (*show_edge_fn)(struct commit *);
7
8
-void traverse_commit_list(struct rev_info *revs, show_commit_fn, show_object_fn);
8
+void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
9
10
void mark_edges_uninteresting(struct commit_list *, struct rev_info *, show_edge_fn);
11
upload-pack.c
+3
-3
@@ -66,7 +66,7 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
66
}
67
68
static FILE *pack_pipe = NULL;
69
-static void show_commit(struct commit *commit)
69
+static void show_commit(struct commit *commit, void *data)
70
{
71
if (commit->object.flags & BOUNDARY)
72
fputc('-', pack_pipe);
@@ -78,7 +78,7 @@ static void show_commit(struct commit *commit)
78
commit->buffer = NULL;
79
}
80
81
-static void show_object(struct object_array_entry *p)
81
+static void show_object(struct object_array_entry *p, void *data)
82
{
83
/* An object with name "foo\n0000000..." can be used to
84
* confuse downstream git-pack-objects very badly.
@@ -134,7 +134,7 @@ static int do_rev_list(int fd, void *create_full_pack)
134
if (prepare_revision_walk(&revs))
135
die("revision walk setup failed");
136
mark_edges_uninteresting(revs.commits, &revs, show_edge);
137
- traverse_commit_list(&revs, show_commit, show_object);
137
+ traverse_commit_list(&revs, show_commit, show_object, NULL);
138
fflush(pack_pipe);
139
fclose(pack_pipe);
140
return 0;