summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-05-10 23:14:17 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2021-05-11 01:30:58 +0100
commit14f6950bcecd2f6c254ab3108b0ac8b267983713 (patch)
treedb9055ccbba9bc4a7e920eac4d575fd6a4699c6d
parentd525e063ba4e478cc4afac4cdf60f7acd989dbf2 (diff)
downloadlibgit2-14f6950bcecd2f6c254ab3108b0ac8b267983713.tar.gz
buf: bom enum is in the buf namespace
Instead of a `git_bom_t` that a `git_buf` function returns, let's keep it `git_buf_bom_t`.
-rw-r--r--src/attr_file.c4
-rw-r--r--src/buffer.c18
-rw-r--r--src/buffer.h18
-rw-r--r--src/config_parse.c4
-rw-r--r--tests/object/blob/filter.c6
5 files changed, 25 insertions, 25 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 6575e5a49..82692727d 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -122,7 +122,7 @@ int git_attr_file__load(
struct stat st;
bool nonexistent = false;
int bom_offset;
- git_bom_t bom;
+ git_buf_bom_t bom;
git_oid id;
git_object_size_t blobsize;
@@ -193,7 +193,7 @@ int git_attr_file__load(
content_str = git_buf_cstr(&content);
bom_offset = git_buf_detect_bom(&bom, &content);
- if (bom == GIT_BOM_UTF8)
+ if (bom == GIT_BUF_BOM_UTF8)
content_str += bom_offset;
/* store the key of the attr_reader; don't bother with cache
diff --git a/src/buffer.c b/src/buffer.c
index ffce73c68..794e1f1ab 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1227,12 +1227,12 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
int git_buf_is_binary(const git_buf *buf)
{
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
- git_bom_t bom;
+ git_buf_bom_t bom;
int printable = 0, nonprintable = 0;
scan += git_buf_detect_bom(&bom, buf);
- if (bom > GIT_BOM_UTF8)
+ if (bom > GIT_BUF_BOM_UTF8)
return 1;
while (scan < end) {
@@ -1257,12 +1257,12 @@ int git_buf_contains_nul(const git_buf *buf)
return (memchr(buf->ptr, '\0', buf->size) != NULL);
}
-int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
+int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
{
const char *ptr;
size_t len;
- *bom = GIT_BOM_NONE;
+ *bom = GIT_BUF_BOM_NONE;
/* need at least 2 bytes to look for any BOM */
if (buf->size < 2)
return 0;
@@ -1273,19 +1273,19 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
switch (*ptr++) {
case 0:
if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
- *bom = GIT_BOM_UTF32_BE;
+ *bom = GIT_BUF_BOM_UTF32_BE;
return 4;
}
break;
case '\xEF':
if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
- *bom = GIT_BOM_UTF8;
+ *bom = GIT_BUF_BOM_UTF8;
return 3;
}
break;
case '\xFE':
if (*ptr == '\xFF') {
- *bom = GIT_BOM_UTF16_BE;
+ *bom = GIT_BUF_BOM_UTF16_BE;
return 2;
}
break;
@@ -1293,10 +1293,10 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
if (*ptr != '\xFE')
break;
if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
- *bom = GIT_BOM_UTF32_LE;
+ *bom = GIT_BUF_BOM_UTF32_LE;
return 4;
} else {
- *bom = GIT_BOM_UTF16_LE;
+ *bom = GIT_BUF_BOM_UTF16_LE;
return 2;
}
break;
diff --git a/src/buffer.h b/src/buffer.h
index e75ecc15c..d043ed626 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -18,16 +18,16 @@
*/
typedef enum {
- GIT_BOM_NONE = 0,
- GIT_BOM_UTF8 = 1,
- GIT_BOM_UTF16_LE = 2,
- GIT_BOM_UTF16_BE = 3,
- GIT_BOM_UTF32_LE = 4,
- GIT_BOM_UTF32_BE = 5
-} git_bom_t;
+ GIT_BUF_BOM_NONE = 0,
+ GIT_BUF_BOM_UTF8 = 1,
+ GIT_BUF_BOM_UTF16_LE = 2,
+ GIT_BUF_BOM_UTF16_BE = 3,
+ GIT_BUF_BOM_UTF32_LE = 4,
+ GIT_BUF_BOM_UTF32_BE = 5
+} git_buf_bom_t;
typedef struct {
- git_bom_t bom; /* BOM found at head of text */
+ git_buf_bom_t bom; /* BOM found at head of text */
unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
unsigned int printable, nonprintable; /* These are just approximations! */
} git_buf_text_stats;
@@ -293,7 +293,7 @@ extern int git_buf_common_prefix(git_buf *buf, const git_strarray *strs);
* @param buf Buffer in which to check the first bytes for a BOM
* @return Number of bytes of BOM data (or 0 if no BOM found)
*/
-extern int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf);
+extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
/**
* Gather stats for a piece of text
diff --git a/src/config_parse.c b/src/config_parse.c
index ea32c36ba..a2d779bfa 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -228,10 +228,10 @@ fail_parse:
static int skip_bom(git_parse_ctx *parser)
{
git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
- git_bom_t bom;
+ git_buf_bom_t bom;
int bom_offset = git_buf_detect_bom(&bom, &buf);
- if (bom == GIT_BOM_UTF8)
+ if (bom == GIT_BUF_BOM_UTF8)
git_parse_advance_chars(parser, bom_offset);
/* TODO: reference implementation is pretty stupid with BoM */
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index a3921f4a0..a8e3d3097 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -43,9 +43,9 @@ static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
{ 0, 0, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 },
- { GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
- { GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
- { GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+ { GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
+ { GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
void test_object_blob_filter__initialize(void)