link_alt_odb_entries: make empty input a noop
If an empty string is passed to link_alt_odb_entries(), our loop finds no entries and we link nothing. But we still do some preparatory work to normalize the object directory path, even though we'll never look at the result. This triggers in basically every git process, since we feed the usually-empty ALTERNATE_DB_ENVIRONMENT to the function. Let's detect early that there's nothing to do and return. While we're at it, let's treat NULL the same as an empty string as a favor to our callers. That saves prepare_alt_odb() from having to cover this case. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 12, 2017 at 10:27 UTC
f28e36686aae9203c0e4375f6d106ddccd129efc
1 file changed
+3
-1
sha1_file.c
+3
-1
@@ -428,6 +428,9 @@ static void link_alt_odb_entries(const char *alt, int sep,
428
struct strbuf objdirbuf = STRBUF_INIT;
429
struct strbuf entry = STRBUF_INIT;
430
431
+ if (!alt || !*alt)
432
+ return;
433
+
434
if (depth > 5) {
435
error("%s: ignoring alternate object stores, nesting too deep.",
436
relative_base);
@@ -631,7 +634,6 @@ void prepare_alt_odb(void)
634
return;
635
636
alt = getenv(ALTERNATE_DB_ENVIRONMENT);
634
- if (!alt) alt = "";
637
638
alt_odb_tail = &alt_odb_list;
639
link_alt_odb_entries(alt, PATH_SEP, NULL, 0);