Skip to content

Commit ddb3474

Browse files
avargitster
authored andcommitted
object-file.c: make parse_loose_header_extended() public
Make the parse_loose_header_extended() function public and remove the parse_loose_header() wrapper. The only direct user of it outside of object-file.c itself was in streaming.c, that caller can simply pass the required "struct object-info *" instead. This change is being done in preparation for teaching read_loose_object() to accept a flag to pass to parse_loose_header(). It isn't strictly necessary for that change, we could simply use parse_loose_header_extended() there, but will leave the API in a better end state. It would be a better end-state to have already moved the declaration of these functions to object-store.h to avoid the forward declaration of "struct object_info" in cache.h, but let's leave that cleanup for some other time. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bfff2c4 commit ddb3474

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,9 @@ char *xdg_cache_home(const char *filename);
13031303
int git_open_cloexec(const char *name, int flags);
13041304
#define git_open(name) git_open_cloexec(name, O_RDONLY)
13051305
int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
1306-
int parse_loose_header(const char *hdr, unsigned long *sizep);
1306+
struct object_info;
1307+
int parse_loose_header(const char *hdr, struct object_info *oi,
1308+
unsigned int flags);
13071309

13081310
int check_object_signature(struct repository *r, const struct object_id *oid,
13091311
void *buf, unsigned long size, const char *type);

object-file.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,8 @@ static void *unpack_loose_rest(git_zstream *stream,
13401340
* too permissive for what we want to check. So do an anal
13411341
* object header parse by hand.
13421342
*/
1343-
static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
1344-
unsigned int flags)
1343+
int parse_loose_header(const char *hdr, struct object_info *oi,
1344+
unsigned int flags)
13451345
{
13461346
const char *type_buf = hdr;
13471347
unsigned long size;
@@ -1401,14 +1401,6 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
14011401
return *hdr ? -1 : type;
14021402
}
14031403

1404-
int parse_loose_header(const char *hdr, unsigned long *sizep)
1405-
{
1406-
struct object_info oi = OBJECT_INFO_INIT;
1407-
1408-
oi.sizep = sizep;
1409-
return parse_loose_header_extended(hdr, &oi, 0);
1410-
}
1411-
14121404
static int loose_object_info(struct repository *r,
14131405
const struct object_id *oid,
14141406
struct object_info *oi, int flags)
@@ -1463,10 +1455,10 @@ static int loose_object_info(struct repository *r,
14631455
if (status < 0)
14641456
; /* Do nothing */
14651457
else if (hdrbuf.len) {
1466-
if ((status = parse_loose_header_extended(hdrbuf.buf, oi, flags)) < 0)
1458+
if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0)
14671459
status = error(_("unable to parse %s header with --allow-unknown-type"),
14681460
oid_to_hex(oid));
1469-
} else if ((status = parse_loose_header_extended(hdr, oi, flags)) < 0)
1461+
} else if ((status = parse_loose_header(hdr, oi, flags)) < 0)
14701462
status = error(_("unable to parse %s header"), oid_to_hex(oid));
14711463

14721464
if (status >= 0 && oi->contentp) {
@@ -2547,6 +2539,8 @@ int read_loose_object(const char *path,
25472539
unsigned long mapsize;
25482540
git_zstream stream;
25492541
char hdr[MAX_HEADER_LEN];
2542+
struct object_info oi = OBJECT_INFO_INIT;
2543+
oi.sizep = size;
25502544

25512545
*contents = NULL;
25522546

@@ -2561,7 +2555,7 @@ int read_loose_object(const char *path,
25612555
goto out;
25622556
}
25632557

2564-
*type = parse_loose_header(hdr, size);
2558+
*type = parse_loose_header(hdr, &oi, 0);
25652559
if (*type < 0) {
25662560
error(_("unable to parse header of %s"), path);
25672561
git_inflate_end(&stream);

streaming.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
223223
const struct object_id *oid,
224224
enum object_type *type)
225225
{
226+
struct object_info oi = OBJECT_INFO_INIT;
227+
oi.sizep = &st->size;
228+
226229
st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
227230
if (!st->u.loose.mapped)
228231
return -1;
@@ -231,7 +234,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
231234
st->u.loose.mapsize,
232235
st->u.loose.hdr,
233236
sizeof(st->u.loose.hdr)) < 0) ||
234-
(parse_loose_header(st->u.loose.hdr, &st->size) < 0)) {
237+
(parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) {
235238
git_inflate_end(&st->z);
236239
munmap(st->u.loose.mapped, st->u.loose.mapsize);
237240
return -1;

0 commit comments

Comments
 (0)