]> asedeno.scripts.mit.edu Git - git.git/blobdiff - refs.c
Documentation: bisect: make a comment fit better in the man page.
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index 7a1f89caad17cfb090e683c9888537666e8398b9..f471152bfc6c500a2597068496ffff3f4d8f5961 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -921,6 +921,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
                                     log_file, strerror(errno));
        }
 
+       adjust_shared_perm(log_file);
+
        msglen = 0;
        if (msg) {
                /* clean up the message and make sure it is a single line */
@@ -978,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);
@@ -1075,6 +1098,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
        unsigned long date;
        unsigned char logged_sha1[20];
        void *log_mapped;
+       size_t mapsz;
 
        logfile = git_path("logs/%s", ref);
        logfd = open(logfile, O_RDONLY, 0);
@@ -1083,7 +1107,8 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
        fstat(logfd, &st);
        if (!st.st_size)
                die("Log %s is empty.", logfile);
-       log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0);
+       mapsz = xsize_t(st.st_size);
+       log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0);
        logdata = log_mapped;
        close(logfd);
 
@@ -1136,7 +1161,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
                                                logfile, show_rfc2822_date(date, tz));
                                }
                        }
-                       munmap(log_mapped, st.st_size);
+                       munmap(log_mapped, mapsz);
                        return 0;
                }
                lastrec = rec;
@@ -1155,7 +1180,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
                die("Log %s is corrupt.", logfile);
        if (msg)
                *msg = ref_msg(logdata, logend);
-       munmap(log_mapped, st.st_size);
+       munmap(log_mapped, mapsz);
 
        if (cutoff_time)
                *cutoff_time = date;