Skip to content

Commit 059268f

Browse files
jacob-kellergitster
authored andcommitted
dir: move starts_with_dot(_dot)_slash to dir.h
Both submodule--helper.c and submodule-config.c have an implementation of starts_with_dot_slash and starts_with_dot_dot_slash. The dir.h header has starts_with_dot(_dot)_slash_native, which sets PATH_MATCH_NATIVE. Move the helpers to dir.h as static inlines. I thought about renaming them to postfix with _platform but that felt too long and ugly. On the other hand it might be slightly confusing with _native. This simplifies a submodule refactor which wants to use the helpers earlier in the submodule--helper.c file. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2084f11 commit 059268f

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

builtin/submodule--helper.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,6 @@ static int module_foreach(int argc, const char **argv, const char *prefix,
438438
return ret;
439439
}
440440

441-
static int starts_with_dot_slash(const char *const path)
442-
{
443-
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH |
444-
PATH_MATCH_XPLATFORM);
445-
}
446-
447-
static int starts_with_dot_dot_slash(const char *const path)
448-
{
449-
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH |
450-
PATH_MATCH_XPLATFORM);
451-
}
452-
453441
struct init_cb {
454442
const char *prefix;
455443
const char *super_prefix;

dir.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,27 @@ static inline int starts_with_dot_dot_slash_native(const char *const path)
676676
return path_match_flags(path, what | PATH_MATCH_NATIVE);
677677
}
678678

679+
/**
680+
* starts_with_dot_slash: convenience wrapper for
681+
* patch_match_flags() with PATH_MATCH_STARTS_WITH_DOT_SLASH and
682+
* PATH_MATCH_XPLATFORM.
683+
*/
684+
static inline int starts_with_dot_slash(const char *const path)
685+
{
686+
const enum path_match_flags what = PATH_MATCH_STARTS_WITH_DOT_SLASH;
687+
688+
return path_match_flags(path, what | PATH_MATCH_XPLATFORM);
689+
}
690+
691+
/**
692+
* starts_with_dot_dot_slash: convenience wrapper for
693+
* patch_match_flags() with PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH and
694+
* PATH_MATCH_XPLATFORM.
695+
*/
696+
static inline int starts_with_dot_dot_slash(const char *const path)
697+
{
698+
const enum path_match_flags what = PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH;
699+
700+
return path_match_flags(path, what | PATH_MATCH_XPLATFORM);
701+
}
679702
#endif

submodule-config.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,6 @@ int check_submodule_name(const char *name)
235235
return 0;
236236
}
237237

238-
static int starts_with_dot_slash(const char *const path)
239-
{
240-
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH |
241-
PATH_MATCH_XPLATFORM);
242-
}
243-
244-
static int starts_with_dot_dot_slash(const char *const path)
245-
{
246-
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH |
247-
PATH_MATCH_XPLATFORM);
248-
}
249-
250238
static int submodule_url_is_relative(const char *url)
251239
{
252240
return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);

0 commit comments

Comments
 (0)