git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice
@ 2014-08-31  4:33 Nguyễn Thái Ngọc Duy
  2014-09-02 18:12 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-08-31  4:33 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

In the --auto code path, gc_before_repack() is called once in parent
process then again in the forked process. Stop the second run.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/gc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/builtin/gc.c b/builtin/gc.c
index 8d219d8..fb0cff3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -261,6 +261,11 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 
 static int gc_before_repack(void)
 {
+	static int nr_runs;
+
+	if (nr_runs++)
+		return 0;
+
 	if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
 		return error(FAILED_RUN, pack_refs_cmd.argv[0]);
 
-- 
2.1.0.rc0.78.gc0d8480

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

* Re: [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice
  2014-08-31  4:33 [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice Nguyễn Thái Ngọc Duy
@ 2014-09-02 18:12 ` Junio C Hamano
  2014-09-02 19:16   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2014-09-02 18:12 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> In the --auto code path, gc_before_repack() is called once in parent
> process then again in the forked process. Stop the second run.

Hmph.  Is the true reason why this happens because we have two calls
to gc_before_repack() in the main, and one is before daemonize()?
Shouldn't this protection be in the caller?

>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/gc.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 8d219d8..fb0cff3 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -261,6 +261,11 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
>  
>  static int gc_before_repack(void)
>  {
> +	static int nr_runs;
> +
> +	if (nr_runs++)
> +		return 0;
> +
>  	if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
>  		return error(FAILED_RUN, pack_refs_cmd.argv[0]);

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

* Re: [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice
  2014-09-02 18:12 ` Junio C Hamano
@ 2014-09-02 19:16   ` Junio C Hamano
  2014-09-04 14:13     ` Duy Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2014-09-02 19:16 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> In the --auto code path, gc_before_repack() is called once in parent
>> process then again in the forked process. Stop the second run.
>
> Hmph.  Is the true reason why this happens because we have two calls
> to gc_before_repack() in the main, and one is before daemonize()?
> Shouldn't this protection be in the caller?

Actually, I think the function already is protecting wastage of
getting called twice by saying "I've done pack-refs already" and
"I've done prune-reflogs already" by setting the two variables to
zero.  Isn't that sufficient?

What problem is this patch trying to fix?

>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  builtin/gc.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/builtin/gc.c b/builtin/gc.c
>> index 8d219d8..fb0cff3 100644
>> --- a/builtin/gc.c
>> +++ b/builtin/gc.c
>> @@ -261,6 +261,11 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
>>  
>>  static int gc_before_repack(void)
>>  {
>> +	static int nr_runs;
>> +
>> +	if (nr_runs++)
>> +		return 0;
>> +
>>  	if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
>>  		return error(FAILED_RUN, pack_refs_cmd.argv[0]);

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

* Re: [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice
  2014-09-02 19:16   ` Junio C Hamano
@ 2014-09-04 14:13     ` Duy Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Duy Nguyen @ 2014-09-04 14:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Wed, Sep 3, 2014 at 2:16 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>>
>>> In the --auto code path, gc_before_repack() is called once in parent
>>> process then again in the forked process. Stop the second run.
>>
>> Hmph.  Is the true reason why this happens because we have two calls
>> to gc_before_repack() in the main, and one is before daemonize()?
>> Shouldn't this protection be in the caller?
>
> Actually, I think the function already is protecting wastage of
> getting called twice by saying "I've done pack-refs already" and
> "I've done prune-reflogs already" by setting the two variables to
> zero.  Isn't that sufficient?
>
> What problem is this patch trying to fix?

Oops. I missed that (and should have verified the problem in the first
place). Sorry for the noise.
-- 
Duy

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

end of thread, other threads:[~2014-09-04 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-31  4:33 [PATCH] gc --auto: do not run 'pack-refs' and 'reflog expire' twice Nguyễn Thái Ngọc Duy
2014-09-02 18:12 ` Junio C Hamano
2014-09-02 19:16   ` Junio C Hamano
2014-09-04 14:13     ` Duy Nguyen

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).