Skip to content

Commit fda5d95

Browse files
calvin-wan-googlegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9748a68 commit fda5d95

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

builtin/symbolic-ref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "gettext.h"
44
#include "refs.h"
55
#include "parse-options.h"
6+
#include "strbuf.h"
67

78
static const char * const git_symbolic_ref_usage[] = {
89
N_("git symbolic-ref [-m <reason>] <name> <ref>"),

builtin/unpack-objects.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "blob.h"
1313
#include "commit.h"
1414
#include "replace-object.h"
15+
#include "strbuf.h"
1516
#include "tag.h"
1617
#include "tree.h"
1718
#include "tree-walk.h"

git-compat-util.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);
677677
report_fn get_warn_routine(void);
678678
void set_die_is_recursing_routine(int (*routine)(void));
679679

680-
int starts_with(const char *str, const char *prefix);
681-
int istarts_with(const char *str, const char *prefix);
682-
683680
/*
684681
* If the string "str" begins with the string found in "prefix", return 1.
685682
* 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,
708705
return 0;
709706
}
710707

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-
734708
/*
735709
* Like skip_prefix, but promises never to read past "len" bytes of the input
736710
* 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)
775749
return strip_suffix_mem(str, len, suffix);
776750
}
777751

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-
784752
#define SWAP(a, b) do { \
785753
void *_swap_a_ptr = &(a); \
786754
void *_swap_b_ptr = &(b); \

strbuf.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,36 @@ char *xstrvfmt(const char *fmt, va_list ap);
735735
__attribute__((format (printf, 1, 2)))
736736
char *xstrfmt(const char *fmt, ...);
737737

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+
738770
#endif /* STRBUF_H */

versioncmp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "git-compat-util.h"
22
#include "config.h"
3+
#include "strbuf.h"
34
#include "string-list.h"
45
#include "versioncmp.h"
56

0 commit comments

Comments
 (0)