git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 1435c28e95005f78e5819eb843e4d9ced73f5131 3161 bytes (raw)
name: t/helper/test-progress.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
 
/*
 * A test helper to exercise the progress display.
 *
 * Reads instructions from standard input, one instruction per line:
 *
 *   "start <total>[ <title>]" - Call start_progress(title, total),
 *                               Uses the default title of "Working hard"
 *                               if the " <title>" is omitted.
 *   "progress <items>" - Call display_progress() with the given item count
 *                        as parameter.
 *   "throughput <bytes> <millis> - Call display_throughput() with the given
 *                                  byte count as parameter.  The 'millis'
 *                                  specify the time elapsed since the
 *                                  start_progress() call.
 *   "update" - Set the 'progress_update' flag.
 *   "stop" - Call stop_progress().
 *
 * See 't0500-progress-display.sh' for examples.
 */
#define GIT_TEST_PROGRESS_ONLY
#include "test-tool.h"
#include "gettext.h"
#include "parse-options.h"
#include "progress.h"
#include "strbuf.h"
#include "string-list.h"

/*
 * We can't use "end + 1" as an argument to start_progress() below, it
 * doesn't xstrdup() its "title" argument. We need to hold onto a
 * valid "char *" for it until the end.
 */
static char *dup_title(struct string_list *titles, const char *title)
{
	return string_list_insert(titles, title)->string;
}

int cmd__progress(int argc, const char **argv)
{
	const char *const default_title = "Working hard";
	struct string_list titles = STRING_LIST_INIT_DUP;
	struct strbuf line = STRBUF_INIT;
	struct progress *progress = NULL;

	const char *usage[] = {
		"test-tool progress <stdin",
		NULL
	};
	struct option options[] = {
		OPT_END(),
	};

	argc = parse_options(argc, argv, NULL, options, usage, 0);
	if (argc)
		usage_with_options(usage, options);

	progress_testing = 1;
	while (strbuf_getline(&line, stdin) != EOF) {
		char *end;

		if (skip_prefix(line.buf, "start ", (const char **) &end)) {
			uint64_t total = strtoull(end, &end, 10);
			if (*end == '\0')
				progress = start_progress(default_title, total);
			else if (*end == ' ')
				progress = start_progress(dup_title(&titles,
								    end + 1),
							  total);
			else
				die("invalid input: '%s'\n", line.buf);
		} else if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
			uint64_t item_count = strtoull(end, &end, 10);
			if (*end != '\0')
				die("invalid input: '%s'\n", line.buf);
			display_progress(progress, item_count);
		} else if (skip_prefix(line.buf, "throughput ",
				       (const char **) &end)) {
			uint64_t byte_count, test_ms;

			byte_count = strtoull(end, &end, 10);
			if (*end != ' ')
				die("invalid input: '%s'\n", line.buf);
			test_ms = strtoull(end + 1, &end, 10);
			if (*end != '\0')
				die("invalid input: '%s'\n", line.buf);
			progress_test_ns = test_ms * 1000 * 1000;
			display_throughput(progress, byte_count);
		} else if (!strcmp(line.buf, "update")) {
			progress_test_force_update();
		} else if (!strcmp(line.buf, "stop")) {
			stop_progress(&progress);
		} else {
			die("invalid input: '%s'\n", line.buf);
		}
	}
	strbuf_release(&line);
	string_list_clear(&titles, 0);

	return 0;
}

debug log:

solving 1435c28e950 ...
found 1435c28e950 in https://public-inbox.org/git/patch-v7-3.7-d685c248686-20211217T041945Z-avarab@gmail.com/ ||
	https://public-inbox.org/git/patch-v4-3.8-1c5f9bdfe6d-20211025T111915Z-avarab@gmail.com/ ||
	https://public-inbox.org/git/patch-v5-3.8-767aa010026-20211101T190630Z-avarab@gmail.com/ ||
	https://public-inbox.org/git/patch-v6-3.8-400b491449e-20211102T122507Z-avarab@gmail.com/
found 50fd3be3dad in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 50fd3be3dad7f5d6028e4a2ebc7b4a40e98d10fd	t/helper/test-progress.c

applying [1/1] https://public-inbox.org/git/patch-v7-3.7-d685c248686-20211217T041945Z-avarab@gmail.com/
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 50fd3be3dad..1435c28e950 100644

Checking patch t/helper/test-progress.c...
Applied patch t/helper/test-progress.c cleanly.

skipping https://public-inbox.org/git/patch-v4-3.8-1c5f9bdfe6d-20211025T111915Z-avarab@gmail.com/ for 1435c28e950
skipping https://public-inbox.org/git/patch-v5-3.8-767aa010026-20211101T190630Z-avarab@gmail.com/ for 1435c28e950
skipping https://public-inbox.org/git/patch-v6-3.8-400b491449e-20211102T122507Z-avarab@gmail.com/ for 1435c28e950
index at:
100644 1435c28e95005f78e5819eb843e4d9ced73f5131	t/helper/test-progress.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).