Re: [PATCH 5/5] cat-file: use packed_object_info() for --batch-all-objects
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 7, 2021, 20:56 UTC
- Message-ID
- <xmqqily8pn9h.fsf@gitster.g>
- In-Reply-To
- <YVy3rPuUal0+9iJs@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c > index b533935d5c..219ff5628d 100644 > --- a/builtin/cat-file.c > +++ b/builtin/cat-file.c > @@ -358,15 +358,26 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
The two new parameters might deserve a comment in front of the function as to the calling convention (namely, offset can be any garbage when the caller signals "unknown" with pack==NULL).
Show 32 quoted lines
> static void batch_object_write(const char *obj_name,
> struct strbuf *scratch,
> struct batch_options *opt,
> - struct expand_data *data)
> + struct expand_data *data,
> + struct packed_git *pack,
> + off_t offset)
> {
> - if (!data->skip_object_info &&
> - oid_object_info_extended(the_repository, &data->oid, &data->info,
> - OBJECT_INFO_LOOKUP_REPLACE) < 0) {
> - printf("%s missing\n",
> - obj_name ? obj_name : oid_to_hex(&data->oid));
> - fflush(stdout);
> - return;
> + if (!data->skip_object_info) {
> + int ret;
> +
> + if (pack)
> + ret = packed_object_info(the_repository, pack, offset,
> + &data->info);
> + else
> + ret = oid_object_info_extended(the_repository,
> + &data->oid, &data->info,
> + OBJECT_INFO_LOOKUP_REPLACE);
> + if (ret < 0) {
> + printf("%s missing\n",
> + obj_name ? obj_name : oid_to_hex(&data->oid));
> + fflush(stdout);
> + return;
> + }
> }The implementation is quite straight-forward.
Show 31 quoted lines
> @@ -463,31 +475,36 @@ static int collect_packed_object(const struct object_id *oid,
> return 0;
> }
>
> -static int batch_unordered_object(const struct object_id *oid, void *vdata)
> +static int batch_unordered_object(const struct object_id *oid,
> + struct packed_git *pack, off_t offset,
> + void *vdata)
> {
> struct object_cb_data *data = vdata;
>
> if (oidset_insert(data->seen, oid))
> return 0;
>
> oidcpy(&data->expand->oid, oid);
> - batch_object_write(NULL, data->scratch, data->opt, data->expand);
> + batch_object_write(NULL, data->scratch, data->opt, data->expand,
> + pack, offset);
> return 0;
> }
> ...
> static int batch_unordered_packed(const struct object_id *oid,
> struct packed_git *pack,
> uint32_t pos,
> void *data)
> {
> - return batch_unordered_object(oid, data);
> + return batch_unordered_object(oid, pack,
> + nth_packed_object_offset(pack, pos),
> + data);
> }We used to discard a good piece of info (i.e. which pack we found the object in), but we can make good use of it.
Nice.