MCPcopy Create free account
hub / github.com/git/git / longest_path_match

Function longest_path_match

symlinks.c:16–42  ·  view source on GitHub ↗

* Returns the length (on a path component basis) of the longest * common prefix match of 'name_a' and 'name_b'. */

Source from the content-addressed store, hash-verified

14 * common prefix match of 'name_a' and 'name_b'.
15 */
16static int longest_path_match(const char *name_a, int len_a,
17 const char *name_b, int len_b,
18 int *previous_slash)
19{
20 int max_len, match_len = 0, match_len_prev = 0, i = 0;
21
22 max_len = len_a < len_b ? len_a : len_b;
23 while (i < max_len && name_a[i] == name_b[i]) {
24 if (name_a[i] == '/') {
25 match_len_prev = match_len;
26 match_len = i;
27 }
28 i++;
29 }
30 /*
31 * Is 'name_b' a substring of 'name_a', the other way around,
32 * or is 'name_a' and 'name_b' the exact same string?
33 */
34 if (i >= max_len && ((len_a > len_b && name_a[len_b] == '/') ||
35 (len_a < len_b && name_b[len_a] == '/') ||
36 (len_a == len_b))) {
37 match_len_prev = match_len;
38 match_len = i;
39 }
40 *previous_slash = match_len_prev;
41 return match_len;
42}
43
44static struct cache_def default_cache = CACHE_DEF_INIT;
45

Callers 2

lstat_cache_matchlenFunction · 0.85
schedule_dir_for_removalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected