threads / patch / 55525

patchbuiltin/repack.c: set a default factor for '--geometric'

Subject: [PATCH] builtin/repack.c: set a default factor for '--geometric'

## tl;dr

6 messages between Apr 20, 2021 and Apr 20, 2021. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Taylor Blau· Apr 20, 2021, 01:47 UTC · lore

The '--geometric=<n>' argument specifies that each pack must contain at least 'n' times as many objects as the size of the next-largest pack. The factor 'n' is customizable, but setting it to '2' is a sane default.

Instead of making the factor a required argument, make the argument optional with a default value of '2'.

To ensure that the option is setup correctly, modify the most complex test of t7703 to drop the explicit factor.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 Documentation/git-repack.txt | 8 ++++----
 builtin/repack.c             | 5 +++--
 t/t7703-repack-geometric.sh  | 2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)
Show changes to 3 files +8 −6

Documentation/git-repack.txt, builtin/repack.c, t/t7703-repack-geometric.sh

diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
index 317d63cf0d..d948a2913d 100644
--- a/Documentation/git-repack.txt
+++ b/Documentation/git-repack.txt
@@ -165,11 +165,11 @@ depth is 4095.
 	Pass the `--delta-islands` option to `git-pack-objects`, see
 	linkgit:git-pack-objects[1].
 
--g=<factor>::
---geometric=<factor>::
+-g=[<factor>]::
+--geometric[=<factor>]::
 	Arrange resulting pack structure so that each successive pack
-	contains at least `<factor>` times the number of objects as the
-	next-largest pack.
+	contains at least `<factor>` (`2` if unspecified) times the
+	number of objects as the next-largest pack.
 +
 `git repack` ensures this by determining a "cut" of packfiles that need
 to be repacked into one in order to ensure a geometric progression. It
diff --git a/builtin/repack.c b/builtin/repack.c
index 2847fdfbab..f2359c9d3a 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -494,8 +494,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 				N_("repack objects in packs marked with .keep")),
 		OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
 				N_("do not repack this pack")),
-		OPT_INTEGER('g', "geometric", &geometric_factor,
-			    N_("find a geometric progression with factor <N>")),
+		{ OPTION_INTEGER, 'g', "geometric", &geometric_factor, N_("n"),
+				N_("find a geometric progression with factor <n>"),
+				PARSE_OPT_OPTARG, NULL, 2 },
 		OPT_END()
 	};
 
diff --git a/t/t7703-repack-geometric.sh b/t/t7703-repack-geometric.sh
index 5ccaa440e0..77cd5f2284 100755
--- a/t/t7703-repack-geometric.sh
+++ b/t/t7703-repack-geometric.sh
@@ -123,7 +123,7 @@ test_expect_success '--geometric with small- and large-pack rollup' '
 
 		find $objdir/pack -name "*.pack" | sort >before &&
 
-		git repack --geometric 2 -d &&
+		git repack --geometric -d &&
 
 		find $objdir/pack -name "*.pack" | sort >after &&
 		comm -12 before after >untouched &&
-- 
2.31.1.163.ga65ce7f831
Derrick Stolee· Apr 20, 2021, 12:39 UTC · re: Taylor Blau · lore

Re: [PATCH] builtin/repack.c: set a default factor for '--geometric'

On 4/19/2021 9:47 PM, Taylor Blau wrote:
Show 6 quoted lines
> The '--geometric=<n>' argument specifies that each pack must contain at
> least 'n' times as many objects as the size of the next-largest pack.
> The factor 'n' is customizable, but setting it to '2' is a sane default.
> 
> Instead of making the factor a required argument, make the argument
> optional with a default value of '2'.
This flexibility is nice.
 
> To ensure that the option is setup correctly, modify the most complex
> test of t7703 to drop the explicit factor.
Good testing.
Show 9 quoted lines
> --g=<factor>::
> ---geometric=<factor>::
> +-g=[<factor>]::
> +--geometric[=<factor>]::
>  	Arrange resulting pack structure so that each successive pack
> -	contains at least `<factor>` times the number of objects as the
> -	next-largest pack.
> +	contains at least `<factor>` (`2` if unspecified) times the
> +	number of objects as the next-largest pack.

The parenthetical interrupts what `<factor>` means. Perhaps rearrange:

	Arrange resulting pack structure so that each successive pack
	contains at least `<factor>` times the number of objects as the
	next-largest pack. If `<factor>` is not specified, then `2` is
	used by default.
Rest of the diff looks good.

Thanks, -Stolee

Junio C Hamano· Apr 20, 2021, 20:25 UTC · re: Taylor Blau · lore

Re: [PATCH] builtin/repack.c: set a default factor for '--geometric'

Taylor Blau <me@ttaylorr.com> writes:
> --g=<factor>::
> ---geometric=<factor>::
> +-g=[<factor>]::
> +--geometric[=<factor>]::

Do you mean "git repack -g= -d" is (1) accepted and/or (2) recommended?

If not, we'd want "-g[=<factor>]" similar to the longer form, no?
Taylor Blau· Apr 20, 2021, 20:31 UTC · re: Junio C Hamano · lore

Re: [PATCH] builtin/repack.c: set a default factor for '--geometric'

On Tue, Apr 20, 2021 at 01:25:02PM -0700, Junio C Hamano wrote:
Show 11 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
> > --g=<factor>::
> > ---geometric=<factor>::
> > +-g=[<factor>]::
> > +--geometric[=<factor>]::
>
> Do you mean "git repack -g= -d" is (1) accepted and/or (2)
> recommended?
>
> If not, we'd want "-g[=<factor>]" similar to the longer form, no?

Thanks for spotting. The '[' should come before the '=' character, not after. I'll send a reroll with this (and a suggestion from Stolee).

Thanks, Taylor

Taylor Blau· Apr 20, 2021, 20:32 UTC · re: Taylor Blau · lore

[PATCH v2] builtin/repack.c: set a default factor for '--geometric'

The '--geometric=<n>' argument specifies that each pack must contain at least 'n' times as many objects as the size of the next-largest pack. The factor 'n' is customizable, but setting it to '2' is a sane default.

Instead of making the factor a required argument, make the argument optional with a default value of '2'.

To ensure that the option is setup correctly, modify the most complex test of t7703 to drop the explicit factor.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
Range-diff against v1:
1:  1ecab81739 ! 1:  8d8dea2e2c builtin/repack.c: set a default factor for '--geometric'
    @@ Documentation/git-repack.txt: depth is 4095.
      
     --g=<factor>::
     ---geometric=<factor>::
    -+-g=[<factor>]::
    ++-g[=<factor>]::
     +--geometric[=<factor>]::
      	Arrange resulting pack structure so that each successive pack
    --	contains at least `<factor>` times the number of objects as the
    + 	contains at least `<factor>` times the number of objects as the
     -	next-largest pack.
    -+	contains at least `<factor>` (`2` if unspecified) times the
    -+	number of objects as the next-largest pack.
    ++	next-largest pack. If `<factor>` is not specified, then `2` is
    ++	used by default.
      +
      `git repack` ensures this by determining a "cut" of packfiles that need
      to be repacked into one in order to ensure a geometric progression. It
 Documentation/git-repack.txt | 7 ++++---
 builtin/repack.c             | 5 +++--
 t/t7703-repack-geometric.sh  | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
Show changes to 3 files +8 −5

Documentation/git-repack.txt, builtin/repack.c, t/t7703-repack-geometric.sh

diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
index 317d63cf0d..f7c7e0aeae 100644
--- a/Documentation/git-repack.txt
+++ b/Documentation/git-repack.txt
@@ -165,11 +165,12 @@ depth is 4095.
 	Pass the `--delta-islands` option to `git-pack-objects`, see
 	linkgit:git-pack-objects[1].
 
--g=<factor>::
---geometric=<factor>::
+-g[=<factor>]::
+--geometric[=<factor>]::
 	Arrange resulting pack structure so that each successive pack
 	contains at least `<factor>` times the number of objects as the
-	next-largest pack.
+	next-largest pack. If `<factor>` is not specified, then `2` is
+	used by default.
 +
 `git repack` ensures this by determining a "cut" of packfiles that need
 to be repacked into one in order to ensure a geometric progression. It
diff --git a/builtin/repack.c b/builtin/repack.c
index 2847fdfbab..f2359c9d3a 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -494,8 +494,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 				N_("repack objects in packs marked with .keep")),
 		OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
 				N_("do not repack this pack")),
-		OPT_INTEGER('g', "geometric", &geometric_factor,
-			    N_("find a geometric progression with factor <N>")),
+		{ OPTION_INTEGER, 'g', "geometric", &geometric_factor, N_("n"),
+				N_("find a geometric progression with factor <n>"),
+				PARSE_OPT_OPTARG, NULL, 2 },
 		OPT_END()
 	};
 
diff --git a/t/t7703-repack-geometric.sh b/t/t7703-repack-geometric.sh
index 5ccaa440e0..77cd5f2284 100755
--- a/t/t7703-repack-geometric.sh
+++ b/t/t7703-repack-geometric.sh
@@ -123,7 +123,7 @@ test_expect_success '--geometric with small- and large-pack rollup' '
 
 		find $objdir/pack -name "*.pack" | sort >before &&
 
-		git repack --geometric 2 -d &&
+		git repack --geometric -d &&
 
 		find $objdir/pack -name "*.pack" | sort >after &&
 		comm -12 before after >untouched &&
-- 
2.31.1.163.ga65ce7f831
Andreas Schwab· Apr 20, 2021, 21:44 UTC · re: Taylor Blau · lore

Re: [PATCH v2] builtin/repack.c: set a default factor for '--geometric'

On Apr 20 2021, Taylor Blau wrote:
Show 17 quoted lines
> diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
> index 317d63cf0d..f7c7e0aeae 100644
> --- a/Documentation/git-repack.txt
> +++ b/Documentation/git-repack.txt
> @@ -165,11 +165,12 @@ depth is 4095.
>  	Pass the `--delta-islands` option to `git-pack-objects`, see
>  	linkgit:git-pack-objects[1].
>  
> --g=<factor>::
> ---geometric=<factor>::
> +-g[=<factor>]::
> +--geometric[=<factor>]::
>  	Arrange resulting pack structure so that each successive pack
>  	contains at least `<factor>` times the number of objects as the
> -	next-largest pack.
> +	next-largest pack. If `<factor>` is not specified, then `2` is
> +	used by default.
I don't think the short option takes a '='.

$ ./git repack -g=2 error: switch `g' expects a numerical value

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

← back to recent threads