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/patch-v6-09.22-5b9278e7bb4-20210907T104559Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 1, 2021 at 11:16 UTC ddb3474b66ef36da40a4cf8346ec4655518243cb
3 files changed +14 -15
cache.h
+3 -1
@@ -1303,7 +1303,9 @@ char *xdg_cache_home(const char *filename);
1303 int git_open_cloexec(const char *name, int flags);
1304 #define git_open(name) git_open_cloexec(name, O_RDONLY)
1305 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);
1309
1310 int check_object_signature(struct repository *r, const struct object_id *oid,
1311 void *buf, unsigned long size, const char *type);
object-file.c
+7 -13
@@ -1340,8 +1340,8 @@ static void *unpack_loose_rest(git_zstream *stream,
1340 * too permissive for what we want to check. So do an anal
1341 * object header parse by hand.
1342 */
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)
1345 {
1346 const char *type_buf = hdr;
1347 unsigned long size;
@@ -1401,14 +1401,6 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
1401 return *hdr ? -1 : type;
1402 }
1403
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 -
1404 static int loose_object_info(struct repository *r,
1405 const struct object_id *oid,
1406 struct object_info *oi, int flags)
@@ -1463,10 +1455,10 @@ static int loose_object_info(struct repository *r,
1455 if (status < 0)
1456 ; /* Do nothing */
1457 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)
1459 status = error(_("unable to parse %s header with --allow-unknown-type"),
1460 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)
1462 status = error(_("unable to parse %s header"), oid_to_hex(oid));
1463
1464 if (status >= 0 && oi->contentp) {
@@ -2547,6 +2539,8 @@ int read_loose_object(const char *path,
2539 unsigned long mapsize;
2540 git_zstream stream;
2541 char hdr[MAX_HEADER_LEN];
2542 + struct object_info oi = OBJECT_INFO_INIT;
2543 + oi.sizep = size;
2544
2545 *contents = NULL;
2546
@@ -2561,7 +2555,7 @@ int read_loose_object(const char *path,
2555 goto out;
2556 }
2557
2564 - *type = parse_loose_header(hdr, size);
2558 + *type = parse_loose_header(hdr, &oi, 0);
2559 if (*type < 0) {
2560 error(_("unable to parse header of %s"), path);
2561 git_inflate_end(&stream);
streaming.c
+4 -1
@@ -223,6 +223,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
223 const struct object_id *oid,
224 enum object_type *type)
225 {
226 + struct object_info oi = OBJECT_INFO_INIT;
227 + oi.sizep = &st->size;
228 +
229 st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
230 if (!st->u.loose.mapped)
231 return -1;
@@ -231,7 +234,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
234 st->u.loose.mapsize,
235 st->u.loose.hdr,
236 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)) {
238 git_inflate_end(&st->z);
239 munmap(st->u.loose.mapped, st->u.loose.mapsize);
240 return -1;