Skip to contentSkip to conversation

gc --auto: do not run 'pack-refs' and 'reflog expire' twice

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gc --auto: do not run 'pack-refs' and 'reflog expire' twice

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

---
 builtin/gc.c | 5 +++++
 1 file changed, 5 insertions(+)
builtin/gc.c +5 -0
index 8d219d8..fb0cff3 100644
@@ -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]);
 
Signature · 1 line
2.1.0.rc0.78.gc0d8480
#1 lore raw
Quoted 2 lines · 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.

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?

Quoted 21 lines
---
 builtin/gc.c | 5 +++++
 1 file changed, 5 insertions(+)
builtin/gc.c +5 -0
index 8d219d8..fb0cff3 100644
@@ -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 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · 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.

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?

Quoted 20 lines
Quoted 20 lines
---
 builtin/gc.c | 5 +++++
 1 file changed, 5 insertions(+)
builtin/gc.c +5 -0
index 8d219d8..fb0cff3 100644
@@ -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]);
author
#3 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · 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.

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?

Quoted 6 lines

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.

Signature · 1 line
Duy