summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-03-17 10:57:59 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2022-03-24 00:31:42 +0100
commit1f480d5127b746c2345701b86f7e15ecbd3377a3 (patch)
tree7061ed3b122a5b45cfe11e2dc18d20f129da6601 /path.c
parent4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a (diff)
parent4d0b43aa765a0056c88381eea862364c95e358ca (diff)
Sync with 2.34.2
* maint-2.34: Git 2.34.2 Git 2.33.2 Git 2.32.1 Git 2.31.2 GIT-VERSION-GEN: bump to v2.33.1 Git 2.30.3 setup_git_directory(): add an owner check for the top-level directory Add a function to determine whether a path is owned by the current user
Diffstat (limited to 'path.c')
-rw-r--r--path.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/path.c b/path.c
index 2c895471d9..d73146b6cd 100644
--- a/path.c
+++ b/path.c
@@ -1225,11 +1225,15 @@ int longest_ancestor_length(const char *path, struct string_list *prefixes)
const char *ceil = prefixes->items[i].string;
int len = strlen(ceil);
- if (len == 1 && ceil[0] == '/')
- len = 0; /* root matches anything, with length 0 */
- else if (!strncmp(path, ceil, len) && path[len] == '/')
- ; /* match of length len */
- else
+ /*
+ * For root directories (`/`, `C:/`, `//server/share/`)
+ * adjust the length to exclude the trailing slash.
+ */
+ if (len > 0 && ceil[len - 1] == '/')
+ len--;
+
+ if (strncmp(path, ceil, len) ||
+ path[len] != '/' || !path[len + 1])
continue; /* no match */
if (len > max_len)