Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
resolve_gitlink_ref(): avoid memory allocation in many cases
author
Michael Haggerty
<mhagger@alum.mit.edu>
Sun, 4 Sep 2016 16:08:23 +0000
(18:08 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Fri, 9 Sep 2016 22:28:13 +0000
(15:28 -0700)
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>
refs.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
424dcc7
)
diff --git
a/refs.c
b/refs.c
index 7b86b4eab5dba2cb2c9fb89a719b5a0ec0639500..17f3497a0b5b6d82fd78e7f00b1c1834c67c1611 100644
(file)
--- a/
refs.c
+++ b/
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);
- struct strbuf submodule = STRBUF_INIT;
+ size_t len = strlen(path);
struct ref_store *refs;
int flags;
struct ref_store *refs;
int flags;
- while (len && path[len
-
1] == '/')
+ while (len && path[len
-
1] == '/')
len--;
len--;
+
if (!len)
return -1;
if (!len)
return -1;
- strbuf_add(&submodule, path, len);
- refs = get_ref_store(submodule.buf);
- strbuf_release(&submodule);
+ if (path[len]) {
+ /* We need to strip off one or more trailing slashes */
+ char *stripped = xmemdupz(path, len);
+
+ refs = get_ref_store(stripped);
+ free(stripped);
+ } else {
+ refs = get_ref_store(path);
+ }
+
if (!refs)
return -1;
if (!refs)
return -1;