diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-06-28 16:18:15 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-06-28 16:18:15 -0700 |
commit | 6c1c4423e2f83037ef762d63be6edbc1f9e6e867 (patch) | |
tree | d02c347b2699147cdc69607c847f0d06028525a9 | |
parent | 54dc78376652d5c3aa481c730bfb1336b0883136 (diff) | |
parent | 42f9852f3c7476b5608ad297443e6d459516f8c0 (diff) | |
download | git-6c1c4423e2f83037ef762d63be6edbc1f9e6e867.tar.gz git-6c1c4423e2f83037ef762d63be6edbc1f9e6e867.tar.xz |
Merge branch 'jc/maint-simpler-common-prefix' into maint
* jc/maint-simpler-common-prefix:
common_prefix: simplify and fix scanning for prefixes
-rw-r--r-- | dir.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -31,22 +31,22 @@ static int common_prefix(const char **pathspec) if (!slash) return 0; + /* + * The first 'prefix' characters of 'path' are common leading + * path components among the pathspecs we have seen so far, + * including the trailing slash. + */ prefix = slash - path + 1; while ((next = *++pathspec) != NULL) { - int len = strlen(next); - if (len >= prefix && !memcmp(path, next, prefix)) + int len, last_matching_slash = -1; + for (len = 0; len < prefix && next[len] == path[len]; len++) + if (next[len] == '/') + last_matching_slash = len; + if (len == prefix) continue; - len = prefix - 1; - for (;;) { - if (!len) - return 0; - if (next[--len] != '/') - continue; - if (memcmp(path, next, len+1)) - continue; - prefix = len + 1; - break; - } + if (last_matching_slash < 0) + return 0; + prefix = last_matching_slash + 1; } return prefix; } |