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 <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
Jun 23, 2025 at 16:11 UTC
059268fd056c4063eb913e6ec265bcdf85437b03
3 files changed
+23
-24
builtin/submodule--helper.c
-12
@@ -438,18 +438,6 @@ cleanup:
438
return ret;
439
}
440
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
-
441
struct init_cb {
442
const char *prefix;
443
const char *super_prefix;
dir.h
+23
@@ -676,4 +676,27 @@ static inline int starts_with_dot_dot_slash_native(const char *const path)
676
return path_match_flags(path, what | PATH_MATCH_NATIVE);
677
}
678
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
+}
702
#endif
submodule-config.c
-12
@@ -235,18 +235,6 @@ in_component:
235
return 0;
236
}
237
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
-
238
static int submodule_url_is_relative(const char *url)
239
{
240
return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);