1212 */
1313#include "cache.h"
1414#include "strbuf.h"
15+ #include "string-list.h"
1516
1617static char bad_path [] = "/bad-path/" ;
1718
@@ -582,20 +583,22 @@ int normalize_path_copy(char *dst, const char *src)
582583 */
583584int longest_ancestor_length (const char * path , const char * prefix_list )
584585{
586+ struct string_list prefixes = STRING_LIST_INIT_DUP ;
585587 char buf [PATH_MAX + 1 ];
586- const char * ceil , * colon ;
587- int len , max_len = -1 ;
588+ int i , max_len = -1 ;
588589
589590 if (prefix_list == NULL || !strcmp (path , "/" ))
590591 return -1 ;
591592
592- for (colon = ceil = prefix_list ; * colon ; ceil = colon + 1 ) {
593- for (colon = ceil ; * colon && * colon != PATH_SEP ; colon ++ );
594- len = colon - ceil ;
593+ string_list_split (& prefixes , prefix_list , PATH_SEP , -1 );
594+
595+ for (i = 0 ; i < prefixes .nr ; i ++ ) {
596+ const char * ceil = prefixes .items [i ].string ;
597+ int len = strlen (ceil );
598+
595599 if (len == 0 || len > PATH_MAX || !is_absolute_path (ceil ))
596600 continue ;
597- strlcpy (buf , ceil , len + 1 );
598- if (normalize_path_copy (buf , buf ) < 0 )
601+ if (normalize_path_copy (buf , ceil ) < 0 )
599602 continue ;
600603 len = strlen (buf );
601604 if (len > 0 && buf [len - 1 ] == '/' )
@@ -608,6 +611,7 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
608611 }
609612 }
610613
614+ string_list_clear (& prefixes , 0 );
611615 return max_len ;
612616}
613617
0 commit comments