{"thread":{"id":"18946","subject":"[PATCH 2/5] rev-list: refactor printing bisect vars","startedAt":"2009-04-19T09:55:43Z","lastAt":"2009-04-19T09:55:43Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"111636","messageId":"20090419115543.ed8220e4.chriscool@tuxfamily.org","threadId":"18946","inReplyTo":null,"subject":"[PATCH 2/5] rev-list: refactor printing bisect vars","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-04-19T09:55:43Z","receivedAt":"2009-04-19T09:55:43Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This simplifies the code, and while at it we create the\n\"print_commit_list\" function that will be reused later.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n bisect.h           |    4 +++\n builtin-rev-list.c |   61 ++++++++++++++++++++++++++++-----------------------\n 2 files changed, 37 insertions(+), 28 deletions(-)\n\ndiff --git a/bisect.h b/bisect.h\nindex cb37ddf..89aa6cb 100644\n--- a/bisect.h\n+++ b/bisect.h\n@@ -9,6 +9,10 @@ extern struct commit_list *filter_skipped(struct commit_list *list,\n \t\t\t\t\t  struct commit_list **tried,\n \t\t\t\t\t  int show_all);\n \n+extern void print_commit_list(struct commit_list *list,\n+\t\t\t      const char *format_cur,\n+\t\t\t      const char *format_last);\n+\n /* bisect_show_flags flags in struct rev_list_info */\n #define BISECT_SHOW_ALL\t\t(1<<0)\n #define BISECT_SHOW_TRIED\t(1<<1)\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 4c5f5ee..d6ec787 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -225,20 +225,37 @@ int estimate_bisect_steps(int all)\n \treturn (e < 3 * x) ? n : n - 1;\n }\n \n+void print_commit_list(struct commit_list *list,\n+\t\t       const char *format_cur,\n+\t\t       const char *format_last)\n+{\n+\tfor (;list; list = list->next) {\n+\t\tconst char *format = list->next ? format_cur : format_last;\n+\t\tprintf(format, sha1_to_hex(list->item->object.sha1));\n+\t}\n+}\n+\n static void show_tried_revs(struct commit_list *tried, int stringed)\n {\n \tprintf(\"bisect_tried='\");\n-\tfor (;tried; tried = tried->next) {\n-\t\tchar *format = tried->next ? \"%s|\" : \"%s\";\n-\t\tprintf(format, sha1_to_hex(tried->item->object.sha1));\n-\t}\n+\tprint_commit_list(tried, \"%s|\", \"%s\");\n \tprintf(stringed ? \"' &&\\n\" : \"'\\n\");\n }\n \n+static void print_var_str(const char *var, const char *val, int stringed)\n+{\n+\tprintf(\"%s='%s'%s\\n\", var, val, stringed ? \" &&\" : \"\");\n+}\n+\n+static void print_var_int(const char *var, int val, int stringed)\n+{\n+\tprintf(\"%s=%d%s\\n\", var, val, stringed ? \" &&\" : \"\");\n+}\n+\n int show_bisect_vars(struct rev_list_info *info, int reaches, int all)\n {\n-\tint cnt, flags = info->bisect_show_flags;\n-\tchar hex[41] = \"\", *format;\n+\tint cnt, stringed, flags = info->bisect_show_flags;\n+\tchar hex[41] = \"\";\n \tstruct commit_list *tried;\n \tstruct rev_info *revs = info->revs;\n \n@@ -268,29 +285,17 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)\n \t\tprintf(\"------\\n\");\n \t}\n \n+\tstringed = flags & BISECT_SHOW_STRINGED;\n+\n \tif (flags & BISECT_SHOW_TRIED)\n-\t\tshow_tried_revs(tried, flags & BISECT_SHOW_STRINGED);\n-\tformat = (flags & BISECT_SHOW_STRINGED) ?\n-\t\t\"bisect_rev=%s &&\\n\"\n-\t\t\"bisect_nr=%d &&\\n\"\n-\t\t\"bisect_good=%d &&\\n\"\n-\t\t\"bisect_bad=%d &&\\n\"\n-\t\t\"bisect_all=%d &&\\n\"\n-\t\t\"bisect_steps=%d\\n\"\n-\t\t:\n-\t\t\"bisect_rev=%s\\n\"\n-\t\t\"bisect_nr=%d\\n\"\n-\t\t\"bisect_good=%d\\n\"\n-\t\t\"bisect_bad=%d\\n\"\n-\t\t\"bisect_all=%d\\n\"\n-\t\t\"bisect_steps=%d\\n\";\n-\tprintf(format,\n-\t       hex,\n-\t       cnt - 1,\n-\t       all - reaches - 1,\n-\t       reaches - 1,\n-\t       all,\n-\t       estimate_bisect_steps(all));\n+\t\tshow_tried_revs(tried, stringed);\n+\n+\tprint_var_str(\"bisect_rev\", hex, stringed);\n+\tprint_var_int(\"bisect_nr\", cnt - 1, stringed);\n+\tprint_var_int(\"bisect_good\", all - reaches - 1, stringed);\n+\tprint_var_int(\"bisect_bad\", reaches - 1, stringed);\n+\tprint_var_int(\"bisect_all\", all, stringed);\n+\tprint_var_int(\"bisect_steps\", estimate_bisect_steps(all), 0);\n \n \treturn 0;\n }\n-- \n1.6.2.2.537.g3b83b\n"}]}