resolve_gitlink_ref(): avoid memory allocation in many cases
If we don't have to strip trailing '/' from the submodule path, then don't allocate and copy the submodule name. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
424dcc7683
commit
48a8475fd3
19
refs.c
19
refs.c
@ -1301,19 +1301,26 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
|||||||
|
|
||||||
int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)
|
int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
int len = strlen(path);
|
size_t len = strlen(path);
|
||||||
struct strbuf submodule = STRBUF_INIT;
|
|
||||||
struct ref_store *refs;
|
struct ref_store *refs;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
while (len && path[len-1] == '/')
|
while (len && path[len - 1] == '/')
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strbuf_add(&submodule, path, len);
|
if (path[len]) {
|
||||||
refs = get_ref_store(submodule.buf);
|
/* We need to strip off one or more trailing slashes */
|
||||||
strbuf_release(&submodule);
|
char *stripped = xmemdupz(path, len);
|
||||||
|
|
||||||
|
refs = get_ref_store(stripped);
|
||||||
|
free(stripped);
|
||||||
|
} else {
|
||||||
|
refs = get_ref_store(path);
|
||||||
|
}
|
||||||
|
|
||||||
if (!refs)
|
if (!refs)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user