Revision ec445074e0ac4d6003acd21c512c43c8fdb8be86 authored by Junio C Hamano on 12 March 2014, 18:04:11 UTC, committed by Junio C Hamano on 13 March 2014, 21:22:20 UTC
The original description talked only about what it does.  Instead,
start it with the purpose of the command, i.e. what it is used for,
and then mention what it does to achieve that goal.

Clarify what <start>, <url> and <end> means in the context of the
overall purpose of the command.

Describe the extended syntax of <end> parameter that is used when
the local branch name is different from the branch name at the
repository the changes are published.

Helped-by: Eric Sunshine
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5aae66b
Raw File
test-wildmatch.c
#ifdef USE_WILDMATCH
#undef USE_WILDMATCH  /* We need real fnmatch implementation here */
#endif
#include "cache.h"
#include "wildmatch.h"

static int perf(int ac, char **av)
{
	struct timeval tv1, tv2;
	struct stat st;
	int fd, i, n, flags1 = 0, flags2 = 0;
	char *buffer, *p;
	uint32_t usec1, usec2;
	const char *lang;
	const char *file = av[0];
	const char *pattern = av[1];

	lang = getenv("LANG");
	if (lang && strcmp(lang, "C"))
		die("Please test it on C locale.");

	if ((fd = open(file, O_RDONLY)) == -1 || fstat(fd, &st))
		die_errno("file open");

	buffer = xmalloc(st.st_size + 2);
	if (read(fd, buffer, st.st_size) != st.st_size)
		die_errno("read");

	buffer[st.st_size] = '\0';
	buffer[st.st_size + 1] = '\0';
	for (i = 0; i < st.st_size; i++)
		if (buffer[i] == '\n')
			buffer[i] = '\0';

	n = atoi(av[2]);
	if (av[3] && !strcmp(av[3], "pathname")) {
		flags1 = WM_PATHNAME;
		flags2 = FNM_PATHNAME;
	}

	gettimeofday(&tv1, NULL);
	for (i = 0; i < n; i++) {
		for (p = buffer; *p; p += strlen(p) + 1)
			wildmatch(pattern, p, flags1, NULL);
	}
	gettimeofday(&tv2, NULL);

	usec1 = (uint32_t)tv2.tv_sec * 1000000 + tv2.tv_usec;
	usec1 -= (uint32_t)tv1.tv_sec * 1000000 + tv1.tv_usec;
	printf("wildmatch %ds %dus\n",
	       (int)(usec1 / 1000000),
	       (int)(usec1 % 1000000));

	gettimeofday(&tv1, NULL);
	for (i = 0; i < n; i++) {
		for (p = buffer; *p; p += strlen(p) + 1)
			fnmatch(pattern, p, flags2);
	}
	gettimeofday(&tv2, NULL);

	usec2 = (uint32_t)tv2.tv_sec * 1000000 + tv2.tv_usec;
	usec2 -= (uint32_t)tv1.tv_sec * 1000000 + tv1.tv_usec;
	if (usec2 > usec1)
		printf("fnmatch   %ds %dus or %.2f%% slower\n",
		       (int)((usec2 - usec1) / 1000000),
		       (int)((usec2 - usec1) % 1000000),
		       (float)(usec2 - usec1) / usec1 * 100);
	else
		printf("fnmatch   %ds %dus or %.2f%% faster\n",
		       (int)((usec1 - usec2) / 1000000),
		       (int)((usec1 - usec2) % 1000000),
		       (float)(usec1 - usec2) / usec1 * 100);
	return 0;
}

int main(int argc, char **argv)
{
	int i;

	if (!strcmp(argv[1], "perf"))
		return perf(argc - 2, argv + 2);

	for (i = 2; i < argc; i++) {
		if (argv[i][0] == '/')
			die("Forward slash is not allowed at the beginning of the\n"
			    "pattern because Windows does not like it. Use `XXX/' instead.");
		else if (!strncmp(argv[i], "XXX/", 4))
			argv[i] += 3;
	}
	if (!strcmp(argv[1], "wildmatch"))
		return !!wildmatch(argv[3], argv[2], WM_PATHNAME, NULL);
	else if (!strcmp(argv[1], "iwildmatch"))
		return !!wildmatch(argv[3], argv[2], WM_PATHNAME | WM_CASEFOLD, NULL);
	else if (!strcmp(argv[1], "pathmatch"))
		return !!wildmatch(argv[3], argv[2], 0, NULL);
	else if (!strcmp(argv[1], "fnmatch"))
		return !!fnmatch(argv[3], argv[2], FNM_PATHNAME);
	else
		return 1;
}
back to top