Allow the test suite to pass in a directory whose name contains spaces
[gitweb.git] / sha1_file.c
index 43990dec735099fd2e94cf73e41f318fbaf5dd38..dd90a785419b851adf97643db9b291ab23b01224 100644 (file)
@@ -1606,7 +1606,7 @@ static void mark_bad_packed_object(struct packed_git *p,
                if (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))
                        return;
        p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
-                                     st_mult(GIT_SHA1_RAWSZ,
+                                     st_mult(GIT_MAX_RAWSZ,
                                              st_add(p->num_bad_objects, 1)));
        hashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1);
        p->num_bad_objects++;
@@ -1684,14 +1684,14 @@ int git_open_cloexec(const char *name, int flags)
                fd = open(name, flags | o_cloexec);
        }
 
-#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
+#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
        {
                static int fd_cloexec = FD_CLOEXEC;
 
                if (!o_cloexec && 0 <= fd && fd_cloexec) {
                        /* Opened w/o O_CLOEXEC?  try with fcntl(2) to add it */
-                       int flags = fcntl(fd, F_GETFL);
-                       if (fcntl(fd, F_SETFL, flags | fd_cloexec))
+                       int flags = fcntl(fd, F_GETFD);
+                       if (fcntl(fd, F_SETFD, flags | fd_cloexec))
                                fd_cloexec = 0;
                }
        }
@@ -2952,7 +2952,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
        if (status && oi->typep)
                *oi->typep = status;
        strbuf_release(&hdrbuf);
-       return 0;
+       return (status < 0) ? status : 0;
 }
 
 int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)
@@ -3481,6 +3481,8 @@ int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
 {
        struct pack_entry e;
 
+       if (!startup_info->have_repository)
+               return 0;
        if (find_pack_entry(sha1, &e))
                return 1;
        if (has_loose_object(sha1))
@@ -3759,7 +3761,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
                strbuf_addf(path, "/%s", de->d_name);
 
                if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2)  {
-                       char hex[GIT_SHA1_HEXSZ+1];
+                       char hex[GIT_MAX_HEXSZ+1];
                        struct object_id oid;
 
                        xsnprintf(hex, sizeof(hex), "%02x%s",
@@ -3913,7 +3915,7 @@ static int check_stream_sha1(git_zstream *stream,
                             const unsigned char *expected_sha1)
 {
        git_SHA_CTX c;
-       unsigned char real_sha1[GIT_SHA1_RAWSZ];
+       unsigned char real_sha1[GIT_MAX_RAWSZ];
        unsigned char buf[4096];
        unsigned long total_read;
        int status = Z_OK;
@@ -3970,7 +3972,6 @@ int read_loose_object(const char *path,
                      void **contents)
 {
        int ret = -1;
-       int fd = -1;
        void *map = NULL;
        unsigned long mapsize;
        git_zstream stream;
@@ -4020,7 +4021,5 @@ int read_loose_object(const char *path,
 out:
        if (map)
                munmap(map, mapsize);
-       if (fd >= 0)
-               close(fd);
        return ret;
 }