dir: create function count_slashes()
Similar functions exist in apply.c and builtin/show-branch.c for counting the number of slashes in a string. Also in the later patches, we introduce a third caller for the same. Hence, we unify it now by cleaning the existing functions and declaring a common function count_slashes in dir.h and implementing it in dir.c to remove this code duplication. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Prathamesh Chavan <pc44800@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b06d364310
commit
e0556a928f
9
dir.c
9
dir.c
@ -49,6 +49,15 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
|
||||
int check_only, const struct pathspec *pathspec);
|
||||
static int get_dtype(struct dirent *de, const char *path, int len);
|
||||
|
||||
int count_slashes(const char *s)
|
||||
{
|
||||
int cnt = 0;
|
||||
while (*s)
|
||||
if (*s++ == '/')
|
||||
cnt++;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
int fspathcmp(const char *a, const char *b)
|
||||
{
|
||||
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
|
||||
|
Reference in New Issue
Block a user