@@ -624,22 +624,32 @@ static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_
624624/*
625625 * A "string_list_each_func_t" function that canonicalizes an entry
626626 * from GIT_CEILING_DIRECTORIES using real_path_if_valid(), or
627- * discards it if unusable.
627+ * discards it if unusable. The presence of an empty entry in
628+ * GIT_CEILING_DIRECTORIES turns off canonicalization for all
629+ * subsequent entries.
628630 */
629631static int canonicalize_ceiling_entry (struct string_list_item * item ,
630- void * unused )
632+ void * cb_data )
631633{
634+ int * empty_entry_found = cb_data ;
632635 char * ceil = item -> string ;
633- const char * real_path ;
634636
635- if (!* ceil || !is_absolute_path (ceil ))
637+ if (!* ceil ) {
638+ * empty_entry_found = 1 ;
636639 return 0 ;
637- real_path = real_path_if_valid (ceil );
638- if (!real_path )
640+ } else if (!is_absolute_path (ceil )) {
639641 return 0 ;
640- free (item -> string );
641- item -> string = xstrdup (real_path );
642- return 1 ;
642+ } else if (* empty_entry_found ) {
643+ /* Keep entry but do not canonicalize it */
644+ return 1 ;
645+ } else {
646+ const char * real_path = real_path_if_valid (ceil );
647+ if (!real_path )
648+ return 0 ;
649+ free (item -> string );
650+ item -> string = xstrdup (real_path );
651+ return 1 ;
652+ }
643653}
644654
645655/*
@@ -679,9 +689,11 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
679689 return setup_explicit_git_dir (gitdirenv , cwd , len , nongit_ok );
680690
681691 if (env_ceiling_dirs ) {
692+ int empty_entry_found = 0 ;
693+
682694 string_list_split (& ceiling_dirs , env_ceiling_dirs , PATH_SEP , -1 );
683695 filter_string_list (& ceiling_dirs , 0 ,
684- canonicalize_ceiling_entry , NULL );
696+ canonicalize_ceiling_entry , & empty_entry_found );
685697 ceil_offset = longest_ancestor_length (cwd , & ceiling_dirs );
686698 string_list_clear (& ceiling_dirs , 0 );
687699 }
0 commit comments