]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file.c: make parse_loose_header_extended() public
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 1 Oct 2021 09:16:47 +0000 (11:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Oct 2021 22:06:00 +0000 (15:06 -0700)
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>
cache.h
object-file.c
streaming.c

diff --git a/cache.h b/cache.h
index ba04ff8bd36b3627c95fc7b9b3fc2aec2d55c205..985caced24668395a2531e78f714b8343feea4e7 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1303,7 +1303,9 @@ char *xdg_cache_home(const char *filename);
 int git_open_cloexec(const char *name, int flags);
 #define git_open(name) git_open_cloexec(name, O_RDONLY)
 int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
-int parse_loose_header(const char *hdr, unsigned long *sizep);
+struct object_info;
+int parse_loose_header(const char *hdr, struct object_info *oi,
+                      unsigned int flags);
 
 int check_object_signature(struct repository *r, const struct object_id *oid,
                           void *buf, unsigned long size, const char *type);
index 3a7fe4fe96d24e1f640daaeb0e7b5fb9ef6f05de..6d97a6f69baf2f5a523b6fffcfcf5dd36e60902c 100644 (file)
@@ -1340,8 +1340,8 @@ static void *unpack_loose_rest(git_zstream *stream,
  * too permissive for what we want to check. So do an anal
  * object header parse by hand.
  */
-static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
-                                      unsigned int flags)
+int parse_loose_header(const char *hdr, struct object_info *oi,
+                      unsigned int flags)
 {
        const char *type_buf = hdr;
        unsigned long size;
@@ -1401,14 +1401,6 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi,
        return *hdr ? -1 : type;
 }
 
-int parse_loose_header(const char *hdr, unsigned long *sizep)
-{
-       struct object_info oi = OBJECT_INFO_INIT;
-
-       oi.sizep = sizep;
-       return parse_loose_header_extended(hdr, &oi, 0);
-}
-
 static int loose_object_info(struct repository *r,
                             const struct object_id *oid,
                             struct object_info *oi, int flags)
@@ -1463,10 +1455,10 @@ static int loose_object_info(struct repository *r,
        if (status < 0)
                ; /* Do nothing */
        else if (hdrbuf.len) {
-               if ((status = parse_loose_header_extended(hdrbuf.buf, oi, flags)) < 0)
+               if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0)
                        status = error(_("unable to parse %s header with --allow-unknown-type"),
                                       oid_to_hex(oid));
-       } else if ((status = parse_loose_header_extended(hdr, oi, flags)) < 0)
+       } else if ((status = parse_loose_header(hdr, oi, flags)) < 0)
                status = error(_("unable to parse %s header"), oid_to_hex(oid));
 
        if (status >= 0 && oi->contentp) {
@@ -2547,6 +2539,8 @@ int read_loose_object(const char *path,
        unsigned long mapsize;
        git_zstream stream;
        char hdr[MAX_HEADER_LEN];
+       struct object_info oi = OBJECT_INFO_INIT;
+       oi.sizep = size;
 
        *contents = NULL;
 
@@ -2561,7 +2555,7 @@ int read_loose_object(const char *path,
                goto out;
        }
 
-       *type = parse_loose_header(hdr, size);
+       *type = parse_loose_header(hdr, &oi, 0);
        if (*type < 0) {
                error(_("unable to parse header of %s"), path);
                git_inflate_end(&stream);
index 5f480ad50c415cc48a591adb29b46f00b67468d7..8beac62cbb71038a34096acd6f6c1a9b07723779 100644 (file)
@@ -223,6 +223,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
                              const struct object_id *oid,
                              enum object_type *type)
 {
+       struct object_info oi = OBJECT_INFO_INIT;
+       oi.sizep = &st->size;
+
        st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
        if (!st->u.loose.mapped)
                return -1;
@@ -231,7 +234,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
                                 st->u.loose.mapsize,
                                 st->u.loose.hdr,
                                 sizeof(st->u.loose.hdr)) < 0) ||
-           (parse_loose_header(st->u.loose.hdr, &st->size) < 0)) {
+           (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) {
                git_inflate_end(&st->z);
                munmap(st->u.loose.mapped, st->u.loose.mapsize);
                return -1;