Code

rev-list: refactor printing bisect vars
authorChristian Couder <chriscool@tuxfamily.org>
Sun, 19 Apr 2009 09:55:43 +0000 (11:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 May 2009 07:30:28 +0000 (00:30 -0700)
This simplifies the code, and while at it we create the
"print_commit_list" function that will be reused later.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bisect.h
builtin-rev-list.c

index cb37ddfac0c3aaba4a55e148c61c3c91d5288243..89aa6cb0b30989ce8b1ac17859efdb9d11c97035 100644 (file)
--- a/bisect.h
+++ b/bisect.h
@@ -9,6 +9,10 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
                                          struct commit_list **tried,
                                          int show_all);
 
+extern void print_commit_list(struct commit_list *list,
+                             const char *format_cur,
+                             const char *format_last);
+
 /* bisect_show_flags flags in struct rev_list_info */
 #define BISECT_SHOW_ALL                (1<<0)
 #define BISECT_SHOW_TRIED      (1<<1)
index 4c5f5eec0ede1d20e7cb3b568bfc8f4097295242..35f88ca425f8c960a7c1d76a18191c92fc118125 100644 (file)
@@ -225,20 +225,37 @@ int estimate_bisect_steps(int all)
        return (e < 3 * x) ? n : n - 1;
 }
 
+void print_commit_list(struct commit_list *list,
+                      const char *format_cur,
+                      const char *format_last)
+{
+       for ( ; list; list = list->next) {
+               const char *format = list->next ? format_cur : format_last;
+               printf(format, sha1_to_hex(list->item->object.sha1));
+       }
+}
+
 static void show_tried_revs(struct commit_list *tried, int stringed)
 {
        printf("bisect_tried='");
-       for (;tried; tried = tried->next) {
-               char *format = tried->next ? "%s|" : "%s";
-               printf(format, sha1_to_hex(tried->item->object.sha1));
-       }
+       print_commit_list(tried, "%s|", "%s");
        printf(stringed ? "' &&\n" : "'\n");
 }
 
+static void print_var_str(const char *var, const char *val, int stringed)
+{
+       printf("%s='%s'%s\n", var, val, stringed ? " &&" : "");
+}
+
+static void print_var_int(const char *var, int val, int stringed)
+{
+       printf("%s=%d%s\n", var, val, stringed ? " &&" : "");
+}
+
 int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 {
-       int cnt, flags = info->bisect_show_flags;
-       char hex[41] = "", *format;
+       int cnt, stringed, flags = info->bisect_show_flags;
+       char hex[41] = "";
        struct commit_list *tried;
        struct rev_info *revs = info->revs;
 
@@ -268,29 +285,17 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
                printf("------\n");
        }
 
+       stringed = flags & BISECT_SHOW_STRINGED;
+
        if (flags & BISECT_SHOW_TRIED)
-               show_tried_revs(tried, flags & BISECT_SHOW_STRINGED);
-       format = (flags & BISECT_SHOW_STRINGED) ?
-               "bisect_rev=%s &&\n"
-               "bisect_nr=%d &&\n"
-               "bisect_good=%d &&\n"
-               "bisect_bad=%d &&\n"
-               "bisect_all=%d &&\n"
-               "bisect_steps=%d\n"
-               :
-               "bisect_rev=%s\n"
-               "bisect_nr=%d\n"
-               "bisect_good=%d\n"
-               "bisect_bad=%d\n"
-               "bisect_all=%d\n"
-               "bisect_steps=%d\n";
-       printf(format,
-              hex,
-              cnt - 1,
-              all - reaches - 1,
-              reaches - 1,
-              all,
-              estimate_bisect_steps(all));
+               show_tried_revs(tried, stringed);
+
+       print_var_str("bisect_rev", hex, stringed);
+       print_var_int("bisect_nr", cnt - 1, stringed);
+       print_var_int("bisect_good", all - reaches - 1, stringed);
+       print_var_int("bisect_bad", reaches - 1, stringed);
+       print_var_int("bisect_all", all, stringed);
+       print_var_int("bisect_steps", estimate_bisect_steps(all), 0);
 
        return 0;
 }