summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJiang Xin <worldhello.net@gmail.com>2022-04-13 14:51:53 +0800
committerJiang Xin <worldhello.net@gmail.com>2022-04-13 14:51:53 +0800
commit61de00a32115b6090891f20797fdfd1501709ab9 (patch)
treee6a0290cef9e52589a8b78e55dbae3daf559e202 /path.c
parentdfbdf52df590cf8af37b193d9bf9f9a41162f3ae (diff)
parent11cfe552610386954886543f5de87dcc49ad5735 (diff)
Merge branch 'master' of github.com:git/git
* 'master' of github.com:git/git: (25 commits) Git 2.36-rc2 i18n: fix some badly formatted i18n strings Git 2.36-rc1 t9902: split test to run on appropriate systems ls-tree doc: document interaction with submodules Documentation: add --batch-command to cat-file synopsis git-ls-tree.txt: fix the name of "%(objectsize:padded)" submodule-helper: fix usage string doc: replace "--" with {litdd} in credential-cache/fsmonitor contrib/scalar: fix 'all' target in Makefile Documentation/Makefile: fix "make info" regression in dad9cd7d518 configure.ac: fix HAVE_SYNC_FILE_RANGE definition git-compat-util: really support openssl as a source of entropy ls-tree: `-l` should not imply recursive listing Git 2.35.2 Git 2.34.2 Git 2.33.2 Git 2.32.1 Git 2.31.2 Git 2.30.3 ...
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)