Beispiel #1
0
void test_path_win32__8dot3_name(void)
{
#ifdef GIT_WIN32
	char *shortname;

	if (!cl_sandbox_supports_8dot3())
		clar__skip();

	/* Some guaranteed short names */
	cl_assert_equal_s("PROGRA~1", (shortname = git_win32_path_8dot3_name("C:\\Program Files")));
	git__free(shortname);

	cl_assert_equal_s("WINDOWS", (shortname = git_win32_path_8dot3_name("C:\\WINDOWS")));
	git__free(shortname);

	/* Create some predictible short names */
	cl_must_pass(p_mkdir(".foo", 0777));
	cl_assert_equal_s("FOO~1", (shortname = git_win32_path_8dot3_name(".foo")));
	git__free(shortname);

	cl_git_write2file("bar~1", "foobar\n", 7, O_RDWR|O_CREAT, 0666);
	cl_must_pass(p_mkdir(".bar", 0777));
	cl_assert_equal_s("BAR~2", (shortname = git_win32_path_8dot3_name(".bar")));
	git__free(shortname);
#endif
}
Beispiel #2
0
bool cl_sandbox_supports_8dot3(void)
{
	git_buf longpath = GIT_BUF_INIT;
	char *shortname;
	bool supported;

	cl_git_pass(
		git_buf_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));

	cl_git_write2file(longpath.ptr, "", 0, O_RDWR|O_CREAT, 0666);
	shortname = git_win32_path_8dot3_name(longpath.ptr);

	supported = (shortname != NULL);

	git__free(shortname);
	git_buf_free(&longpath);

	return supported;
}
const char *git_repository__8dot3_name(git_repository *repo)
{
	if (!repo->has_8dot3) {
		repo->has_8dot3 = 1;

#ifdef GIT_WIN32
		if (!repo->is_bare) {
			repo->name_8dot3 = git_win32_path_8dot3_name(repo->path_repository);

			/* We anticipate the 8.3 name is "GIT~1", so use a static for
			 * easy testing in the common case */
			if (repo->name_8dot3 &&
				strcasecmp(repo->name_8dot3, git_repository__8dot3_default) == 0)
				repo->has_8dot3_default = 1;
		}
#endif
	}

	return repo->has_8dot3_default ?
		git_repository__8dot3_default : repo->name_8dot3;
}