hash.h: move SHA-1 implementation selection into a header file
[gitweb.git] / refs / files-backend.c
index d16feb19c57b1b74594947f8730b984e94c43def..c041d4ba21a8fe70eb6d8277358e7e3f29a69bfb 100644 (file)
@@ -697,7 +697,7 @@ static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
 
        if (peel_entry(entry, 0))
                return -1;
-       hashcpy(peeled->hash, entry->u.value.peeled.hash);
+       oidcpy(peeled, &entry->u.value.peeled);
        return 0;
 }
 
@@ -1353,6 +1353,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
        int fd;
        int ret = -1;
        int save_errno;
+       int remaining_retries = 3;
 
        *type = 0;
        strbuf_reset(&sb_path);
@@ -1373,8 +1374,14 @@ static int files_read_raw_ref(struct ref_store *ref_store,
         * <-> symlink) between the lstat() and reading, then
         * we don't want to report that as an error but rather
         * try again starting with the lstat().
+        *
+        * We'll keep a count of the retries, though, just to avoid
+        * any confusing situation sending us into an infinite loop.
         */
 
+       if (remaining_retries-- <= 0)
+               goto out;
+
        if (lstat(path, &st) < 0) {
                if (errno != ENOENT)
                        goto out;
@@ -1403,6 +1410,11 @@ static int files_read_raw_ref(struct ref_store *ref_store,
                        ret = 0;
                        goto out;
                }
+               /*
+                * It doesn't look like a refname; fall through to just
+                * treating it like a non-symlink, and reading whatever it
+                * points to.
+                */
        }
 
        /* Is it a directory? */
@@ -1426,7 +1438,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
         */
        fd = open(path, O_RDONLY);
        if (fd < 0) {
-               if (errno == ENOENT)
+               if (errno == ENOENT && !S_ISLNK(st.st_mode))
                        /* inconsistent with lstat; retry */
                        goto stat_ref;
                else
@@ -2670,7 +2682,7 @@ static int files_rename_ref(struct ref_store *ref_store,
        }
 
        flag = log_all_ref_updates;
-       log_all_ref_updates = 0;
+       log_all_ref_updates = LOG_REFS_NONE;
        if (write_ref_to_lockfile(lock, orig_sha1, &err) ||
            commit_ref_update(refs, lock, orig_sha1, NULL, &err)) {
                error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
@@ -2823,8 +2835,8 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
 {
        int logfd, result, oflags = O_APPEND | O_WRONLY;
 
-       if (log_all_ref_updates < 0)
-               log_all_ref_updates = !is_bare_repository();
+       if (log_all_ref_updates == LOG_REFS_UNSET)
+               log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
        result = log_ref_setup(refname, logfile, err, flags & REF_FORCE_CREATE_REFLOG);