Commit 68f9d6b2 by Arthur Schreiber

Refs: Fix some issue when core.precomposeunicode = true.

This fixes two issues I found when core.precomposeunicode is enabled:

* When creating a reference with a NFD string, the returned
  git_reference would return this NFD string as the reference’s
  name. But when looking up the reference later, the name would
  then be returned as NFC string.
* Renaming a reference would not honor the core.precomposeunicode and
  apply no normalization to the new reference name.
parent 5f0527ae
...@@ -365,7 +365,7 @@ static int reference__create( ...@@ -365,7 +365,7 @@ static int reference__create(
if (ref_out) if (ref_out)
*ref_out = NULL; *ref_out = NULL;
error = git_reference__normalize_name_lax(normalized, sizeof(normalized), name); error = reference_normalize_for_repo(normalized, sizeof(normalized), repo, name);
if (error < 0) if (error < 0)
return error; return error;
...@@ -388,15 +388,15 @@ static int reference__create( ...@@ -388,15 +388,15 @@ static int reference__create(
return -1; return -1;
} }
ref = git_reference__alloc(name, oid, NULL); ref = git_reference__alloc(normalized, oid, NULL);
} else { } else {
char normalized_target[GIT_REFNAME_MAX]; char normalized_target[GIT_REFNAME_MAX];
if ((error = git_reference__normalize_name_lax( if ((error = reference_normalize_for_repo(
normalized_target, sizeof(normalized_target), symbolic)) < 0) normalized_target, sizeof(normalized_target), repo, symbolic)) < 0)
return error; return error;
ref = git_reference__alloc_symbolic(name, normalized_target); ref = git_reference__alloc_symbolic(normalized, normalized_target);
} }
GITERR_CHECK_ALLOC(ref); GITERR_CHECK_ALLOC(ref);
...@@ -569,18 +569,14 @@ int git_reference_symbolic_set_target( ...@@ -569,18 +569,14 @@ int git_reference_symbolic_set_target(
static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force, static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
const git_signature *signature, const char *message) const git_signature *signature, const char *message)
{ {
unsigned int normalization_flags;
char normalized[GIT_REFNAME_MAX]; char normalized[GIT_REFNAME_MAX];
bool should_head_be_updated = false; bool should_head_be_updated = false;
int error = 0; int error = 0;
assert(ref && new_name && signature); assert(ref && new_name && signature);
normalization_flags = ref->type == GIT_REF_SYMBOLIC ? if ((error = reference_normalize_for_repo(
GIT_REF_FORMAT_ALLOW_ONELEVEL : GIT_REF_FORMAT_NORMAL; normalized, sizeof(normalized), git_reference_owner(ref), new_name)) < 0)
if ((error = git_reference_normalize_name(
normalized, sizeof(normalized), new_name, normalization_flags)) < 0)
return error; return error;
...@@ -590,12 +586,12 @@ static int reference__rename(git_reference **out, git_reference *ref, const char ...@@ -590,12 +586,12 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
should_head_be_updated = (error > 0); should_head_be_updated = (error > 0);
if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force, signature, message)) < 0) if ((error = git_refdb_rename(out, ref->db, ref->name, normalized, force, signature, message)) < 0)
return error; return error;
/* Update HEAD it was pointing to the reference being renamed */ /* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated && if (should_head_be_updated &&
(error = git_repository_set_head(ref->db->repo, new_name, signature, message)) < 0) { (error = git_repository_set_head(ref->db->repo, normalized, signature, message)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference"); giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
return error; return error;
} }
...@@ -1018,17 +1014,6 @@ cleanup: ...@@ -1018,17 +1014,6 @@ cleanup:
return error; return error;
} }
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);
}
#define GIT_REF_TYPEMASK (GIT_REF_OID | GIT_REF_SYMBOLIC) #define GIT_REF_TYPEMASK (GIT_REF_OID | GIT_REF_SYMBOLIC)
int git_reference_cmp( int git_reference_cmp(
......
...@@ -66,7 +66,6 @@ struct git_reference { ...@@ -66,7 +66,6 @@ struct git_reference {
git_reference *git_reference__set_name(git_reference *ref, const char *name); git_reference *git_reference__set_name(git_reference *ref, const char *name);
int git_reference__normalize_name_lax(char *buffer_out, size_t out_size, const char *name);
int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags); int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message); int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message);
int git_reference__is_valid_name(const char *refname, unsigned int flags); int git_reference__is_valid_name(const char *refname, unsigned int flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment