当前位置: 首页>>代码示例>>C++>>正文


C++ p_unlink函数代码示例

本文整理汇总了C++中p_unlink函数的典型用法代码示例。如果您正苦于以下问题:C++ p_unlink函数的具体用法?C++ p_unlink怎么用?C++ p_unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了p_unlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_checkout_tree__safe_proceeds_if_no_index

/* Emulate checking out in a repo created by clone --no-checkout,
 * which would not have written an index. */
void test_checkout_tree__safe_proceeds_if_no_index(void)
{
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
	git_oid oid;
	git_object *obj = NULL;

	assert_on_branch(g_repo, "master");
	cl_must_pass(p_unlink("testrepo/.git/index"));

	/* do second checkout safe because we should be clean after first */
	opts.checkout_strategy = GIT_CHECKOUT_SAFE;

	cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees"));
	cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));

	cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));

	cl_assert(git_path_isfile("testrepo/README"));
	cl_assert(git_path_isfile("testrepo/branch_file.txt"));
	cl_assert(git_path_isfile("testrepo/new.txt"));
	cl_assert(git_path_isfile("testrepo/ab/4.txt"));
	cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
	cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
	cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));

	cl_assert(!git_path_isdir("testrepo/a"));

	assert_on_branch(g_repo, "subtrees");

	git_object_free(obj);
}
开发者ID:Kat7984,项目名称:libgit2,代码行数:34,代码来源:tree.c

示例2: test_reset_hard__cleans_up_merge

void test_reset_hard__cleans_up_merge(void)
{
    git_buf merge_head_path = GIT_BUF_INIT,
            merge_msg_path = GIT_BUF_INIT,
            merge_mode_path = GIT_BUF_INIT,
            orig_head_path = GIT_BUF_INIT;

    cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
    cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");

    cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
    cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");

    cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
    cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");

    cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
    cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");

    cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
    cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));

    cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
    cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
    cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));

    cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
    cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));

    git_buf_free(&merge_head_path);
    git_buf_free(&merge_msg_path);
    git_buf_free(&merge_mode_path);
    git_buf_free(&orig_head_path);
}
开发者ID:jasperla,项目名称:libgit2,代码行数:34,代码来源:hard.c

示例3: test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir

void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
{
	git_reference *ref;
	git_buf log_path = GIT_BUF_INIT;
	git_oid id;

	/* Create a new branch pointing at the HEAD */
	git_oid_fromstr(&id, current_master_tip);
	cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
	git_reference_free(ref);

	git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
	git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");

	cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));

	/* delete the ref manually, leave the reflog */
	cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head"));

	/* new ref creation should fail since new-dir contains reflogs still */
	git_oid_fromstr(&id, current_master_tip);
	cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
	git_reference_free(ref);

	git_buf_dispose(&log_path);
}
开发者ID:csware,项目名称:libgit2,代码行数:26,代码来源:reflog.c

示例4: test_checkout_index__conflicts_honor_coreautocrlf

void test_checkout_index__conflicts_honor_coreautocrlf(void)
{
#ifdef GIT_WIN32
	git_index *index;
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
	git_buf conflicting_buf = GIT_BUF_INIT;

	cl_git_pass(p_unlink("./testrepo/.gitattributes"));
	cl_repo_set_bool(g_repo, "core.autocrlf", true);

	cl_git_pass(git_repository_index(&index, g_repo));

	add_conflict(index, "conflicting.txt");
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_checkout_index(g_repo, NULL, &opts));

	cl_git_pass(git_futils_readbuffer(&conflicting_buf, "testrepo/conflicting.txt"));
	cl_assert(strcmp(conflicting_buf.ptr,
		"<<<<<<< ours\r\n"
		"this file is changed in master and branch\r\n"
		"=======\r\n"
		"this file is changed in branch and master\r\n"
		">>>>>>> theirs\r\n") == 0);
	git_buf_free(&conflicting_buf);

	git_index_free(index);
#endif
}
开发者ID:DeokjuJung,项目名称:libgit2,代码行数:29,代码来源:index.c

示例5: test_object_blob_fromchunks__doesnot_overwrite_an_already_existing_object

void test_object_blob_fromchunks__doesnot_overwrite_an_already_existing_object(void)
{
	git_buf path = GIT_BUF_INIT;
	git_buf content = GIT_BUF_INIT;
	git_oid expected_oid, oid;
	int howmany = 7;

	cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9"));

	cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany));

	/* Let's replace the content of the blob file storage with something else... */
	cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/32/1cbdf08803c744082332332838df6bd160f8f9"));
	cl_git_pass(p_unlink(git_buf_cstr(&path)));
	cl_git_mkfile(git_buf_cstr(&path), "boom");

	/* ...request a creation of the same blob... */
	howmany = 7;
	cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany));

	/* ...and ensure the content of the faked blob file hasn't been altered */
	cl_git_pass(git_futils_readbuffer(&content, git_buf_cstr(&path)));
	cl_assert(!git__strcmp("boom", git_buf_cstr(&content)));

	git_buf_free(&path);
	git_buf_free(&content);
}
开发者ID:1336,项目名称:libgit2,代码行数:27,代码来源:fromchunks.c

示例6: test_stash_save__cannot_stash_when_there_are_no_local_change

void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
{
	git_index *index;
	git_oid stash_tip_oid;

	cl_git_pass(git_repository_index(&index, repo));

	/*
	 * 'what', 'where' and 'who' are being committed.
	 * 'when' remains untracked.
	 */
	cl_git_pass(git_index_add_bypath(index, "what"));
	cl_git_pass(git_index_add_bypath(index, "where"));
	cl_git_pass(git_index_add_bypath(index, "who"));

	cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
	git_index_free(index);

	cl_assert_equal_i(GIT_ENOTFOUND,
		git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));

	p_unlink("stash/when");
	cl_assert_equal_i(GIT_ENOTFOUND,
		git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
}
开发者ID:csware,项目名称:libgit2,代码行数:25,代码来源:save.c

示例7: _rmdir_recurs_foreach

static int _rmdir_recurs_foreach(void *opaque, git_buf *path)
{
	git_directory_removal_type removal_type = *(git_directory_removal_type *)opaque;

	if (git_path_isdir(path->ptr) == true) {
		if (git_path_direach(path, _rmdir_recurs_foreach, opaque) < 0)
			return -1;

		if (p_rmdir(path->ptr) < 0) {
			if (removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS && (errno == ENOTEMPTY || errno == EEXIST))
				return 0;

			giterr_set(GITERR_OS, "Could not remove directory '%s'", path->ptr);
			return -1;
		}

		return 0;
	}

	if (removal_type == GIT_DIRREMOVAL_FILES_AND_DIRS) {
		if (p_unlink(path->ptr) < 0) {
			giterr_set(GITERR_OS, "Could not remove directory.  File '%s' cannot be removed", path->ptr);
			return -1;
		}

		return 0;
	}

	if (removal_type == GIT_DIRREMOVAL_EMPTY_HIERARCHY) {
		giterr_set(GITERR_OS, "Could not remove directory. File '%s' still present", path->ptr);
		return -1;
	}

	return 0;
}
开发者ID:ralpheav,项目名称:PM_GIT,代码行数:35,代码来源:fileops.c

示例8: git_filebuf_cleanup

void git_filebuf_cleanup(git_filebuf *file)
{
	if (file->fd_is_open && file->fd >= 0)
		p_close(file->fd);

	if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock))
		p_unlink(file->path_lock);

	if (file->digest)
		git_hash_free_ctx(file->digest);

	if (file->buffer)
		git__free(file->buffer);

	/* use the presence of z_buf to decide if we need to deflateEnd */
	if (file->z_buf) {
		git__free(file->z_buf);
		deflateEnd(&file->zs);
	}

	if (file->path_original)
		git__free(file->path_original);
	if (file->path_lock)
		git__free(file->path_lock);

	memset(file, 0x0, sizeof(git_filebuf));
	file->fd = -1;
}
开发者ID:spritetong,项目名称:tortoisegit-libgit2-utf8,代码行数:28,代码来源:filebuf.c

示例9: test_core_filebuf__umask

/* make sure git_filebuf_commit takes umask into account */
void test_core_filebuf__umask(void)
{
	git_filebuf file = GIT_FILEBUF_INIT;
	char test[] = "test";
	struct stat statbuf;
	mode_t mask, os_mask;

#ifdef GIT_WIN32
	os_mask = 0600;
#else
	os_mask = 0777;
#endif

	p_umask(mask = p_umask(0));

	cl_assert(file.buffer == NULL);

	cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
	cl_assert(file.buffer != NULL);
	cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
	cl_assert(file.buffer != NULL);

	cl_git_pass(git_filebuf_commit(&file));
	cl_assert(file.buffer == NULL);

	cl_must_pass(p_stat("test", &statbuf));
	cl_assert_equal_i(statbuf.st_mode & os_mask, (0666 & ~mask) & os_mask);

	cl_must_pass(p_unlink(test));
}
开发者ID:structuresound,项目名称:libgit2,代码行数:31,代码来源:filebuf.c

示例10: test_config_new__write_new_config

void test_config_new__write_new_config(void)
{
	git_config *config;
	git_buf buf = GIT_BUF_INIT;

	cl_git_mkfile(TEST_CONFIG, "");
	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));

	cl_git_pass(git_config_set_string(config, "color.ui", "auto"));
	cl_git_pass(git_config_set_string(config, "core.editor", "ed"));

	git_config_free(config);

	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));

	cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
	cl_assert_equal_s("auto", git_buf_cstr(&buf));
	git_buf_clear(&buf);
	cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
	cl_assert_equal_s("ed", git_buf_cstr(&buf));

	git_buf_free(&buf);
	git_config_free(config);

	p_unlink(TEST_CONFIG);
}
开发者ID:1336,项目名称:libgit2,代码行数:26,代码来源:new.c

示例11: test_status_worktree__status_file_with_clean_index_and_empty_workdir

void test_status_worktree__status_file_with_clean_index_and_empty_workdir(void)
{
	git_repository *repo;
	unsigned int status = 0;
	git_index *index;

	cl_git_pass(p_mkdir("wd", 0777));

	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
	cl_git_pass(git_repository_set_workdir(repo, "wd", false));

	cl_git_pass(git_index_open(&index, "my-index"));
	fill_index_wth_head_entries(repo, index);

	git_repository_set_index(repo, index);

	cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));

	cl_assert_equal_i(GIT_STATUS_WT_DELETED, status);

	git_repository_free(repo);
	git_index_free(index);
	cl_git_pass(p_rmdir("wd"));
	cl_git_pass(p_unlink("my-index"));
}
开发者ID:ralpheav,项目名称:PM_GIT,代码行数:25,代码来源:worktree.c

示例12: create_index

static void create_index(struct checkout_index_entry *entries, size_t entries_len)
{
	git_buf path = GIT_BUF_INIT;
	size_t i;

	for (i = 0; i < entries_len; i++) {
		git_buf_joinpath(&path, TEST_REPO_PATH, entries[i].path);

		if (entries[i].stage == 3 && (i == 0 || strcmp(entries[i-1].path, entries[i].path) != 0 || entries[i-1].stage != 2))
			p_unlink(git_buf_cstr(&path));

		git_index_remove_bypath(g_index, entries[i].path);
	}

	for (i = 0; i < entries_len; i++) {
		git_index_entry entry;

		memset(&entry, 0x0, sizeof(git_index_entry));

		entry.mode = entries[i].mode;
		GIT_IDXENTRY_STAGE_SET(&entry, entries[i].stage);
		git_oid_fromstr(&entry.id, entries[i].oid_str);
		entry.path = entries[i].path;

		cl_git_pass(git_index_add(g_index, &entry));
	}

	git_buf_free(&path);
}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:29,代码来源:conflict.c

示例13: test_repo_message__message

void test_repo_message__message(void)
{
	const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
	ssize_t len;

	cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
	cl_git_mkfile(git_buf_cstr(&_path), expected);

	len = git_repository_message(NULL, 0, _repo);
	cl_assert(len > 0);

	_actual = git__malloc(len + 1);
	cl_assert(_actual != NULL);

	/* Test non truncation */
	cl_assert(git_repository_message(_actual, len, _repo) > 0);
	cl_assert_equal_s(expected, _actual);

	/* Test truncation and that trailing NUL is inserted */
	cl_assert(git_repository_message(_actual, 6, _repo) > 0);
	cl_assert_equal_s("Test\n", _actual);

	cl_git_pass(p_unlink(git_buf_cstr(&_path)));
	cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo));
}
开发者ID:0CV0,项目名称:libgit2,代码行数:25,代码来源:message.c

示例14: try_create_file_with_nsec_timestamp

static bool try_create_file_with_nsec_timestamp(const char *path)
{
	struct stat st;
	int try;

	/* retry a few times to avoid nanos *actually* equal 0 race condition */
	for (try = 0; try < 3; try++) {
		cl_git_mkfile(path, "This is hopefully a file with nanoseconds!");

		cl_must_pass(p_stat(path, &st));

		if (st.st_ctime_nsec && st.st_mtime_nsec)
			return true;
	}

	return false;
}

/* try to determine if the underlying filesystem supports a resolution
 * higher than a single second.  (i'm looking at you, hfs+)
 */
static bool should_expect_nsecs(void)
{
	git_buf nsec_path = GIT_BUF_INIT;
	bool expect;

	git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");

	expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);

	p_unlink(nsec_path.ptr);

	git_buf_clear(&nsec_path);

	return expect;
}

static bool has_nsecs(void)
{
	const git_index_entry *entry;
	size_t i;
	bool has_nsecs = false;

	for (i = 0; i < git_index_entrycount(repo_index); i++) {
		entry = git_index_get_byindex(repo_index, i);

		if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) {
			has_nsecs = true;
			break;
		}
	}

	return has_nsecs;
}

void test_index_nsec__has_nanos(void)
{
	cl_assert_equal_b(true, has_nsecs());
}
开发者ID:Dipti126,项目名称:git,代码行数:59,代码来源:nsec.c

示例15: futils__rmdir_recurs_foreach

static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
{
	int error = 0;
	futils__rmdir_data *data = opaque;
	struct stat st;

	if (data->depth > FUTILS_MAX_DEPTH)
		error = futils__error_cannot_rmdir(
			path->ptr, "directory nesting too deep");

	else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
		if (errno == ENOENT)
			error = 0;
		else if (errno == ENOTDIR) {
			/* asked to remove a/b/c/d/e and a/b is a normal file */
			if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
				error = futils__rm_first_parent(path, data->base);
			else
				futils__error_cannot_rmdir(
					path->ptr, "parent is not directory");
		}
		else
			error = git_path_set_error(errno, path->ptr, "rmdir");
	}

	else if (S_ISDIR(st.st_mode)) {
		data->depth++;

		error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);

		data->depth--;

		if (error < 0)
			return error;

		if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
			return error;

		if ((error = p_rmdir(path->ptr)) < 0) {
			if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
				(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
				error = 0;
			else
				error = git_path_set_error(errno, path->ptr, "rmdir");
		}
	}

	else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
		if (p_unlink(path->ptr) < 0)
			error = git_path_set_error(errno, path->ptr, "remove");
	}

	else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
		error = futils__error_cannot_rmdir(path->ptr, "still present");

	return error;
}
开发者ID:KindDragon,项目名称:libgit2,代码行数:57,代码来源:fileops.c


注:本文中的p_unlink函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。