diff mbox series

[v2,3/8] pack-objects: limit scope in 'add_object_entry_from_pack()'

Message ID f8ac36b110b91ff3723f5049cfc6bf9f624521bd.1744661167.git.me@ttaylorr.com (mailing list archive)
State Superseded
Headers show
Series repack: avoid MIDX'ing cruft pack(s) where possible | expand

Commit Message

Taylor Blau April 14, 2025, 8:06 p.m. UTC
add_object_entry_from_pack() handles objects from identified packs by
checking their type, before adding commit objects as pending in the
subsequent traversal used by `--stdin-packs`.

There are a couple of quality-of-life refactorings that I noticed while
working in this area:

  - We declare 'revs' (given to us through the miscellaneous context
    argument) earlier in the "if (p)" conditional than is necessary.

  - The 'struct object_info' can use a designated initializer to fill in
    the structures type pointer, since that is the only field that we
    care about.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 builtin/pack-objects.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Elijah Newren April 15, 2025, 3:10 a.m. UTC | #1
On Mon, Apr 14, 2025 at 1:06 PM Taylor Blau <me@ttaylorr.com> wrote:
>
> add_object_entry_from_pack() handles objects from identified packs by
> checking their type, before adding commit objects as pending in the
> subsequent traversal used by `--stdin-packs`.
>
> There are a couple of quality-of-life refactorings that I noticed while
> working in this area:
>
>   - We declare 'revs' (given to us through the miscellaneous context
>     argument) earlier in the "if (p)" conditional than is necessary.

Fair enough.

>   - The 'struct object_info' can use a designated initializer to fill in
>     the structures type pointer, since that is the only field that we
>     care about.

I prefer the original; it's more future-proof against someone making
OBJECT_INFO_INIT be something other than an all-zero initializer.

>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  builtin/pack-objects.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index aaea968ed2..540e5eba9e 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -3490,14 +3490,12 @@ static int add_object_entry_from_pack(const struct object_id *oid,
>                 return 0;
>
>         if (p) {
> -               struct rev_info *revs = _data;
> -               struct object_info oi = OBJECT_INFO_INIT;
> -
> -               oi.typep = &type;
> +               struct object_info oi = { .typep = &type };
>                 if (packed_object_info(the_repository, p, ofs, &oi) < 0) {
>                         die(_("could not get type of object %s in pack %s"),
>                             oid_to_hex(oid), p->pack_name);
>                 } else if (type == OBJ_COMMIT) {
> +                       struct rev_info *revs = _data;
>                         /*
>                          * commits in included packs are used as starting points for the
>                          * subsequent revision walk
> --
> 2.49.0.229.gc267761125.dirty
diff mbox series

Patch

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index aaea968ed2..540e5eba9e 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3490,14 +3490,12 @@  static int add_object_entry_from_pack(const struct object_id *oid,
 		return 0;
 
 	if (p) {
-		struct rev_info *revs = _data;
-		struct object_info oi = OBJECT_INFO_INIT;
-
-		oi.typep = &type;
+		struct object_info oi = { .typep = &type };
 		if (packed_object_info(the_repository, p, ofs, &oi) < 0) {
 			die(_("could not get type of object %s in pack %s"),
 			    oid_to_hex(oid), p->pack_name);
 		} else if (type == OBJ_COMMIT) {
+			struct rev_info *revs = _data;
 			/*
 			 * commits in included packs are used as starting points for the
 			 * subsequent revision walk