| 29 | #include "string-list.h" |
| 30 | |
| 31 | int cmd__progress(int argc, const char **argv) |
| 32 | { |
| 33 | const char *const default_title = "Working hard"; |
| 34 | struct string_list titles = STRING_LIST_INIT_DUP; |
| 35 | struct strbuf line = STRBUF_INIT; |
| 36 | struct progress *progress = NULL; |
| 37 | |
| 38 | const char *usage[] = { |
| 39 | "test-tool progress <stdin", |
| 40 | NULL |
| 41 | }; |
| 42 | struct option options[] = { |
| 43 | OPT_END(), |
| 44 | }; |
| 45 | |
| 46 | argc = parse_options(argc, argv, NULL, options, usage, 0); |
| 47 | if (argc) |
| 48 | usage_with_options(usage, options); |
| 49 | |
| 50 | progress_testing = 1; |
| 51 | while (strbuf_getline(&line, stdin) != EOF) { |
| 52 | char *end; |
| 53 | |
| 54 | if (skip_prefix(line.buf, "start ", (const char **) &end)) { |
| 55 | uint64_t total = strtoull(end, &end, 10); |
| 56 | const char *title; |
| 57 | |
| 58 | /* |
| 59 | * We can't use "end + 1" as an argument to |
| 60 | * start_progress(), it doesn't xstrdup() its |
| 61 | * "title" argument. We need to hold onto a |
| 62 | * valid "char *" for it until the end. |
| 63 | */ |
| 64 | if (!*end) |
| 65 | title = default_title; |
| 66 | else if (*end == ' ') |
| 67 | title = string_list_insert(&titles, end + 1)->string; |
| 68 | else |
| 69 | die("invalid input: '%s'", line.buf); |
| 70 | |
| 71 | progress = start_progress(the_repository, title, total); |
| 72 | } else if (skip_prefix(line.buf, "progress ", (const char **) &end)) { |
| 73 | uint64_t item_count = strtoull(end, &end, 10); |
| 74 | if (*end != '\0') |
| 75 | die("invalid input: '%s'", line.buf); |
| 76 | display_progress(progress, item_count); |
| 77 | } else if (skip_prefix(line.buf, "throughput ", |
| 78 | (const char **) &end)) { |
| 79 | uint64_t byte_count, test_ms; |
| 80 | |
| 81 | byte_count = strtoull(end, &end, 10); |
| 82 | if (*end != ' ') |
| 83 | die("invalid input: '%s'", line.buf); |
| 84 | test_ms = strtoull(end + 1, &end, 10); |
| 85 | if (*end != '\0') |
| 86 | die("invalid input: '%s'", line.buf); |
| 87 | progress_test_ns = test_ms * 1000 * 1000; |
| 88 | display_throughput(progress, byte_count); |
nothing calls this directly
no test coverage detected