rev-list: remove last static vars used in "show_commit"
This patch removes the last static variables that were used in the "show_commit" function. To do that, we create a new "rev_list_info" struct that we will pass in the "void *data" argument to "show_commit". This means that we have to change the first argument to "show_bisect_vars" too. While at it, we also remove a "struct commit_list *list" variable in "cmd_rev_list" that is not really needed. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Apr 6, 2009 at 22:28 UTC
d797257eb280b67dd1f7153a66b03453c0fb927a
3 files changed
+34
-28
bisect.c
+5
-1
@@ -535,8 +535,12 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix)
535
int bisect_next_vars(const char *prefix)
536
{
537
struct rev_info revs;
538
+ struct rev_list_info info;
539
int reaches = 0, all = 0;
540
541
+ memset(&info, 0, sizeof(info));
542
+ info.revs = &revs;
543
+
544
bisect_rev_setup(&revs, prefix);
545
546
if (prepare_revision_walk(&revs))
@@ -547,6 +551,6 @@ int bisect_next_vars(const char *prefix)
551
revs.commits = find_bisection(revs.commits, &reaches, &all,
552
!!skipped_sha1_nr);
553
550
- return show_bisect_vars(&revs, reaches, all,
554
+ return show_bisect_vars(&info, reaches, all,
555
BISECT_SHOW_TRIED | BISECT_SHOW_STRINGED);
556
}
bisect.h
+8
-6
@@ -14,12 +14,14 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
14
#define BISECT_SHOW_TRIED (1<<1)
15
#define BISECT_SHOW_STRINGED (1<<2)
16
17
-/*
18
- * The flag BISECT_SHOW_ALL should not be set if this function is called
19
- * from outside "builtin-rev-list.c" as otherwise it would use
20
- * static "revs" from this file.
21
- */
22
-extern int show_bisect_vars(struct rev_info *revs, int reaches, int all,
17
+struct rev_list_info {
18
+ struct rev_info *revs;
19
+ int show_timestamp;
20
+ int hdr_termination;
21
+ const char *header_prefix;
22
+};
23
+
24
+extern int show_bisect_vars(struct rev_list_info *info, int reaches, int all,
25
int flags);
26
27
extern int bisect_next_vars(const char *prefix);
builtin-rev-list.c
+21
-21
@@ -42,21 +42,18 @@ static const char rev_list_usage[] =
42
" --bisect-all"
43
;
44
45
-static int show_timestamp;
46
-static int hdr_termination;
47
-static const char *header_prefix;
48
-
45
static void finish_commit(struct commit *commit, void *data);
46
static void show_commit(struct commit *commit, void *data)
47
{
52
- struct rev_info *revs = data;
48
+ struct rev_list_info *info = data;
49
+ struct rev_info *revs = info->revs;
50
51
graph_show_commit(revs->graph);
52
56
- if (show_timestamp)
53
+ if (info->show_timestamp)
54
printf("%lu ", commit->date);
58
- if (header_prefix)
59
- fputs(header_prefix, stdout);
55
+ if (info->header_prefix)
56
+ fputs(info->header_prefix, stdout);
57
58
if (!revs->graph) {
59
if (commit->object.flags & BOUNDARY)
@@ -138,7 +135,7 @@ static void show_commit(struct commit *commit, void *data)
135
}
136
} else {
137
if (buf.len)
141
- printf("%s%c", buf.buf, hdr_termination);
138
+ printf("%s%c", buf.buf, info->hdr_termination);
139
}
140
strbuf_release(&buf);
141
} else {
@@ -236,11 +233,13 @@ static void show_tried_revs(struct commit_list *tried, int stringed)
233
printf(stringed ? "' &&\n" : "'\n");
234
}
235
239
-int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
236
+int show_bisect_vars(struct rev_list_info *info, int reaches, int all,
237
+ int flags)
238
{
239
int cnt;
240
char hex[41] = "", *format;
241
struct commit_list *tried;
242
+ struct rev_info *revs = info->revs;
243
244
if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
245
return 1;
@@ -264,7 +263,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
263
strcpy(hex, sha1_to_hex(revs->commits->item->object.sha1));
264
265
if (flags & BISECT_SHOW_ALL) {
267
- traverse_commit_list(revs, show_commit, show_object, revs);
266
+ traverse_commit_list(revs, show_commit, show_object, info);
267
printf("------\n");
268
}
269
@@ -298,7 +297,7 @@ int show_bisect_vars(struct rev_info *revs, int reaches, int all, int flags)
297
int cmd_rev_list(int argc, const char **argv, const char *prefix)
298
{
299
struct rev_info revs;
301
- struct commit_list *list;
300
+ struct rev_list_info info;
301
int i;
302
int read_from_stdin = 0;
303
int bisect_list = 0;
@@ -313,6 +312,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
312
revs.commit_format = CMIT_FMT_UNSPECIFIED;
313
argc = setup_revisions(argc, argv, &revs, NULL);
314
315
+ memset(&info, 0, sizeof(info));
316
+ info.revs = &revs;
317
+
318
quiet = DIFF_OPT_TST(&revs.diffopt, QUIET);
319
for (i = 1 ; i < argc; i++) {
320
const char *arg = argv[i];
@@ -322,7 +324,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
324
continue;
325
}
326
if (!strcmp(arg, "--timestamp")) {
325
- show_timestamp = 1;
327
+ info.show_timestamp = 1;
328
continue;
329
}
330
if (!strcmp(arg, "--bisect")) {
@@ -352,19 +354,17 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
354
}
355
if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
356
/* The command line has a --pretty */
355
- hdr_termination = '\n';
357
+ info.hdr_termination = '\n';
358
if (revs.commit_format == CMIT_FMT_ONELINE)
357
- header_prefix = "";
359
+ info.header_prefix = "";
360
else
359
- header_prefix = "commit ";
361
+ info.header_prefix = "commit ";
362
}
363
else if (revs.verbose_header)
364
/* Only --header was specified */
365
revs.commit_format = CMIT_FMT_RAW;
366
365
- list = revs.commits;
366
-
367
- if ((!list &&
367
+ if ((!revs.commits &&
368
(!(revs.tag_objects||revs.tree_objects||revs.blob_objects) &&
369
!revs.pending.nr)) ||
370
revs.diff)
@@ -387,14 +387,14 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
387
bisect_find_all);
388
389
if (bisect_show_vars)
390
- return show_bisect_vars(&revs, reaches, all,
390
+ return show_bisect_vars(&info, reaches, all,
391
bisect_show_all ? BISECT_SHOW_ALL : 0);
392
}
393
394
traverse_commit_list(&revs,
395
quiet ? finish_commit : show_commit,
396
quiet ? finish_object : show_object,
397
- &revs);
397
+ &info);
398
399
return 0;
400
}