Skip to content

Commit da2e057

Browse files
committed
Merge branch 'mh/simplify-cache-tree-find'
* mh/simplify-cache-tree-find: cache_tree_find(): use path variable when passing over slashes cache_tree_find(): remove early return cache_tree_find(): remove redundant check cache_tree_find(): fix comment formatting cache_tree_find(): find the end of path component using strchrnul() cache_tree_find(): remove redundant checks
2 parents 6bd3424 + 3491047 commit da2e057

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

cache-tree.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -550,22 +550,19 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
550550
const char *slash;
551551
struct cache_tree_sub *sub;
552552

553-
slash = strchr(path, '/');
554-
if (!slash)
555-
slash = path + strlen(path);
556-
/* between path and slash is the name of the
557-
* subtree to look for.
553+
slash = strchrnul(path, '/');
554+
/*
555+
* Between path and slash is the name of the subtree
556+
* to look for.
558557
*/
559558
sub = find_subtree(it, path, slash - path, 0);
560559
if (!sub)
561560
return NULL;
562561
it = sub->cache_tree;
563-
if (slash)
564-
while (*slash && *slash == '/')
565-
slash++;
566-
if (!slash || !*slash)
567-
return it; /* prefix ended with slashes */
562+
568563
path = slash;
564+
while (*path == '/')
565+
path++;
569566
}
570567
return it;
571568
}

0 commit comments

Comments
 (0)