Skip to content

Commit

Permalink
Merge branch 'mh/simplify-cache-tree-find'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Mar 18, 2014
2 parents 6bd3424 + 3491047 commit da2e057
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,22 +550,19 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
const char *slash;
struct cache_tree_sub *sub;

slash = strchr(path, '/');
if (!slash)
slash = path + strlen(path);
/* between path and slash is the name of the
* subtree to look for.
slash = strchrnul(path, '/');
/*
* Between path and slash is the name of the subtree
* to look for.
*/
sub = find_subtree(it, path, slash - path, 0);
if (!sub)
return NULL;
it = sub->cache_tree;
if (slash)
while (*slash && *slash == '/')
slash++;
if (!slash || !*slash)
return it; /* prefix ended with slashes */

path = slash;
while (*path == '/')
path++;
}
return it;
}
Expand Down

0 comments on commit da2e057

Please sign in to comment.