Skip to content

Commit f28e366

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0f7beb commit f28e366

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sha1_file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ static void link_alt_odb_entries(const char *alt, int sep,
428428
struct strbuf objdirbuf = STRBUF_INIT;
429429
struct strbuf entry = STRBUF_INIT;
430430

431+
if (!alt || !*alt)
432+
return;
433+
431434
if (depth > 5) {
432435
error("%s: ignoring alternate object stores, nesting too deep.",
433436
relative_base);
@@ -631,7 +634,6 @@ void prepare_alt_odb(void)
631634
return;
632635

633636
alt = getenv(ALTERNATE_DB_ENVIRONMENT);
634-
if (!alt) alt = "";
635637

636638
alt_odb_tail = &alt_odb_list;
637639
link_alt_odb_entries(alt, PATH_SEP, NULL, 0);

0 commit comments

Comments
 (0)