示例#1
0
void test_describe_describe__describe_a_repo_with_no_refs(void)
{
	git_repository *repo;
	git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
	git_buf buf = GIT_BUF_INIT;
	git_object *object;
	git_describe_result *result = NULL;

	repo = cl_git_sandbox_init("testrepo.git");
	cl_git_pass(git_revparse_single(&object, repo, "HEAD"));

	cl_git_pass(git_reference_foreach(repo, delete_cb, NULL));

	/* Impossible to describe without falling back to OIDs */
	cl_git_fail(git_describe_commit(&result, object, &opts));

	/* Try again with OID fallbacks */
	opts.show_commit_oid_as_fallback = 1;
	cl_git_pass(git_describe_commit(&result, object, &opts));

	git_describe_result_free(result);
	git_object_free(object);
	git_buf_dispose(&buf);
	cl_git_sandbox_cleanup();
}
示例#2
0
文件: reference.c 项目: jwes/luagi
int luagi_reference_foreach( lua_State *L )
{
   git_repository **repo = checkrepo( L, 1 );
   luaL_checktype( L, 2, LUA_TFUNCTION );

   luagi_foreach_t *p = malloc( sizeof( luagi_foreach_t ) );
   p->L = L;
   p->callback_pos = 2;

   int just_names = lua_toboolean( L, 3 );
   
   if( just_names )
   {
      if( git_reference_foreach_name( *repo, name_callback, p ))
      {
         ltk_error_abort( L );
      }
   }
   else
   {
      if( git_reference_foreach( *repo, ref_callback, p ))
      {
         ltk_error_abort( L );
      }
   }
   free( p );
   return 0;   
}
示例#3
0
int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data)
{
	tag_cb_data data;

	assert(repo && cb);

	data.cb = cb;
	data.cb_data = cb_data;
	data.repo = repo;

	return git_reference_foreach(repo, GIT_REF_OID, &tags_cb, &data);
}
示例#4
0
int main(int argc, char **argv)
{
        git_repository *repo;

        if (argc != 1 || argv[1] /* silence -Wunused-parameter */)
                fatal("Sorry, no for-each-ref options supported yet", NULL);

        check_lg2(git_repository_open(&repo, "."),
                  "Could not open repository", NULL);
        check_lg2(git_reference_foreach(repo, show_ref, repo),
                  "Could not iterate over references", NULL);
        return 0;
}
示例#5
0
int
main(int argc, char **argv)
{
	git_buf pathbuf;
	const char *path;
	const git_error *err;
	git_repository *repo;
	struct tag_filter_struct filter;
	
	path = NULL;
	if(argc == 2)
	{
		path = argv[1];
	}
	else if(argc != 1)
	{
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}
	if(!path)
	{
		path = getenv("GIT_DIR");
	}
	memset(&pathbuf, 0, sizeof(pathbuf));
	if(!path)
	{
		if(git_repository_discover(&pathbuf, ".", 0, "/"))
		{
			err = giterr_last();
			fprintf(stderr, "%s: %s\n", path, err->message);
			exit(EXIT_FAILURE);
		}
		path = pathbuf.ptr;
	}
	if(git_repository_open(&repo, path))
	{
		err = giterr_last();
		fprintf(stderr, "%s: %s\n", path, err->message);
		exit(EXIT_FAILURE);
	}
	/* Only available in HEAD:
	git_tag_foreach(repo, tag_callback, NULL);
	 */
	filter.data = NULL;
	filter.cb = tag_callback;
	filter.repo = repo;
	git_reference_foreach(repo, ref_callback, &filter);
	git_repository_free(repo);
	git_buf_free(&pathbuf);
	return 0;
}
int git_branch_foreach(
	git_repository *repo,
	unsigned int list_flags,
	git_branch_foreach_cb branch_cb,
	void *payload)
{
	branch_foreach_filter filter;

	filter.branch_cb = branch_cb;
	filter.branch_type = list_flags;
	filter.callback_payload = payload;

	return git_reference_foreach(repo, GIT_REF_LISTALL, &branch_foreach_cb, (void *)&filter);
}
示例#7
0
文件: clone.c 项目: ralpheav/PM_GIT
static int update_head_to_remote(git_repository *repo, git_remote *remote)
{
	int retcode = -1;
	git_remote_head *remote_head;
	struct head_info head_info;
	git_buf remote_master_name = GIT_BUF_INIT;

	/* Did we just clone an empty repository? */
	if (remote->refs.length == 0) {
		return setup_tracking_config(
			repo,
			"master",
			GIT_REMOTE_ORIGIN,
			GIT_REFS_HEADS_MASTER_FILE);
	}

	/* Get the remote's HEAD. This is always the first ref in remote->refs. */
	remote_head = NULL;
	
	if (!remote->transport->ls(remote->transport, get_head_callback, &remote_head))
		return -1;

	assert(remote_head);

	git_oid_cpy(&head_info.remote_head_oid, &remote_head->oid);
	git_buf_init(&head_info.branchname, 16);
	head_info.repo = repo;
	head_info.refspec = git_remote_fetchspec(remote);
	
	/* Determine the remote tracking reference name from the local master */
	if (git_refspec_transform_r(
		&remote_master_name,
		head_info.refspec,
		GIT_REFS_HEADS_MASTER_FILE) < 0)
			return -1;

	/* Check to see if the remote HEAD points to the remote master */
	if (reference_matches_remote_head(git_buf_cstr(&remote_master_name), &head_info) < 0)
		goto cleanup;

	if (git_buf_len(&head_info.branchname) > 0) {
		retcode = update_head_to_new_branch(
			repo,
			&head_info.remote_head_oid,
			git_buf_cstr(&head_info.branchname));

		goto cleanup;
	}

	/* Not master. Check all the other refs. */
	if (git_reference_foreach(
		repo,
		GIT_REF_LISTALL,
		reference_matches_remote_head,
		&head_info) < 0)
			goto cleanup;

	if (git_buf_len(&head_info.branchname) > 0) {
		retcode = update_head_to_new_branch(
			repo,
			&head_info.remote_head_oid,
			git_buf_cstr(&head_info.branchname));

		goto cleanup;
	} else {
		/* TODO: What should we do if nothing has been found?
		 */
	}

cleanup:
	git_buf_free(&remote_master_name);
	git_buf_free(&head_info.branchname);
	return retcode;
}
示例#8
0
文件: learning.c 项目: liangx8/cpp
void learning_libgit(git_repository *repo){
  git_reference_foreach(repo,ref_callback,NULL);

}