rev-list: refactor printing bisect vars
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>
Christian Couder committed
Apr 19, 2009 at 11:55 UTC
280e65cbd83a867437cef3543d445013ecbfe29a
2 files changed
+37
-28
bisect.h
+4
@@ -9,6 +9,10 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
9
struct commit_list **tried,
10
int show_all);
11
12
+extern void print_commit_list(struct commit_list *list,
13
+ const char *format_cur,
14
+ const char *format_last);
15
+
16
/* bisect_show_flags flags in struct rev_list_info */
17
#define BISECT_SHOW_ALL (1<<0)
18
#define BISECT_SHOW_TRIED (1<<1)
builtin-rev-list.c
+33
-28
@@ -225,20 +225,37 @@ int estimate_bisect_steps(int all)
225
return (e < 3 * x) ? n : n - 1;
226
}
227
228
+void print_commit_list(struct commit_list *list,
229
+ const char *format_cur,
230
+ const char *format_last)
231
+{
232
+ for ( ; list; list = list->next) {
233
+ const char *format = list->next ? format_cur : format_last;
234
+ printf(format, sha1_to_hex(list->item->object.sha1));
235
+ }
236
+}
237
+
238
static void show_tried_revs(struct commit_list *tried, int stringed)
239
{
240
printf("bisect_tried='");
231
- for (;tried; tried = tried->next) {
232
- char *format = tried->next ? "%s|" : "%s";
233
- printf(format, sha1_to_hex(tried->item->object.sha1));
234
- }
241
+ print_commit_list(tried, "%s|", "%s");
242
printf(stringed ? "' &&\n" : "'\n");
243
}
244
245
+static void print_var_str(const char *var, const char *val, int stringed)
246
+{
247
+ printf("%s='%s'%s\n", var, val, stringed ? " &&" : "");
248
+}
249
+
250
+static void print_var_int(const char *var, int val, int stringed)
251
+{
252
+ printf("%s=%d%s\n", var, val, stringed ? " &&" : "");
253
+}
254
+
255
int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
256
{
240
- int cnt, flags = info->bisect_show_flags;
241
- char hex[41] = "", *format;
257
+ int cnt, stringed, flags = info->bisect_show_flags;
258
+ char hex[41] = "";
259
struct commit_list *tried;
260
struct rev_info *revs = info->revs;
261
@@ -268,29 +285,17 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
285
printf("------\n");
286
}
287
288
+ stringed = flags & BISECT_SHOW_STRINGED;
289
+
290
if (flags & BISECT_SHOW_TRIED)
272
- show_tried_revs(tried, flags & BISECT_SHOW_STRINGED);
273
- format = (flags & BISECT_SHOW_STRINGED) ?
274
- "bisect_rev=%s &&\n"
275
- "bisect_nr=%d &&\n"
276
- "bisect_good=%d &&\n"
277
- "bisect_bad=%d &&\n"
278
- "bisect_all=%d &&\n"
279
- "bisect_steps=%d\n"
280
- :
281
- "bisect_rev=%s\n"
282
- "bisect_nr=%d\n"
283
- "bisect_good=%d\n"
284
- "bisect_bad=%d\n"
285
- "bisect_all=%d\n"
286
- "bisect_steps=%d\n";
287
- printf(format,
288
- hex,
289
- cnt - 1,
290
- all - reaches - 1,
291
- reaches - 1,
292
- all,
293
- estimate_bisect_steps(all));
291
+ show_tried_revs(tried, stringed);
292
+
293
+ print_var_str("bisect_rev", hex, stringed);
294
+ print_var_int("bisect_nr", cnt - 1, stringed);
295
+ print_var_int("bisect_good", all - reaches - 1, stringed);
296
+ print_var_int("bisect_bad", reaches - 1, stringed);
297
+ print_var_int("bisect_all", all, stringed);
298
+ print_var_int("bisect_steps", estimate_bisect_steps(all), 0);
299
300
return 0;
301
}