git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/7] enable separate reflog for HEAD

From
Nicolas Pitre <nico@cam.org>
Date
Jan 26, 2007, 22:26 UTC
Message-ID
<11698503712998-git-send-email-nico@cam.org>
In-Reply-To
<11698503712588-git-send-email-nico@cam.org>

If HEAD is tied to a branch then both logs/HEAD and logs/heads/<branch> are updated. This is also true for any symbolic refs in general, but only HEAD will see its reflog created automatically.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
 refs.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index 9641fad..92fa2e4 100644
--- a/refs.c
+++ b/refs.c
@@ -935,7 +935,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 
 	if (log_all_ref_updates &&
 	    (!strncmp(ref_name, "refs/heads/", 11) ||
-	     !strncmp(ref_name, "refs/remotes/", 13))) {
+	     !strncmp(ref_name, "refs/remotes/", 13) ||
+	     !strcmp(ref_name, "HEAD"))) {
 		if (safe_create_leading_directories(log_file) < 0)
 			return error("unable to create directory for %s",
 				     log_file);
@@ -1005,7 +1006,9 @@ int write_ref_sha1(struct ref_lock *lock,
 		return -1;
 	}
 	invalidate_cached_refs();
-	if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0) {
+	if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
+	    (strcmp(lock->ref_name, lock->orig_ref_name) &&
+	     log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) {
 		unlock_ref(lock);
 		return -1;
 	}
-- 
1.5.0.rc2.g6e2c
Previous: Nicolas PitreNext: Nicolas Pitre
Message 3 of 8 in “make reflog filename independent from struct ref_lock”
  1. 1/7 make reflog filename independent from struct ref_lockNicolas Pitre, Jan 26, 2007
  2. 2/7 lock_ref_sha1_basic(): remember the original name of a ref when resolving itNicolas Pitre, Jan 26, 2007
  3. 3/7 enable separate reflog for HEADNicolas Pitre, Jan 26, 2007
  4. 4/7 add reflog entries for HEAD when detachedNicolas Pitre, Jan 26, 2007
  5. 5/7 move create_symref() past log_ref_write()Nicolas Pitre, Jan 26, 2007
  6. 6/7 add logref support to git-symbolic-refNicolas Pitre, Jan 26, 2007
  7. 7/7 add reflog when moving HEAD to a new branchNicolas Pitre, Jan 26, 2007
  8. 2/3 create_symref(): do not assume pathname from git_path() persists long enoughJunio C Hamano, Jan 27, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.