summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-03 16:35:03 -0400
committerJunio C Hamano <gitster@pobox.com>2016-10-10 13:52:36 -0700
commita5b34d21521c015cd41ced4a3fdde57d79891eb3 (patch)
tree4cd7013288363bdde05efe99985d66c7c8d3a309 /submodule.c
parent4ea82473aa310de7543141f96c2e6b23ef9fcd4c (diff)
downloadgit-a5b34d21521c015cd41ced4a3fdde57d79891eb3.tar.gz
alternates: provide helper for adding to alternates list
The submodule code wants to temporarily add an alternate object store to our in-memory alt_odb list, but does it manually. Let's provide a helper so it can reuse the code in link_alt_odb_entry(). While we're adding our new add_to_alternates_memory(), let's document add_to_alternates_file(), as the two are related. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c23
1 files changed, 1 insertions, 22 deletions
diff --git a/submodule.c b/submodule.c
index 0ef2ff4321..8b3274a9dc 100644
--- a/submodule.c
+++ b/submodule.c
@@ -123,9 +123,7 @@ void stage_updated_gitmodules(void)
static int add_submodule_odb(const char *path)
{
struct strbuf objects_directory = STRBUF_INIT;
- struct alternate_object_database *alt_odb;
int ret = 0;
- size_t alloc;
ret = strbuf_git_path_submodule(&objects_directory, path, "objects/");
if (ret)
@@ -134,26 +132,7 @@ static int add_submodule_odb(const char *path)
ret = -1;
goto done;
}
- /* avoid adding it twice */
- prepare_alt_odb();
- for (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)
- if (alt_odb->name - alt_odb->base == objects_directory.len &&
- !strncmp(alt_odb->base, objects_directory.buf,
- objects_directory.len))
- goto done;
-
- alloc = st_add(objects_directory.len, 42); /* for "12/345..." sha1 */
- alt_odb = xmalloc(st_add(sizeof(*alt_odb), alloc));
- alt_odb->next = alt_odb_list;
- xsnprintf(alt_odb->base, alloc, "%s", objects_directory.buf);
- alt_odb->name = alt_odb->base + objects_directory.len;
- alt_odb->name[2] = '/';
- alt_odb->name[40] = '\0';
- alt_odb->name[41] = '\0';
- alt_odb_list = alt_odb;
-
- /* add possible alternates from the submodule */
- read_info_alternates(objects_directory.buf, 0);
+ add_to_alternates_memory(objects_directory.buf);
done:
strbuf_release(&objects_directory);
return ret;