Skip to content

Commit 14f6950

Browse files
committed
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`.
1 parent d525e06 commit 14f6950

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

src/attr_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int git_attr_file__load(
122122
struct stat st;
123123
bool nonexistent = false;
124124
int bom_offset;
125-
git_bom_t bom;
125+
git_buf_bom_t bom;
126126
git_oid id;
127127
git_object_size_t blobsize;
128128

@@ -193,7 +193,7 @@ int git_attr_file__load(
193193
content_str = git_buf_cstr(&content);
194194
bom_offset = git_buf_detect_bom(&bom, &content);
195195

196-
if (bom == GIT_BOM_UTF8)
196+
if (bom == GIT_BUF_BOM_UTF8)
197197
content_str += bom_offset;
198198

199199
/* store the key of the attr_reader; don't bother with cache

src/buffer.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,12 +1227,12 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
12271227
int git_buf_is_binary(const git_buf *buf)
12281228
{
12291229
const char *scan = buf->ptr, *end = buf->ptr + buf->size;
1230-
git_bom_t bom;
1230+
git_buf_bom_t bom;
12311231
int printable = 0, nonprintable = 0;
12321232

12331233
scan += git_buf_detect_bom(&bom, buf);
12341234

1235-
if (bom > GIT_BOM_UTF8)
1235+
if (bom > GIT_BUF_BOM_UTF8)
12361236
return 1;
12371237

12381238
while (scan < end) {
@@ -1257,12 +1257,12 @@ int git_buf_contains_nul(const git_buf *buf)
12571257
return (memchr(buf->ptr, '\0', buf->size) != NULL);
12581258
}
12591259

1260-
int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
1260+
int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf)
12611261
{
12621262
const char *ptr;
12631263
size_t len;
12641264

1265-
*bom = GIT_BOM_NONE;
1265+
*bom = GIT_BUF_BOM_NONE;
12661266
/* need at least 2 bytes to look for any BOM */
12671267
if (buf->size < 2)
12681268
return 0;
@@ -1273,30 +1273,30 @@ int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf)
12731273
switch (*ptr++) {
12741274
case 0:
12751275
if (len >= 4 && ptr[0] == 0 && ptr[1] == '\xFE' && ptr[2] == '\xFF') {
1276-
*bom = GIT_BOM_UTF32_BE;
1276+
*bom = GIT_BUF_BOM_UTF32_BE;
12771277
return 4;
12781278
}
12791279
break;
12801280
case '\xEF':
12811281
if (len >= 3 && ptr[0] == '\xBB' && ptr[1] == '\xBF') {
1282-
*bom = GIT_BOM_UTF8;
1282+
*bom = GIT_BUF_BOM_UTF8;
12831283
return 3;
12841284
}
12851285
break;
12861286
case '\xFE':
12871287
if (*ptr == '\xFF') {
1288-
*bom = GIT_BOM_UTF16_BE;
1288+
*bom = GIT_BUF_BOM_UTF16_BE;
12891289
return 2;
12901290
}
12911291
break;
12921292
case '\xFF':
12931293
if (*ptr != '\xFE')
12941294
break;
12951295
if (len >= 4 && ptr[1] == 0 && ptr[2] == 0) {
1296-
*bom = GIT_BOM_UTF32_LE;
1296+
*bom = GIT_BUF_BOM_UTF32_LE;
12971297
return 4;
12981298
} else {
1299-
*bom = GIT_BOM_UTF16_LE;
1299+
*bom = GIT_BUF_BOM_UTF16_LE;
13001300
return 2;
13011301
}
13021302
break;

src/buffer.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
*/
1919

2020
typedef enum {
21-
GIT_BOM_NONE = 0,
22-
GIT_BOM_UTF8 = 1,
23-
GIT_BOM_UTF16_LE = 2,
24-
GIT_BOM_UTF16_BE = 3,
25-
GIT_BOM_UTF32_LE = 4,
26-
GIT_BOM_UTF32_BE = 5
27-
} git_bom_t;
21+
GIT_BUF_BOM_NONE = 0,
22+
GIT_BUF_BOM_UTF8 = 1,
23+
GIT_BUF_BOM_UTF16_LE = 2,
24+
GIT_BUF_BOM_UTF16_BE = 3,
25+
GIT_BUF_BOM_UTF32_LE = 4,
26+
GIT_BUF_BOM_UTF32_BE = 5
27+
} git_buf_bom_t;
2828

2929
typedef struct {
30-
git_bom_t bom; /* BOM found at head of text */
30+
git_buf_bom_t bom; /* BOM found at head of text */
3131
unsigned int nul, cr, lf, crlf; /* NUL, CR, LF and CRLF counts */
3232
unsigned int printable, nonprintable; /* These are just approximations! */
3333
} git_buf_text_stats;
@@ -293,7 +293,7 @@ extern int git_buf_common_prefix(git_buf *buf, const git_strarray *strs);
293293
* @param buf Buffer in which to check the first bytes for a BOM
294294
* @return Number of bytes of BOM data (or 0 if no BOM found)
295295
*/
296-
extern int git_buf_detect_bom(git_bom_t *bom, const git_buf *buf);
296+
extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
297297

298298
/**
299299
* Gather stats for a piece of text

src/config_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ static int parse_section_header(git_config_parser *reader, char **section_out)
228228
static int skip_bom(git_parse_ctx *parser)
229229
{
230230
git_buf buf = GIT_BUF_INIT_CONST(parser->content, parser->content_len);
231-
git_bom_t bom;
231+
git_buf_bom_t bom;
232232
int bom_offset = git_buf_detect_bom(&bom, &buf);
233233

234-
if (bom == GIT_BOM_UTF8)
234+
if (bom == GIT_BUF_BOM_UTF8)
235235
git_parse_advance_chars(parser, bom_offset);
236236

237237
/* TODO: reference implementation is pretty stupid with BoM */

tests/object/blob/filter.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
4343
{ 0, 0, 2, 2, 2, 6, 0 },
4444
{ 0, 0, 4, 4, 1, 31, 0 },
4545
{ 0, 1, 1, 2, 1, 9, 5 },
46-
{ GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
47-
{ GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
48-
{ GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
46+
{ GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
47+
{ GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
48+
{ GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
4949
};
5050

5151
void test_object_blob_filter__initialize(void)

0 commit comments

Comments
 (0)