mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-03 07:05:46 +00:00
Add internal ref set_name fn instead of realloc
The refdb_fs implementation calls realloc directly on a reference object when it wants to rename it. It is not a public object, so this doesn't mess with the immutability of references, but it does assume certain constraints on the reference representation. This commit wraps that assumption in an isolated API to isolate it.
This commit is contained in:
parent
a4977169e1
commit
24c71f14b4
11
src/refs.c
11
src/refs.c
@ -88,6 +88,17 @@ git_reference *git_reference__alloc(
|
||||
return ref;
|
||||
}
|
||||
|
||||
git_reference *git_reference__set_name(
|
||||
git_reference *ref, const char *name)
|
||||
{
|
||||
size_t namelen = strlen(name);
|
||||
git_reference *rewrite =
|
||||
git__realloc(ref, sizeof(git_reference) + namelen + 1);
|
||||
if (rewrite != NULL)
|
||||
memcpy(rewrite->name, name, namelen + 1);
|
||||
return rewrite;
|
||||
}
|
||||
|
||||
void git_reference_free(git_reference *reference)
|
||||
{
|
||||
if (reference == NULL)
|
||||
|
@ -61,6 +61,8 @@ struct git_reference {
|
||||
char name[0];
|
||||
};
|
||||
|
||||
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__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid);
|
||||
|
Loading…
Reference in New Issue
Block a user