Git fork

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>

authored by

Jacob Keller and committed by
Junio C Hamano
059268fd 2084f119

+23 -24
-12
builtin/submodule--helper.c
··· 438 438 return ret; 439 439 } 440 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 - 453 441 struct init_cb { 454 442 const char *prefix; 455 443 const char *super_prefix;
+23
dir.h
··· 676 676 return path_match_flags(path, what | PATH_MATCH_NATIVE); 677 677 } 678 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 + } 679 702 #endif
-12
submodule-config.c
··· 235 235 return 0; 236 236 } 237 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 - 250 238 static int submodule_url_is_relative(const char *url) 251 239 { 252 240 return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);