git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing
@ 2007-10-10 23:49 Brandon Casey
  2007-10-11  0:12 ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Brandon Casey @ 2007-10-10 23:49 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

This makes use of repack's new "-A" option which does not drop packed
unreachable objects. This makes git-gc safe to call at any time,
particularly when a repository is referenced as an alternate by
another repository.

git-gc --prune will use the "-a" option to repack instead of "-A", so
that packed unreachable objects will be removed.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 builtin-gc.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index 23ad2b6..779245b 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -26,7 +26,7 @@ static int gc_auto_pack_limit = 20;
 #define MAX_ADD 10
 static const char *argv_pack_refs[] = {"pack-refs", "--all", "--prune", NULL};
 static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
-static const char *argv_repack[MAX_ADD] = {"repack", "-a", "-d", "-l", NULL};
+static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL};
 static const char *argv_prune[] = {"prune", NULL};
 static const char *argv_rerere[] = {"rerere", "gc", NULL};
 
@@ -143,8 +143,6 @@ static int too_many_packs(void)
 
 static int need_to_gc(void)
 {
-	int ac = 0;
-
 	/*
 	 * Setting gc.auto and gc.autopacklimit to 0 or negative can
 	 * disable the automatic gc.
@@ -158,14 +156,10 @@ static int need_to_gc(void)
 	 * we run "repack -A -d -l".  Otherwise we tell the caller
 	 * there is no need.
 	 */
-	argv_repack[ac++] = "repack";
 	if (too_many_packs())
-		argv_repack[ac++] = "-A";
+		append_option(argv_repack, "-A", MAX_ADD);
 	else if (!too_many_loose_objects())
 		return 0;
-	argv_repack[ac++] = "-d";
-	argv_repack[ac++] = "-l";
-	argv_repack[ac++] = NULL;
 	return 1;
 }
 
@@ -211,6 +205,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		prune = 0;
 		if (!need_to_gc())
 			return 0;
+	} else {
+		/*
+		 * Use safer (for shared repos) "-A" option to
+		 * repack when not pruning. Auto-gc makes its
+                 * own decision.
+		 */
+		if (prune)
+			append_option(argv_repack, "-a", MAX_ADD);
+		else
+			append_option(argv_repack, "-A", MAX_ADD);
 	}
 
 	if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
-- 
1.5.3.4.207.g00000

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing
  2007-10-10 23:49 [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing Brandon Casey
@ 2007-10-11  0:12 ` Johannes Schindelin
  2007-10-11  0:26   ` Brandon Casey
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2007-10-11  0:12 UTC (permalink / raw)
  To: Brandon Casey; +Cc: Git Mailing List, Junio C Hamano

Hi,

On Wed, 10 Oct 2007, Brandon Casey wrote:

>  static int need_to_gc(void)
>  {
> -	int ac = 0;
> -
>  	/*
>  	 * Setting gc.auto and gc.autopacklimit to 0 or negative can
>  	 * disable the automatic gc.
> @@ -158,14 +156,10 @@ static int need_to_gc(void)
>  	 * we run "repack -A -d -l".  Otherwise we tell the caller
>  	 * there is no need.
>  	 */
> -	argv_repack[ac++] = "repack";
>  	if (too_many_packs())
> -		argv_repack[ac++] = "-A";
> +		append_option(argv_repack, "-A", MAX_ADD);
>  	else if (!too_many_loose_objects())
>  		return 0;
> -	argv_repack[ac++] = "-d";
> -	argv_repack[ac++] = "-l";
> -	argv_repack[ac++] = NULL;
>  	return 1;
>  }
>  

This is a nice cleanup, but it does not belong in this patch.

> @@ -211,6 +205,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>  		prune = 0;
>  		if (!need_to_gc())
>  			return 0;
> +	} else {
> +		/*
> +		 * Use safer (for shared repos) "-A" option to
> +		 * repack when not pruning. Auto-gc makes its
> +                 * own decision.
> +		 */
> +		if (prune)
> +			append_option(argv_repack, "-a", MAX_ADD);
> +		else
> +			append_option(argv_repack, "-A", MAX_ADD);
>  	}
>  
>  	if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))

To use the append_option() function, you need to make sure that the argv 
has enough space, so I suggest adding another NULL to argv_repack[].  This 
is enough, since you only ever add one option.  But you should mention it 
somewhere, probably above the definition of argv_repack[].

Other than that: I think your patch makes tons of sense; much better than 
what I tried to cobble together with the cyclic alternates detection.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing
  2007-10-11  0:12 ` Johannes Schindelin
@ 2007-10-11  0:26   ` Brandon Casey
  2007-10-11  0:49     ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Brandon Casey @ 2007-10-11  0:26 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List, Junio C Hamano

On Thu, 11 Oct 2007, Johannes Schindelin wrote:

> Hi,
>
> On Wed, 10 Oct 2007, Brandon Casey wrote:

<snip>

> This is a nice cleanup, but it does not belong in this patch.

I was thinking the same thing right after I sent it off.

>
>> @@ -211,6 +205,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>>  		prune = 0;
>>  		if (!need_to_gc())
>>  			return 0;
>> +	} else {
>> +		/*
>> +		 * Use safer (for shared repos) "-A" option to
>> +		 * repack when not pruning. Auto-gc makes its
>> +                 * own decision.
>> +		 */
>> +		if (prune)
>> +			append_option(argv_repack, "-a", MAX_ADD);
>> +		else
>> +			append_option(argv_repack, "-A", MAX_ADD);
>>  	}
>>
>>  	if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
>
> To use the append_option() function, you need to make sure that the argv
> has enough space, so I suggest adding another NULL to argv_repack[].  This
> is enough, since you only ever add one option.  But you should mention it
> somewhere, probably above the definition of argv_repack[].

Shouldn't argv_repack have space for MAX_ADD (10) items?

append_option() is already used with argv_repack when --aggressive is
used.

> Other than that: I think your patch makes tons of sense; much better than
> what I tried to cobble together with the cyclic alternates detection.

Thanks.

-brandon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing
  2007-10-11  0:26   ` Brandon Casey
@ 2007-10-11  0:49     ` Johannes Schindelin
  2007-10-11  0:59       ` Brandon Casey
  2007-10-11  1:00       ` [PATCH] git-gc --auto: simplify "repack" command line building Brandon Casey
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Schindelin @ 2007-10-11  0:49 UTC (permalink / raw)
  To: Brandon Casey; +Cc: Git Mailing List, Junio C Hamano

Hi,

On Wed, 10 Oct 2007, Brandon Casey wrote:

> On Thu, 11 Oct 2007, Johannes Schindelin wrote:
> 
> > > @@ -211,6 +205,16 @@ int cmd_gc(int argc, const char **argv, const char
> > > *prefix)
> > >  		prune = 0;
> > >  		if (!need_to_gc())
> > >  			return 0;
> > > +	} else {
> > > +		/*
> > > +		 * Use safer (for shared repos) "-A" option to
> > > +		 * repack when not pruning. Auto-gc makes its
> > > +                 * own decision.
> > > +		 */
> > > +		if (prune)
> > > +			append_option(argv_repack, "-a", MAX_ADD);
> > > +		else
> > > +			append_option(argv_repack, "-A", MAX_ADD);
> > >  	}
> > > 
> > >  	if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
> > 
> > To use the append_option() function, you need to make sure that the 
> > argv has enough space, so I suggest adding another NULL to 
> > argv_repack[].  This is enough, since you only ever add one option.  
> > But you should mention it somewhere, probably above the definition of 
> > argv_repack[].
> 
> Shouldn't argv_repack have space for MAX_ADD (10) items?

Ouch... I overlooked that.  So please strike this objection.

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing
  2007-10-11  0:49     ` Johannes Schindelin
@ 2007-10-11  0:59       ` Brandon Casey
  2007-10-11  1:00       ` [PATCH] git-gc --auto: simplify "repack" command line building Brandon Casey
  1 sibling, 0 replies; 6+ messages in thread
From: Brandon Casey @ 2007-10-11  0:59 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List, Junio C Hamano

This makes use of repack's new "-A" option which does not drop packed
unreachable objects. This makes git-gc safe to call at any time,
particularly when a repository is referenced as an alternate by
another repository.

git-gc --prune will use the "-a" option to repack instead of "-A", so
that packed unreachable objects will be removed.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 builtin-gc.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index 23ad2b6..6323e0d 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -26,7 +26,7 @@ static int gc_auto_pack_limit = 20;
 #define MAX_ADD 10
 static const char *argv_pack_refs[] = {"pack-refs", "--all", "--prune", NULL};
 static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
-static const char *argv_repack[MAX_ADD] = {"repack", "-a", "-d", "-l", NULL};
+static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL};
 static const char *argv_prune[] = {"prune", NULL};
 static const char *argv_rerere[] = {"rerere", "gc", NULL};
 
@@ -211,6 +211,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		prune = 0;
 		if (!need_to_gc())
 			return 0;
+	} else {
+		/*
+		 * Use safer (for shared repos) "-A" option to
+		 * repack when not pruning. Auto-gc makes its
+		 * own decision.
+		 */
+		if (prune)
+			append_option(argv_repack, "-a", MAX_ADD);
+		else
+			append_option(argv_repack, "-A", MAX_ADD);
 	}
 
 	if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
-- 
1.5.3.4.208.g729c0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] git-gc --auto: simplify "repack" command line building
  2007-10-11  0:49     ` Johannes Schindelin
  2007-10-11  0:59       ` Brandon Casey
@ 2007-10-11  1:00       ` Brandon Casey
  1 sibling, 0 replies; 6+ messages in thread
From: Brandon Casey @ 2007-10-11  1:00 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List, Junio C Hamano

Since "-a" is removed from the base repack command line,
we can simplify how we add additional options to this
command line when using --auto.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 builtin-gc.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index 6323e0d..956c32d 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -143,8 +143,6 @@ static int too_many_packs(void)
 
 static int need_to_gc(void)
 {
-	int ac = 0;
-
 	/*
 	 * Setting gc.auto and gc.autopacklimit to 0 or negative can
 	 * disable the automatic gc.
@@ -158,14 +156,10 @@ static int need_to_gc(void)
 	 * we run "repack -A -d -l".  Otherwise we tell the caller
 	 * there is no need.
 	 */
-	argv_repack[ac++] = "repack";
 	if (too_many_packs())
-		argv_repack[ac++] = "-A";
+		append_option(argv_repack, "-A", MAX_ADD);
 	else if (!too_many_loose_objects())
 		return 0;
-	argv_repack[ac++] = "-d";
-	argv_repack[ac++] = "-l";
-	argv_repack[ac++] = NULL;
 	return 1;
 }
 
-- 
1.5.3.4.208.g729c0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-11  1:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-10 23:49 [PATCH] git-gc: by default use safer "-A" option to repack when not --prune'ing Brandon Casey
2007-10-11  0:12 ` Johannes Schindelin
2007-10-11  0:26   ` Brandon Casey
2007-10-11  0:49     ` Johannes Schindelin
2007-10-11  0:59       ` Brandon Casey
2007-10-11  1:00       ` [PATCH] git-gc --auto: simplify "repack" command line building Brandon Casey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).