Previously we stripped off any slashes that were present.  Instead,
add a slash if it is missing.  This removes the need for an extra
check that path has a slash following the prefix and makes the
handling of the root directory more natural, making the way clear to
use string_list_longest_prefix().

Signed-off-by: Michael Haggerty <mhag...@alum.mit.edu>
---
 path.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/path.c b/path.c
index b255a74..a56c64a 100644
--- a/path.c
+++ b/path.c
@@ -570,7 +570,7 @@ int normalize_path_copy(char *dst, const char *src)
 
 static int normalize_path_callback(struct string_list_item *item, void 
*cb_data)
 {
-       char buf[PATH_MAX+1];
+       char buf[PATH_MAX+2];
        const char *ceil = item->string;
        int len = strlen(ceil);
 
@@ -579,8 +579,10 @@ static int normalize_path_callback(struct string_list_item 
*item, void *cb_data)
        if (normalize_path_copy(buf, ceil) < 0)
                return 0;
        len = strlen(buf);
-       if (len > 0 && buf[len-1] == '/')
-               buf[--len] = '\0';
+       if (len == 0 || buf[len-1] != '/') {
+               buf[len++] = '/';
+               buf[len++] = '\0';
+       }
        free(item->string);
        item->string = xstrdup(buf);
        return 1;
@@ -615,9 +617,8 @@ int longest_ancestor_length(const char *path, const char 
*prefix_list)
                int len = strlen(ceil);
 
                if (!strncmp(path, ceil, len) &&
-                   path[len] == '/' &&
-                   len > max_len) {
-                       max_len = len;
+                   len - 1 > max_len) {
+                       max_len = len - 1;
                }
        }
 
-- 
1.7.11.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to