git-compat-util: move strbuf.c funcs to its header
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers from git-compat-util.h. Signed-off-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Calvin Wan committed
Jul 5, 2023 at 17:09 UTC
fda5d9595d5172fcbba34742e92d6c7ed4cbe5ef
5 files changed
+35
-32
builtin/symbolic-ref.c
+1
@@ -3,6 +3,7 @@
3
#include "gettext.h"
4
#include "refs.h"
5
#include "parse-options.h"
6
+#include "strbuf.h"
7
8
static const char * const git_symbolic_ref_usage[] = {
9
N_("git symbolic-ref [-m <reason>] <name> <ref>"),
builtin/unpack-objects.c
+1
@@ -12,6 +12,7 @@
12
#include "blob.h"
13
#include "commit.h"
14
#include "replace-object.h"
15
+#include "strbuf.h"
16
#include "tag.h"
17
#include "tree.h"
18
#include "tree-walk.h"
git-compat-util.h
-32
@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);
677
report_fn get_warn_routine(void);
678
void set_die_is_recursing_routine(int (*routine)(void));
679
680
-int starts_with(const char *str, const char *prefix);
681
-int istarts_with(const char *str, const char *prefix);
682
-
680
/*
681
* If the string "str" begins with the string found in "prefix", return 1.
682
* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -708,29 +705,6 @@ static inline int skip_prefix(const char *str, const char *prefix,
705
return 0;
706
}
707
711
-/*
712
- * If the string "str" is the same as the string in "prefix", then the "arg"
713
- * parameter is set to the "def" parameter and 1 is returned.
714
- * If the string "str" begins with the string found in "prefix" and then a
715
- * "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1"
716
- * (i.e., to the point in the string right after the prefix and the "=" sign),
717
- * and 1 is returned.
718
- *
719
- * Otherwise, return 0 and leave "arg" untouched.
720
- *
721
- * When we accept both a "--key" and a "--key=<val>" option, this function
722
- * can be used instead of !strcmp(arg, "--key") and then
723
- * skip_prefix(arg, "--key=", &arg) to parse such an option.
724
- */
725
-int skip_to_optional_arg_default(const char *str, const char *prefix,
726
- const char **arg, const char *def);
727
-
728
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
729
- const char **arg)
730
-{
731
- return skip_to_optional_arg_default(str, prefix, arg, "");
732
-}
733
-
708
/*
709
* Like skip_prefix, but promises never to read past "len" bytes of the input
710
* buffer, and returns the remaining number of bytes in "out" via "outlen".
@@ -775,12 +749,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)
749
return strip_suffix_mem(str, len, suffix);
750
}
751
778
-static inline int ends_with(const char *str, const char *suffix)
779
-{
780
- size_t len;
781
- return strip_suffix(str, suffix, &len);
782
-}
783
-
752
#define SWAP(a, b) do { \
753
void *_swap_a_ptr = &(a); \
754
void *_swap_b_ptr = &(b); \
strbuf.h
+32
@@ -735,4 +735,36 @@ char *xstrvfmt(const char *fmt, va_list ap);
735
__attribute__((format (printf, 1, 2)))
736
char *xstrfmt(const char *fmt, ...);
737
738
+int starts_with(const char *str, const char *prefix);
739
+int istarts_with(const char *str, const char *prefix);
740
+
741
+/*
742
+ * If the string "str" is the same as the string in "prefix", then the "arg"
743
+ * parameter is set to the "def" parameter and 1 is returned.
744
+ * If the string "str" begins with the string found in "prefix" and then a
745
+ * "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1"
746
+ * (i.e., to the point in the string right after the prefix and the "=" sign),
747
+ * and 1 is returned.
748
+ *
749
+ * Otherwise, return 0 and leave "arg" untouched.
750
+ *
751
+ * When we accept both a "--key" and a "--key=<val>" option, this function
752
+ * can be used instead of !strcmp(arg, "--key") and then
753
+ * skip_prefix(arg, "--key=", &arg) to parse such an option.
754
+ */
755
+int skip_to_optional_arg_default(const char *str, const char *prefix,
756
+ const char **arg, const char *def);
757
+
758
+static inline int skip_to_optional_arg(const char *str, const char *prefix,
759
+ const char **arg)
760
+{
761
+ return skip_to_optional_arg_default(str, prefix, arg, "");
762
+}
763
+
764
+static inline int ends_with(const char *str, const char *suffix)
765
+{
766
+ size_t len;
767
+ return strip_suffix(str, suffix, &len);
768
+}
769
+
770
#endif /* STRBUF_H */
versioncmp.c
+1
@@ -1,5 +1,6 @@
1
#include "git-compat-util.h"
2
#include "config.h"
3
+#include "strbuf.h"
4
#include "string-list.h"
5
#include "versioncmp.h"
6