Skip to contentSkip to conversation

Make git reflog expire honour core.sharedRepository.

PATCH In review Pierre Habouzit 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make git reflog expire honour core.sharedRepository.

---
 builtin-reflog.c       |    1 +
 t/t1301-shared-repo.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

Some people like to have logAllRefUpdates even for bare repositories, and if shared, git-gc breaks them.

builtin-reflog.c +1 -0
index 897d1dc..430929f 100644
@@ -308,6 +308,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref && commit_ref(lock)) {
 			status |= error("Couldn't set %s", lock->ref_name);
 		}
+		adjust_shared_perm(log_file);
 	}
 	free(newlog_path);
 	free(log_file);
t/t1301-shared-repo.sh +15 -0
index 5e4252a..6c78c8b 100755
@@ -83,4 +83,19 @@ do
 
 done
 
+test_expect_success 'git reflog expire honors core.sharedRepository' '
+	git config core.sharedRepository group &&
+	git reflog expire --all &&
+	actual="$(ls -l .git/logs/refs/heads/master)" &&
+	case "$actual" in
+	-rw-rw-*)
+		: happy
+		;;
+	*)
+		echo Ooops, .git/logs/refs/heads/master is not 0662 [$actual]
+		false
+		;;
+	esac
+'
+
 test_done
Signature · 1 line
1.5.6.rc3.149.gaacb0.dirty
#1 lore raw
Quoted 14 lines · Pierre Habouzit
---
 builtin-reflog.c       |    1 +
 t/t1301-shared-repo.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

Some people like to have logAllRefUpdates even for bare repositories, and if shared, git-gc breaks them.

builtin-reflog.c +0 -0
index 897d1dc..430929f 100644

builtin-reflog.c static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, · line 311

Quoted 4 lines
builtin-reflog.c +1 -0
@@ -308,6 +308,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref && commit_ref(lock)) {
 			status |= error("Couldn't set %s", lock->ref_name);
 		}
+		adjust_shared_perm(log_file);

Why is it sane to do this unconditionally, instead of putting in another else or something?

#2 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Pierre Habouzit
---
 builtin-reflog.c       |    1 +
 t/t1301-shared-repo.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

Some people like to have logAllRefUpdates even for bare repositories, and if shared, git-gc breaks them.

Quoted 12 lines

builtin-reflog.c static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, · line 311

Quoted 9 lines
builtin-reflog.c +1 -0
index 897d1dc..430929f 100644
@@ -308,6 +308,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref && commit_ref(lock)) {
 			status |= error("Couldn't set %s", lock->ref_name);
 		}
+		adjust_shared_perm(log_file);

Why is it sane to do this unconditionally, instead of putting in another else or something?

Huh indeed, the proper patch should have been:

- }
+ } else {
+ adjust_shared_perm(log_file);
+ }

It was inattention on my end, I focused more on writing a test case
than on the one liner fix. Sorry.

Signature · 3 lines
·O·  Pierre Habouzit
··O                                                [email protected]
OOO                                                http://www.madism.org
#3 lore raw
In reply to Junio C Hamano

Hi,

Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Pierre Habouzit
---
 builtin-reflog.c       |    1 +
 t/t1301-shared-repo.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

Some people like to have logAllRefUpdates even for bare repositories, and if shared, git-gc breaks them.

Quoted 12 lines

builtin-reflog.c static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, · line 311

Quoted 9 lines
builtin-reflog.c +1 -0
index 897d1dc..430929f 100644
@@ -308,6 +308,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref && commit_ref(lock)) {
 			status |= error("Couldn't set %s", lock->ref_name);
 		}
+		adjust_shared_perm(log_file);

Why is it sane to do this unconditionally, instead of putting in another else or something?

Because adjust_shared_perm() checks for shared_repository, and returns when there is nothing to do.

IMO this is a sane convention, since you _never_ want to do this unconditionally anyway, and you avoid a lot of identical "if () adjust()" constructs.

Ciao,
Dscho

#4 lore raw

Hi,

Quoted 26 lines · Johannes Schindelin
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Pierre Habouzit
---
 builtin-reflog.c       |    1 +
 t/t1301-shared-repo.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

Some people like to have logAllRefUpdates even for bare repositories, and if shared, git-gc breaks them.

Quoted 12 lines

builtin-reflog.c static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, · line 311

Quoted 9 lines
builtin-reflog.c +1 -0
index 897d1dc..430929f 100644
@@ -308,6 +308,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref && commit_ref(lock)) {
 			status |= error("Couldn't set %s", lock->ref_name);
 		}
+		adjust_shared_perm(log_file);

Why is it sane to do this unconditionally, instead of putting in another else or something?

Quoted 2 lines

Because adjust_shared_perm() checks for shared_repository, and returns when there is nothing to do.

Ooops. I think I missed your point, namely that this should only be done when no error occurred. I just blame it on the short snippet.

Sorry,
Dscho