Skip to contentSkip to conversation

Enhance core.logallrefupdates

RFC/PATCH Junio C Hamano 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

This enhances core.logallrefupdates by allowing it to take "heads" as the value as well, which causes git to create missing reflog files automatically only for branch heads. Usually tags are create-once-and-live-forever, and it is irritating to see reflog files created automatically every time a new tag is made.

As before, boolean "true" means create missing reflog files for all refs.

---

* Setting it to "tags" is not supported, as it does not make much sense wanting to log only tag updates.

Come to think of it, it might make sense to change the meaning of "true" to do what this patch does. I do not think of reasons to create missing reflog for tags automatically anyway.

Opinions?

 cache.h  |    2 ++
 config.c |    9 ++++++++-
 refs.c   |    7 ++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
cache.h +2 -0
index 0565333..6029a1d 100644
@@ -186,6 +186,8 @@ extern int use_legacy_headers;
 extern int trust_executable_bit;
 extern int assume_unchanged;
 extern int prefer_symlink_refs;
+#define REF_LOG_ALL 1
+#define REF_LOG_HEADS 2
 extern int log_all_ref_updates;
 extern int warn_ambiguous_refs;
 extern int shared_repository;
config.c +8 -1
index e8f0caf..c254a57 100644
@@ -270,7 +270,14 @@ int git_default_config(const char *var, 
 	}
 
 	if (!strcmp(var, "core.logallrefupdates")) {
-		log_all_ref_updates = git_config_bool(var, value);
+		if (!strcasecmp(value, "heads"))
+			log_all_ref_updates = REF_LOG_HEADS;
+		else if (!strcasecmp(value, "all"))
+			log_all_ref_updates = REF_LOG_ALL;
+		else if (git_config_bool(var, value))
+			log_all_ref_updates = REF_LOG_ALL;
+		else
+			log_all_ref_updates = 0;
 		return 0;
 	}
 
refs.c +6 -1
index 305c1a9..fa3c3d7 100644
@@ -720,8 +720,13 @@ static int log_ref_write(struct ref_lock
 	unsigned maxlen, len;
 	char *logrec;
 	const char *committer;
+	int create_missing = log_all_ref_updates;
 
-	if (log_all_ref_updates) {
+	if ((log_all_ref_updates == REF_LOG_HEADS) &&
+	    strncmp(lock->ref_name, "refs/heads/", 11))
+		create_missing = 0;
+
+	if (create_missing) {
 		if (safe_create_leading_directories(lock->log_file) < 0)
 			return error("unable to create directory for %s",
 				lock->log_file);
#1 lore raw
Quoted 11 lines · Junio C Hamano

This enhances core.logallrefupdates by allowing it to take "heads" as the value as well, which causes git to create missing reflog files automatically only for branch heads.  Usually tags are create-once-and-live-forever, and it is irritating to see reflog files created automatically every time a new tag is made.

As before, boolean "true" means create missing reflog files for all refs.

---

Quoted 7 lines

 * Setting it to "tags" is not supported, as it does not make much sense wanting to log only tag updates.

   Come to think of it, it might make sense to change the meaning of "true" to do what this patch does.  I do not think of reasons to create missing reflog for tags automatically anyway.

If we change meaning of "true", perhaps (just in case in case) we should add "all" value?

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#2 lore raw
Quoted 7 lines · Jakub Narebski
Quoted 4 lines

   Come to think of it, it might make sense to change the meaning of "true" to do what this patch does.  I do not think of reasons to create missing reflog for tags automatically anyway.

If we change meaning of "true", perhaps (just in case in case) we should add "all" value?

Didn't I just say that I do not think of reasons to do so ;-)?

Saying "just in case" is not enough. You need to say at least "this hypothetical workflow which requires to update refs/xxx and doing automated reflog creation only under refs/heads makes that workflow less convenient".

#3 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Jakub Narebski
Quoted 4 lines

   Come to think of it, it might make sense to change the meaning of "true" to do what this patch does.  I do not think of reasons to create missing reflog for tags automatically anyway.

If we change meaning of "true", perhaps (just in case in case) we should add "all" value?

Quoted 6 lines

Didn't I just say that I do not think of reasons to do so ;-)?

Saying "just in case" is not enough. You need to say at least "this hypothetical workflow which requires to update refs/xxx and doing automated reflog creation only under refs/heads makes that workflow less convenient".

If I remember correctly there was example of workflow which did fetch remote heads to local tags. But I'm not sure if this reflog made sense with that workflow.

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git