git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] update HEAD reflog when branch pointed to by HEAD is directly modified
@ 2007-03-21 21:11 Nicolas Pitre
  0 siblings, 0 replies; only message in thread
From: Nicolas Pitre @ 2007-03-21 21:11 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

The HEAD reflog is updated as well as the reflog for the branch pointed 
to by HEAD whenever it is referenced with "HEAD".

There are some cases where a specific branch may be modified directly.  
In those cases, the HEAD reflog should be updated as well if it is a 
symref to that branch in order to be consistent.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---

diff --git a/refs.c b/refs.c
index 9f1fb68..435eeca 100644
--- a/refs.c
+++ b/refs.c
@@ -980,6 +980,27 @@ int write_ref_sha1(struct ref_lock *lock,
 		unlock_ref(lock);
 		return -1;
 	}
+	if (strcmp(lock->orig_ref_name, "HEAD") != 0) {
+		/*
+		 * Special hack: If a branch is updated directly and HEAD
+		 * points to it (may happen on the remote side of a push
+		 * for example) then logically the HEAD reflog should be
+		 * updated too. 
+		 * A generic solution implies reverse symref information, 
+		 * but finding all symrefs pointing to the given branch
+		 * would be rather costly for this rare event (the direct
+		 * update of a branch) to be worth it.  So let's cheat and
+		 * check with HEAD only which should cover 99% of all usage
+		 * scenarios (even 100% of the default ones).
+		 */
+		unsigned char head_sha1[20];
+		int head_flag;
+		const char *head_ref;
+		head_ref = resolve_ref("HEAD", head_sha1, 1, &head_flag);
+		if (head_ref && (head_flag & REF_ISSYMREF) &&
+		    !strcmp(head_ref, lock->ref_name))
+			log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
+	}
 	if (commit_lock_file(lock->lk)) {
 		error("Couldn't set %s", lock->ref_name);
 		unlock_ref(lock);

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2007-03-21 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-21 21:11 [PATCH] update HEAD reflog when branch pointed to by HEAD is directly modified Nicolas Pitre

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).