Skip to content

Commit 280e65c

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent 1c87654 commit 280e65c

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

bisect.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
99
struct commit_list **tried,
1010
int show_all);
1111

12+
extern void print_commit_list(struct commit_list *list,
13+
const char *format_cur,
14+
const char *format_last);
15+
1216
/* bisect_show_flags flags in struct rev_list_info */
1317
#define BISECT_SHOW_ALL (1<<0)
1418
#define BISECT_SHOW_TRIED (1<<1)

builtin-rev-list.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,37 @@ int estimate_bisect_steps(int all)
225225
return (e < 3 * x) ? n : n - 1;
226226
}
227227

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+
228238
static void show_tried_revs(struct commit_list *tried, int stringed)
229239
{
230240
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");
235242
printf(stringed ? "' &&\n" : "'\n");
236243
}
237244

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+
238255
int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
239256
{
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] = "";
242259
struct commit_list *tried;
243260
struct rev_info *revs = info->revs;
244261

@@ -268,29 +285,17 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
268285
printf("------\n");
269286
}
270287

288+
stringed = flags & BISECT_SHOW_STRINGED;
289+
271290
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);
294299

295300
return 0;
296301
}

0 commit comments

Comments
 (0)