Reuse sha1 in packed_git in fast-import.
[gitweb.git] / fast-import.c
index ebffa7c904bc892dc086aa8a53257253764d2453..5767e808c65144739e47cab1e9f32703d2377a91 100644 (file)
@@ -248,7 +248,6 @@ static struct packed_git *pack_data;
 static struct packed_git **all_packs;
 static int pack_fd;
 static unsigned long pack_size;
-static unsigned char pack_sha1[20];
 
 /* Table of objects we've written. */
 static unsigned int object_entry_alloc = 5000;
@@ -590,19 +589,6 @@ static void release_tree_entry(struct tree_entry *e)
        avail_tree_entry = e;
 }
 
-static void yread(int fd, void *buffer, size_t length)
-{
-       ssize_t ret = 0;
-       while (ret < length) {
-               ssize_t size = xread(fd, (char *) buffer + ret, length - ret);
-               if (!size)
-                       die("Read from descriptor %i: end of stream", fd);
-               if (size < 0)
-                       die("Read from descriptor %i: %s", fd, strerror(errno));
-               ret += size;
-       }
-}
-
 static void start_packfile()
 {
        struct packed_git *p;
@@ -642,7 +628,8 @@ static void fixup_header_footer()
                die("Failed seeking to start: %s", strerror(errno));
 
        SHA1_Init(&c);
-       yread(pack_fd, hdr, 8);
+       if (read_in_full(pack_fd, hdr, 8) != 8)
+               die("Unable to reread header of %s", pack_data->pack_name);
        SHA1_Update(&c, hdr, 8);
 
        cnt = htonl(object_count);
@@ -658,8 +645,8 @@ static void fixup_header_footer()
        }
        free(buf);
 
-       SHA1_Final(pack_sha1, &c);
-       write_or_die(pack_fd, pack_sha1, sizeof(pack_sha1));
+       SHA1_Final(pack_data->sha1, &c);
+       write_or_die(pack_fd, pack_data->sha1, sizeof(pack_data->sha1));
 }
 
 static int oecmp (const void *a_, const void *b_)
@@ -709,8 +696,8 @@ static void write_index(const char *idx_name)
                sha1write(f, &offset, 4);
                sha1write(f, (*c)->sha1, sizeof((*c)->sha1));
        }
-       sha1write(f, pack_sha1, sizeof(pack_sha1));
-       sha1close(f, NULL, 1);
+       sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
+       sha1close(f, pack_data->sha1, 1);
        free(idx);
 }