git-cvsimport-script: clean up documentation
[git.git] / pack-objects.c
index f0c84c9..62ed265 100644 (file)
@@ -11,7 +11,7 @@ enum object_type {
        OBJ_COMMIT,
        OBJ_TREE,
        OBJ_BLOB,
-       OBJ_DELTA       // NOTE! This is _not_ the same as a "delta" object in the filesystem
+       OBJ_DELTA
 };
 
 struct object_entry {
@@ -29,6 +29,7 @@ static struct object_entry **sorted_by_sha, **sorted_by_type;
 static struct object_entry *objects = NULL;
 static int nr_objects = 0, nr_alloc = 0;
 static const char *base_name;
+static unsigned char pack_file_sha1[20];
 
 static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
 {
@@ -95,7 +96,7 @@ static void write_pack_file(void)
                entry->offset = offset;
                offset += write_object(f, entry);
        }
-       sha1close(f);
+       sha1close(f, pack_file_sha1, 1);
        mb = offset >> 20;
        offset &= 0xfffff;
 }
@@ -111,7 +112,7 @@ static void write_index_file(void)
        /*
         * Write the first-level table (the list is sorted,
         * but we use a 256-entry lookup to be able to avoid
-        * having to do eight extra binary search iterations)
+        * having to do eight extra binary search iterations).
         */
        for (i = 0; i < 256; i++) {
                struct object_entry **next = list;
@@ -136,7 +137,8 @@ static void write_index_file(void)
                sha1write(f, &offset, 4);
                sha1write(f, entry->sha1, 20);
        }
-       sha1close(f);
+       sha1write(f, pack_file_sha1, 20);
+       sha1close(f, NULL, 1);
 }
 
 static void add_object_entry(unsigned char *sha1, unsigned int hash)
@@ -158,28 +160,22 @@ static void add_object_entry(unsigned char *sha1, unsigned int hash)
 
 static void check_object(struct object_entry *entry)
 {
-       char buffer[128];
-       char type[10];
-       unsigned long mapsize;
-       z_stream stream;
-       void *map;
-
-       map = map_sha1_file(entry->sha1, &mapsize);
-       if (!map)
-               die("unable to map %s", sha1_to_hex(entry->sha1));
-       if (unpack_sha1_header(&stream, map, mapsize, buffer, sizeof(buffer)) < 0)
-               die("unable to unpack %s header", sha1_to_hex(entry->sha1));
-       munmap(map, mapsize);
-       if (parse_sha1_header(buffer, type, &entry->size) < 0)
-               die("unable to parse %s header", sha1_to_hex(entry->sha1));
-       if (!strcmp(type, "commit")) {
-               entry->type = OBJ_COMMIT;
-       } else if (!strcmp(type, "tree")) {
-               entry->type = OBJ_TREE;
-       } else if (!strcmp(type, "blob")) {
-               entry->type = OBJ_BLOB;
-       } else
-               die("unable to pack object %s of type %s", sha1_to_hex(entry->sha1), type);
+       char type[20];
+
+       if (!sha1_object_info(entry->sha1, type, &entry->size)) {
+               if (!strcmp(type, "commit")) {
+                       entry->type = OBJ_COMMIT;
+               } else if (!strcmp(type, "tree")) {
+                       entry->type = OBJ_TREE;
+               } else if (!strcmp(type, "blob")) {
+                       entry->type = OBJ_BLOB;
+               } else
+                       die("unable to pack object %s of type %s",
+                           sha1_to_hex(entry->sha1), type);
+       }
+       else
+               die("unable to get type of object %s",
+                   sha1_to_hex(entry->sha1));
 }
 
 static void get_object_details(void)