@matheusbsbs / matheus-bagliano / commits / 605fac8b5b
Fork 0

update HEAD reflog when branch pointed to by HEAD is directly modified

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Mar 21, 2007 at 17:11 UTC 605fac8b5bd6d4a2ca817631e2c56ba2d0a1ed91
1 file changed +21
refs.c
+21
@@ -980,6 +980,27 @@ int write_ref_sha1(struct ref_lock *lock,
980 unlock_ref(lock);
981 return -1;
982 }
983 + if (strcmp(lock->orig_ref_name, "HEAD") != 0) {
984 + /*
985 + * Special hack: If a branch is updated directly and HEAD
986 + * points to it (may happen on the remote side of a push
987 + * for example) then logically the HEAD reflog should be
988 + * updated too.
989 + * A generic solution implies reverse symref information,
990 + * but finding all symrefs pointing to the given branch
991 + * would be rather costly for this rare event (the direct
992 + * update of a branch) to be worth it. So let's cheat and
993 + * check with HEAD only which should cover 99% of all usage
994 + * scenarios (even 100% of the default ones).
995 + */
996 + unsigned char head_sha1[20];
997 + int head_flag;
998 + const char *head_ref;
999 + head_ref = resolve_ref("HEAD", head_sha1, 1, &head_flag);
1000 + if (head_ref && (head_flag & REF_ISSYMREF) &&
1001 + !strcmp(head_ref, lock->ref_name))
1002 + log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
1003 + }
1004 if (commit_lock_file(lock->lk)) {
1005 error("Couldn't set %s", lock->ref_name);
1006 unlock_ref(lock);