Exemple #1
0
static int update_wt_heads(git_repository *repo, const char *path, void *payload)
{
	rename_cb_data *data = (rename_cb_data *) payload;
	git_reference *head = NULL;
	char *gitdir = NULL;
	int error;

	if ((error = git_reference__read_head(&head, repo, path)) < 0) {
		giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references");
		goto out;
	}

	if ((gitdir = git_path_dirname(path)) == NULL) {
		error = -1;
		goto out;
	}

	if (git_reference_type(head) != GIT_REF_SYMBOLIC ||
	    git__strcmp(head->target.symbolic, data->old_name) != 0) {
		error = 0;
		goto out;
	}

	/* Update HEAD it was pointing to the reference being renamed */
	if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {
		giterr_set(GITERR_REFERENCE, "failed to update HEAD after renaming reference");
		goto out;
	}

out:
	git_reference_free(head);
	git__free(gitdir);

	return error;
}
Exemple #2
0
static char *get_filename(const char *in)
{
	char *search_dirname, *search_filename, *filename = NULL;
	git_buf out = GIT_BUF_INIT;
	DIR *dir;
	struct dirent *de;

	cl_assert(search_dirname = git_path_dirname(in));
	cl_assert(search_filename = git_path_basename(in));

	cl_assert(dir = opendir(search_dirname));

	while ((de = readdir(dir))) {
		if (strcasecmp(de->d_name, search_filename) == 0) {
			git_buf_join(&out, '/', search_dirname, de->d_name);
			filename = git_buf_detach(&out);
			break;
		}
	}

	closedir(dir);

	git__free(search_dirname);
	git__free(search_filename);
	git_buf_dispose(&out);

	return filename;
}
Exemple #3
0
static char *get_filename(const char *in)
{
#ifdef GIT_WIN32
	HANDLE fh;
	HMODULE kerneldll;
	char *filename;

	typedef DWORD (__stdcall *getfinalpathname)(HANDLE, LPSTR, DWORD, DWORD);
	getfinalpathname getfinalpathfn;

	cl_assert(filename = malloc(MAX_PATH));
	cl_assert(kerneldll = LoadLibrary("kernel32.dll"));
	cl_assert(getfinalpathfn = (getfinalpathname)GetProcAddress(kerneldll, "GetFinalPathNameByHandleA"));

	cl_assert(fh = CreateFileA(in, FILE_READ_ATTRIBUTES | STANDARD_RIGHTS_READ, FILE_SHARE_READ,
		NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));

	cl_win32_pass(getfinalpathfn(fh, filename, MAX_PATH, VOLUME_NAME_DOS));

	CloseHandle(fh);

	git_path_mkposix(filename);

	return filename;
#else
	char *search_dirname, *search_filename, *filename = NULL;
	git_buf out = GIT_BUF_INIT;
	DIR *dir;
	struct dirent *de;

	cl_assert(search_dirname = git_path_dirname(in));
	cl_assert(search_filename = git_path_basename(in));

	cl_assert(dir = opendir(search_dirname));

	while ((de = readdir(dir))) {
		if (strcasecmp(de->d_name, search_filename) == 0) {
			git_buf_join(&out, '/', search_dirname, de->d_name);
			filename = git_buf_detach(&out);
			break;
		}
	}

	closedir(dir);

	git__free(search_dirname);
	git__free(search_filename);
	git_buf_free(&out);

	return filename;
#endif
}
Exemple #4
0
static void
check_dirname(const char *A, const char *B)
{
	git_buf dir = GIT_BUF_INIT;
	char *dir2;

	cl_assert(git_path_dirname_r(&dir, A) >= 0);
	cl_assert_equal_s(B, dir.ptr);
	git_buf_dispose(&dir);

	cl_assert((dir2 = git_path_dirname(A)) != NULL);
	cl_assert_equal_s(B, dir2);
	git__free(dir2);
}