12
12
*/
13
13
#include "cache.h"
14
14
#include "strbuf.h"
15
+ #include "string-list.h"
15
16
16
17
static char bad_path [] = "/bad-path/" ;
17
18
@@ -582,20 +583,22 @@ int normalize_path_copy(char *dst, const char *src)
582
583
*/
583
584
int longest_ancestor_length (const char * path , const char * prefix_list )
584
585
{
586
+ struct string_list prefixes = STRING_LIST_INIT_DUP ;
585
587
char buf [PATH_MAX + 1 ];
586
- const char * ceil , * colon ;
587
- int len , max_len = -1 ;
588
+ int i , max_len = -1 ;
588
589
589
590
if (prefix_list == NULL || !strcmp (path , "/" ))
590
591
return -1 ;
591
592
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
+
595
599
if (len == 0 || len > PATH_MAX || !is_absolute_path (ceil ))
596
600
continue ;
597
- strlcpy (buf , ceil , len + 1 );
598
- if (normalize_path_copy (buf , buf ) < 0 )
601
+ if (normalize_path_copy (buf , ceil ) < 0 )
599
602
continue ;
600
603
len = strlen (buf );
601
604
if (len > 0 && buf [len - 1 ] == '/' )
@@ -608,6 +611,7 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
608
611
}
609
612
}
610
613
614
+ string_list_clear (& prefixes , 0 );
611
615
return max_len ;
612
616
}
613
617
0 commit comments