diff mbox series

[v3,3/9] pack-objects: factor out handling '--stdin-packs'

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

Commit Message

Taylor Blau April 15, 2025, 10:46 p.m. UTC
At the bottom of cmd_pack_objects() we check which mode the command is
running in (e.g., generating a cruft pack, handling '--stdin-packs',
using the internal rev-list, etc.) and handle the mode appropriately.

The '--stdin-packs' case is handled inline (dating back to its
introduction in 339bce27f4 (builtin/pack-objects.c: add '--stdin-packs'
option, 2021-02-22)) since it is relatively short. Extract the body of
"if (stdin_packs)" into its own function to prepare for the
implementation to become lengthier in a following commit.

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

Comments

Junio C Hamano April 16, 2025, 12:59 a.m. UTC | #1
Taylor Blau <me@ttaylorr.com> writes:

> At the bottom of cmd_pack_objects() we check which mode the command is
> running in (e.g., generating a cruft pack, handling '--stdin-packs',
> using the internal rev-list, etc.) and handle the mode appropriately.
>
> The '--stdin-packs' case is handled inline (dating back to its
> introduction in 339bce27f4 (builtin/pack-objects.c: add '--stdin-packs'
> option, 2021-02-22)) since it is relatively short. Extract the body of
> "if (stdin_packs)" into its own function to prepare for the
> implementation to become lengthier in a following commit.
>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  builtin/pack-objects.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)

Makes sense.

>
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index 4ab695a3aa..a293267074 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -3674,6 +3674,17 @@ static void read_packs_list_from_stdin(void)
>  	string_list_clear(&exclude_packs, 0);
>  }
>  
> +static void add_unreachable_loose_objects(void);
> +
> +static void read_stdin_packs(int rev_list_unpacked)
> +{
> +	/* avoids adding objects in excluded packs */
> +	ignore_packed_keep_in_core = 1;
> +	read_packs_list_from_stdin();
> +	if (rev_list_unpacked)
> +		add_unreachable_loose_objects();
> +}
> +
>  static void add_cruft_object_entry(const struct object_id *oid, enum object_type type,
>  				   struct packed_git *pack, off_t offset,
>  				   const char *name, uint32_t mtime)
> @@ -3769,7 +3780,6 @@ static void mark_pack_kept_in_core(struct string_list *packs, unsigned keep)
>  	}
>  }
>  
> -static void add_unreachable_loose_objects(void);
>  static void add_objects_in_unpacked_packs(void);
>  
>  static void enumerate_cruft_objects(void)
> @@ -4776,11 +4786,7 @@ int cmd_pack_objects(int argc,
>  		progress_state = start_progress(the_repository,
>  						_("Enumerating objects"), 0);
>  	if (stdin_packs) {
> -		/* avoids adding objects in excluded packs */
> -		ignore_packed_keep_in_core = 1;
> -		read_packs_list_from_stdin();
> -		if (rev_list_unpacked)
> -			add_unreachable_loose_objects();
> +		read_stdin_packs(rev_list_unpacked);
>  	} else if (cruft) {
>  		read_cruft_objects();
>  	} else if (!use_internal_rev_list) {
diff mbox series

Patch

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 4ab695a3aa..a293267074 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3674,6 +3674,17 @@  static void read_packs_list_from_stdin(void)
 	string_list_clear(&exclude_packs, 0);
 }
 
+static void add_unreachable_loose_objects(void);
+
+static void read_stdin_packs(int rev_list_unpacked)
+{
+	/* avoids adding objects in excluded packs */
+	ignore_packed_keep_in_core = 1;
+	read_packs_list_from_stdin();
+	if (rev_list_unpacked)
+		add_unreachable_loose_objects();
+}
+
 static void add_cruft_object_entry(const struct object_id *oid, enum object_type type,
 				   struct packed_git *pack, off_t offset,
 				   const char *name, uint32_t mtime)
@@ -3769,7 +3780,6 @@  static void mark_pack_kept_in_core(struct string_list *packs, unsigned keep)
 	}
 }
 
-static void add_unreachable_loose_objects(void);
 static void add_objects_in_unpacked_packs(void);
 
 static void enumerate_cruft_objects(void)
@@ -4776,11 +4786,7 @@  int cmd_pack_objects(int argc,
 		progress_state = start_progress(the_repository,
 						_("Enumerating objects"), 0);
 	if (stdin_packs) {
-		/* avoids adding objects in excluded packs */
-		ignore_packed_keep_in_core = 1;
-		read_packs_list_from_stdin();
-		if (rev_list_unpacked)
-			add_unreachable_loose_objects();
+		read_stdin_packs(rev_list_unpacked);
 	} else if (cruft) {
 		read_cruft_objects();
 	} else if (!use_internal_rev_list) {