diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-06-22 14:15:21 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-22 14:15:21 -0700 |
commit | 52ab95cfea15ae8a60fb4febc99d54034c8800b8 (patch) | |
tree | ba06be7965dcd1ed226dab1cbb3cf70818bb187d | |
parent | Merge branch 'sb/t4005-modernize' (diff) | |
parent | dir: create function count_slashes() (diff) | |
download | tgif-52ab95cfea15ae8a60fb4febc99d54034c8800b8.tar.xz |
Merge branch 'pc/dir-count-slashes'
Three instances of the same helper function have been consolidated
to one.
* pc/dir-count-slashes:
dir: create function count_slashes()
-rw-r--r-- | apply.c | 11 | ||||
-rw-r--r-- | builtin/show-branch.c | 13 | ||||
-rw-r--r-- | dir.c | 9 | ||||
-rw-r--r-- | dir.h | 3 |
4 files changed, 15 insertions, 21 deletions
@@ -762,17 +762,6 @@ static char *find_name_traditional(struct apply_state *state, return find_name_common(state, line, def, p_value, line + len, 0); } -static int count_slashes(const char *cp) -{ - int cnt = 0; - char ch; - - while ((ch = *cp++)) - if (ch == '/') - cnt++; - return cnt; -} - /* * Given the string after "--- " or "+++ ", guess the appropriate * p_value for the given patch. diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 4a6cc6f490..3636a05594 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -5,6 +5,7 @@ #include "color.h" #include "argv-array.h" #include "parse-options.h" +#include "dir.h" static const char* show_branch_usage[] = { N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n" @@ -421,14 +422,6 @@ static int append_tag_ref(const char *refname, const struct object_id *oid, static const char *match_ref_pattern = NULL; static int match_ref_slash = 0; -static int count_slash(const char *s) -{ - int cnt = 0; - while (*s) - if (*s++ == '/') - cnt++; - return cnt; -} static int append_matching_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data) @@ -438,7 +431,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid, * refs/tags/v0.99.9a and friends. */ const char *tail; - int slash = count_slash(refname); + int slash = count_slashes(refname); for (tail = refname; *tail && match_ref_slash < slash; ) if (*tail++ == '/') slash--; @@ -529,7 +522,7 @@ static void append_one_rev(const char *av) int saved_matches = ref_name_cnt; match_ref_pattern = av; - match_ref_slash = count_slash(av); + match_ref_slash = count_slashes(av); for_each_ref(append_matching_ref, NULL); if (saved_matches == ref_name_cnt && ref_name_cnt < MAX_REVS) @@ -52,6 +52,15 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, static int get_dtype(struct dirent *de, struct index_state *istate, 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); @@ -197,6 +197,9 @@ struct dir_struct { unsigned unmanaged_exclude_files; }; +/*Count the number of slashes for string s*/ +extern int count_slashes(const char *s); + /* * The ordering of these constants is significant, with * higher-numbered match types signifying "closer" (i.e. more |