summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-03 20:35:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-10 20:52:36 (GMT)
commita5b34d21521c015cd41ced4a3fdde57d79891eb3 (patch)
tree4cd7013288363bdde05efe99985d66c7c8d3a309 /sha1_file.c
parent4ea82473aa310de7543141f96c2e6b23ef9fcd4c (diff)
downloadgit-a5b34d21521c015cd41ced4a3fdde57d79891eb3.zip
git-a5b34d21521c015cd41ced4a3fdde57d79891eb3.tar.gz
git-a5b34d21521c015cd41ced4a3fdde57d79891eb3.tar.bz2
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 'sha1_file.c')
-rw-r--r--sha1_file.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 3d8c1e8..7a3b745 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -440,6 +440,17 @@ void add_to_alternates_file(const char *reference)
free(alts);
}
+void add_to_alternates_memory(const char *reference)
+{
+ /*
+ * Make sure alternates are initialized, or else our entry may be
+ * overwritten when they are.
+ */
+ prepare_alt_odb();
+
+ link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0);
+}
+
/*
* Compute the exact path an alternate is at and returns it. In case of
* error NULL is returned and the human readable error is added to `err`