Пример #1
0
void test_refs_normalize__buffer_has_to_be_big_enough_to_hold_the_normalized_version(void)
{
	char buffer_out[21];

	cl_git_pass(git_reference_normalize_name(
		buffer_out, 21, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL));
	cl_git_fail(git_reference_normalize_name(
		buffer_out, 20, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL));
}
Пример #2
0
static void ensure_refname_invalid(unsigned int flags, const char *input_refname)
{
	char buffer_out[GIT_REFNAME_MAX];

	cl_assert_equal_i(
		GIT_EINVALIDSPEC,
		git_reference_normalize_name(buffer_out, sizeof(buffer_out), input_refname, flags));
}
Пример #3
0
// Helpers
static void ensure_refname_normalized(
	unsigned int flags,
	const char *input_refname,
	const char *expected_refname)
{
	char buffer_out[GIT_REFNAME_MAX];

	cl_git_pass(git_reference_normalize_name(buffer_out, sizeof(buffer_out), input_refname, flags));

	cl_assert_equal_i(0, strcmp(buffer_out, expected_refname));
}
Пример #4
0
int git_reference__normalize_name_lax(
	char *buffer_out,
	size_t out_size,
	const char *name)
{
	return git_reference_normalize_name(
		buffer_out,
		out_size,
		name,
		GIT_REF_FORMAT_ALLOW_ONELEVEL);
}
Пример #5
0
static int reference_normalize_for_repo(
	git_refname_t out,
	git_repository *repo,
	const char *name)
{
	int precompose;
	unsigned int flags = GIT_REF_FORMAT_ALLOW_ONELEVEL;

	if (!git_repository__cvar(&precompose, repo, GIT_CVAR_PRECOMPOSE) &&
		precompose)
		flags |= GIT_REF_FORMAT__PRECOMPOSE_UNICODE;

	return git_reference_normalize_name(out, GIT_REFNAME_MAX, name, flags);
}
Пример #6
0
int git_reference_rename(
	git_reference **out,
	git_reference *ref,
	const char *new_name,
	int force)
{
	unsigned int normalization_flags;
	char normalized[GIT_REFNAME_MAX];
	bool should_head_be_updated = false;
	int error = 0;
	int reference_has_log;

	normalization_flags = ref->type == GIT_REF_SYMBOLIC ?
		GIT_REF_FORMAT_ALLOW_ONELEVEL : GIT_REF_FORMAT_NORMAL;

	if ((error = git_reference_normalize_name(
			normalized, sizeof(normalized), new_name, normalization_flags)) < 0)
		return error;

	/* Check if we have to update HEAD. */
	if ((error = git_branch_is_head(ref)) < 0)
		return error;

	should_head_be_updated = (error > 0);

	if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force)) < 0)
		return error;

	/* Update HEAD it was poiting to the reference being renamed. */
	if (should_head_be_updated &&
		(error = git_repository_set_head(ref->db->repo, new_name)) < 0) {
		giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
		return error;
	}

	/* Rename the reflog file, if it exists. */
	reference_has_log = git_reference_has_log(ref);
	if (reference_has_log < 0)
		return reference_has_log;

	if (reference_has_log && (error = git_reflog_rename(git_reference_owner(ref), git_reference_name(ref), new_name)) < 0)
		return error;

	return 0;
}
Пример #7
0
int luagi_reference_normalize_name( lua_State *L )
{
   const char *name = luaL_checkstring( L, 1 );

   int flags = GIT_REF_FORMAT_NORMAL;
   if( lua_type( L, 2 ) == LUA_TTABLE)
   {

      add_flag( flags, L, 2, ALLOW_ONELEVEL, GIT_REF_FORMAT_ALLOW_ONELEVEL );
      add_flag( flags, L, 2, REFSPEC_PATTERN, GIT_REF_FORMAT_REFSPEC_PATTERN );
      add_flag( flags, L, 2, REFSPEC_SHORTHAND, GIT_REF_FORMAT_REFSPEC_SHORTHAND );
   }

   char buffer_out[ bufsize ];

   memset( buffer_out, 0, bufsize );
   if( git_reference_normalize_name( buffer_out, bufsize, name, flags ) != 0 )
   {
      return ltk_push_git_error( L );
   }
   lua_pushstring( L, buffer_out );
   return 1;
}