int resolve_gitlink_ref(const char *submodule, const char *refname,
unsigned char *sha1)
{
- size_t len = strlen(submodule);
struct ref_store *refs;
int flags;
- while (len && is_dir_sep(submodule[len - 1]))
- len--;
-
- if (!len)
- return -1;
-
- if (submodule[len]) {
- /* We need to strip off one or more trailing slashes */
- char *stripped = xmemdupz(submodule, len);
-
- refs = get_submodule_ref_store(stripped);
- free(stripped);
- } else {
- refs = get_submodule_ref_store(submodule);
- }
+ refs = get_submodule_ref_store(submodule);
if (!refs)
return -1;
{
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
+ char *to_free = NULL;
+ size_t len;
+
+ if (submodule) {
+ len = strlen(submodule);
+ while (len && is_dir_sep(submodule[len - 1]))
+ len--;
+ if (!len)
+ return NULL;
+ }
if (!submodule || !*submodule) {
/*
return get_main_ref_store();
}
+ if (submodule[len])
+ /* We need to strip off one or more trailing slashes */
+ submodule = to_free = xmemdupz(submodule, len);
+
refs = lookup_ref_store_map(&submodule_ref_stores, submodule);
if (refs)
goto done;
done:
strbuf_release(&submodule_sb);
+ free(to_free);
+
return refs;
}